summaryrefslogtreecommitdiffstats
path: root/examples/game_of_life
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-05-01 05:42:07 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-05-01 05:42:07 +0200
commitffbe59f8129c80afb3e86eae67efaa5370fbfa8e (patch)
tree93f11093d42907b73d80ad03326406067be03574 /examples/game_of_life
parent0a5f1bb676f89a26711a8885935ffe94a370c261 (diff)
downloadiced-ffbe59f8129c80afb3e86eae67efaa5370fbfa8e.tar.gz
iced-ffbe59f8129c80afb3e86eae67efaa5370fbfa8e.tar.bz2
iced-ffbe59f8129c80afb3e86eae67efaa5370fbfa8e.zip
Zoom to cursor in `game_of_life` example
Diffstat (limited to 'examples/game_of_life')
-rw-r--r--examples/game_of_life/src/main.rs16
1 files changed, 15 insertions, 1 deletions
diff --git a/examples/game_of_life/src/main.rs b/examples/game_of_life/src/main.rs
index 92500309..c818d99f 100644
--- a/examples/game_of_life/src/main.rs
+++ b/examples/game_of_life/src/main.rs
@@ -292,7 +292,21 @@ mod grid {
if y < 0.0 && self.scaling > Self::MIN_SCALING
|| y > 0.0 && self.scaling < Self::MAX_SCALING
{
- self.scaling = (self.scaling + y / 30.0)
+ let factor = y / 30.0;
+
+ if let Some(cursor_to_center) =
+ cursor.position_from(bounds.center())
+ {
+ self.translation = self.translation
+ - Vector::new(
+ cursor_to_center.x * factor
+ / (self.scaling * self.scaling),
+ cursor_to_center.y * factor
+ / (self.scaling * self.scaling),
+ );
+ }
+
+ self.scaling = (self.scaling + factor)
.max(Self::MIN_SCALING)
.min(Self::MAX_SCALING);