Improve scrolling smoothness in game_of_life
This commit is contained in:
parent
ffbe59f812
commit
1833c77312
1 changed files with 10 additions and 7 deletions
|
|
@ -292,24 +292,27 @@ mod grid {
|
||||||
if y < 0.0 && self.scaling > Self::MIN_SCALING
|
if y < 0.0 && self.scaling > Self::MIN_SCALING
|
||||||
|| y > 0.0 && self.scaling < Self::MAX_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) =
|
if let Some(cursor_to_center) =
|
||||||
cursor.position_from(bounds.center())
|
cursor.position_from(bounds.center())
|
||||||
{
|
{
|
||||||
|
let factor = self.scaling - old_scaling;
|
||||||
|
|
||||||
self.translation = self.translation
|
self.translation = self.translation
|
||||||
- Vector::new(
|
- Vector::new(
|
||||||
cursor_to_center.x * factor
|
cursor_to_center.x * factor
|
||||||
/ (self.scaling * self.scaling),
|
/ (old_scaling * old_scaling),
|
||||||
cursor_to_center.y * factor
|
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();
|
self.cache.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue