Improve scrolling smoothness in game_of_life

This commit is contained in:
Héctor Ramón Jiménez 2020-05-01 06:23:05 +02:00
parent ffbe59f812
commit 1833c77312

View file

@ -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();
}