Skip to content

Commit

Permalink
Improve zooming logic in game_of_life
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed May 1, 2020
1 parent c23995e commit f2e63f1
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions examples/game_of_life/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
.min(Self::MIN_SCALING)
.max(Self::MAX_SCALING);

self.cache.clear();
}
Expand Down

0 comments on commit f2e63f1

Please sign in to comment.