fix: tame animated resize scaling

This commit is contained in:
Samuel Onoja committed 2026-09-25 01:13:21 +01:00
1 parent f6dce3316a
commit bf4f5f77f7
6 files changed
+27 -22

No files matched your search

+9 -7
View File
@@ -237,19 +237,22 @@ impl WindowGeometry {
pub fn inverse_visual_point(&self, x: f64, y: f64) -> Option<(f64, f64)> {
let visual = self.visual.current;
let scale = self.visual_scale()?;
let (scale_x, scale_y) = self.visual_scale()?;
Some(((x - visual.x) / scale, (y - visual.y) / scale))
Some(((x - visual.x) / scale_x, (y - visual.y) / scale_y))
}
pub fn visual_scale(&self) -> Option<f64> {
pub fn visual_scale(&self) -> Option<(f64, f64)> {
let source = self.client.committed_size?;
let visual = self.visual.current;
if source.width <= 0 || source.height <= 0 || visual.width <= 0.0 || visual.height <= 0.0 {
return None;
}
Some((visual.width / f64::from(source.width)).max(visual.height / f64::from(source.height)))
Some((
visual.width / f64::from(source.width),
visual.height / f64::from(source.height),
))
}
}
@@ -381,15 +384,14 @@ mod tests {
}
#[test]
fn inverse_visual_point_matches_uniform_cover_transform() {
fn inverse_visual_point_matches_stretched_transform() {
let initial = Rect::new(100.0, 50.0, 400.0, 300.0);
let mut geometry = WindowGeometry::new(initial, Some(ClientSize::from_rect(initial)));
geometry.visual.current = Rect::new(200.0, 100.0, 600.0, 600.0);
// Cover scales the 4:3 source by 2x for a square allocation, then clips it.
assert_eq!(
geometry.inverse_visual_point(600.0, 500.0),
Some((200.0, 200.0))
Some((400.0 * 2.0 / 3.0, 200.0))
);
}