Zoom to cursor in game_of_life example
This commit is contained in:
parent
0a5f1bb676
commit
ffbe59f812
1 changed files with 15 additions and 1 deletions
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue