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 06:23:05 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-05-01 06:23:05 +0200
commit1833c77312ede2e5d47b62df0eea771f6fa559e9 (patch)
tree433d7c436935bade3621068eaf7fe2466a56366b /examples/game_of_life
parentffbe59f8129c80afb3e86eae67efaa5370fbfa8e (diff)
downloadiced-1833c77312ede2e5d47b62df0eea771f6fa559e9.tar.gz
iced-1833c77312ede2e5d47b62df0eea771f6fa559e9.tar.bz2
iced-1833c77312ede2e5d47b62df0eea771f6fa559e9.zip
Improve scrolling smoothness in `game_of_life`
Diffstat (limited to 'examples/game_of_life')
-rw-r--r--examples/game_of_life/src/main.rs17
1 files changed, 10 insertions, 7 deletions
diff --git a/examples/game_of_life/src/main.rs b/examples/game_of_life/src/main.rs
index c818d99f..44ab4da6 100644
--- a/examples/game_of_life/src/main.rs
+++ b/examples/game_of_life/src/main.rs
@@ -292,24 +292,27 @@ mod grid {
if y < 0.0 && self.scaling > Self::MIN_SCALING
|| y > 0.0 && self.scaling < Self::MAX_SCALING
{
- let factor = y / 30.0;
+ let old_scaling = self.scaling;
+
+ self.scaling = (self.scaling
+ * (1.0 + y / 30.0))
+ .max(Self::MIN_SCALING)
+ .min(Self::MAX_SCALING);
if let Some(cursor_to_center) =
cursor.position_from(bounds.center())
{
+ let factor = self.scaling - old_scaling;
+
self.translation = self.translation
- Vector::new(
cursor_to_center.x * factor
- / (self.scaling * self.scaling),
+ / (old_scaling * old_scaling),
cursor_to_center.y * factor
- / (self.scaling * self.scaling),
+ / (old_scaling * old_scaling),
);
}
- self.scaling = (self.scaling + factor)
- .max(Self::MIN_SCALING)
- .min(Self::MAX_SCALING);
-
self.cache.clear();
}