zoom: Be a little more lenient with OnEdge movement and fractional cursor positions

This commit is contained in:
Victoria Brekenfeld 2025-02-17 17:59:52 +01:00 committed by Victoria Brekenfeld
parent 909ca8cf9d
commit 9e8c2f5e24

View file

@ -239,8 +239,10 @@ impl ZoomState {
original_position: Point<f64, Global>,
movement: ZoomMovement,
) {
let output_geometry = output.geometry().to_f64();
let mut zoomed_output_geometry = output.zoomed_geometry(self.level).unwrap().to_f64();
let cursor_position = cursor_position.to_i32_round();
let original_position = original_position.to_i32_round();
let output_geometry = output.geometry();
let mut zoomed_output_geometry = output.zoomed_geometry(self.level).unwrap();
let output_state = output.user_data().get::<Mutex<OutputZoomState>>().unwrap();
let mut output_state_ref = output_state.lock().unwrap();
@ -253,11 +255,13 @@ impl ZoomState {
let cursor_position = cursor_position.to_local(output);
match movement {
ZoomMovement::Continuously => output_state_ref.focal_point = cursor_position,
ZoomMovement::Continuously => output_state_ref.focal_point = cursor_position.to_f64(),
ZoomMovement::OnEdge => {
if !zoomed_output_geometry.contains(original_position) {
if !zoomed_output_geometry
.overlaps_or_touches(Rectangle::new(original_position, Size::from((1, 1))))
{
zoomed_output_geometry.loc = cursor_position.to_global(&output)
- zoomed_output_geometry.size.downscale(2.).to_point();
- zoomed_output_geometry.size.downscale(2).to_point();
let mut focal_point = zoomed_output_geometry
.loc
.to_local(&output)
@ -267,19 +271,20 @@ impl ZoomState {
)
.to_global(&output);
focal_point.x = focal_point.x.clamp(
output_geometry.loc.x as f64,
((output_geometry.loc.x + output_geometry.size.w) as f64).next_lower(), // FIXME: Replace with f64::next_down when stable
output_geometry.loc.x,
output_geometry.loc.x + output_geometry.size.w - 1,
);
focal_point.y = focal_point.y.clamp(
output_geometry.loc.y as f64,
((output_geometry.loc.y + output_geometry.size.h) as f64).next_lower(), // FIXME: Replace with f64::next_down when stable
output_geometry.loc.y,
output_geometry.loc.y + output_geometry.size.h - 1,
);
output_state_ref.previous_point =
Some((output_state_ref.focal_point, Instant::now()));
output_state_ref.focal_point = focal_point.to_local(&output);
output_state_ref.focal_point = focal_point.to_local(&output).to_f64();
} else if !zoomed_output_geometry.contains(cursor_position.to_global(&output)) {
let mut diff = output_state_ref.focal_point.to_global(&output)
+ (cursor_position.to_global(&output) - original_position)
.to_f64()
.upscale(self.level);
diff.x = diff.x.clamp(
output_geometry.loc.x as f64,
@ -296,7 +301,7 @@ impl ZoomState {
}
ZoomMovement::Centered => {
zoomed_output_geometry.loc = cursor_position.to_global(&output)
- zoomed_output_geometry.size.downscale(2.).to_point();
- zoomed_output_geometry.size.downscale(2).to_point();
let mut focal_point = zoomed_output_geometry
.loc
@ -307,14 +312,14 @@ impl ZoomState {
)
.to_global(&output);
focal_point.x = focal_point.x.clamp(
output_geometry.loc.x as f64,
((output_geometry.loc.x + output_geometry.size.w) as f64).next_lower(), // FIXME: Replace with f64::next_down when stable
output_geometry.loc.x,
output_geometry.loc.x + output_geometry.size.w - 1,
);
focal_point.y = focal_point.y.clamp(
output_geometry.loc.y as f64,
((output_geometry.loc.y + output_geometry.size.h) as f64).next_lower(), // FIXME: Replace with f64::next_down when stable
output_geometry.loc.y,
output_geometry.loc.y + output_geometry.size.h - 1,
);
output_state_ref.focal_point = focal_point.to_local(&output);
output_state_ref.focal_point = focal_point.to_local(&output).to_f64();
}
}
}