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:19:05 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-05-01 05:21:27 +0200
commit0a5f1bb676f89a26711a8885935ffe94a370c261 (patch)
treee76c322b5686b2b8dad5bae0720ef9170b39916a /examples/game_of_life
parentc23995ecb4ddc0c9cc33b0d50404a478b8b5e659 (diff)
downloadiced-0a5f1bb676f89a26711a8885935ffe94a370c261.tar.gz
iced-0a5f1bb676f89a26711a8885935ffe94a370c261.tar.bz2
iced-0a5f1bb676f89a26711a8885935ffe94a370c261.zip
Improve zooming logic in `game_of_life`
Diffstat (limited to 'examples/game_of_life')
-rw-r--r--examples/game_of_life/src/main.rs19
1 files changed, 9 insertions, 10 deletions
diff --git a/examples/game_of_life/src/main.rs b/examples/game_of_life/src/main.rs
index 8a140ed4..92500309 100644
--- a/examples/game_of_life/src/main.rs
+++ b/examples/game_of_life/src/main.rs
@@ -178,7 +178,7 @@ mod grid {
fn default() -> Self {
Self {
life: Life::default(),
- interaction: Interaction::default(),
+ interaction: Interaction::None,
cache: Cache::default(),
translation: Vector::default(),
scaling: 1.0,
@@ -187,6 +187,9 @@ mod grid {
}
impl Grid {
+ const MIN_SCALING: f32 = 0.1;
+ const MAX_SCALING: f32 = 2.0;
+
pub fn tick(&mut self) {
self.life.tick();
self.cache.clear()
@@ -286,10 +289,12 @@ mod grid {
mouse::Event::WheelScrolled { delta } => match delta {
mouse::ScrollDelta::Lines { y, .. }
| mouse::ScrollDelta::Pixels { y, .. } => {
- if y > 0.0 && self.scaling < 2.0
- || y < 0.0 && self.scaling > 0.25
+ if y < 0.0 && self.scaling > Self::MIN_SCALING
+ || y > 0.0 && self.scaling < Self::MAX_SCALING
{
- self.scaling += y / 30.0;
+ self.scaling = (self.scaling + y / 30.0)
+ .max(Self::MIN_SCALING)
+ .min(Self::MAX_SCALING);
self.cache.clear();
}
@@ -467,10 +472,4 @@ mod grid {
Drawing,
Panning { translation: Vector, start: Point },
}
-
- impl Default for Interaction {
- fn default() -> Interaction {
- Interaction::None
- }
- }
}