zoom: Be a little more lenient with OnEdge movement and fractional cursor positions
This commit is contained in:
parent
909ca8cf9d
commit
9e8c2f5e24
1 changed files with 21 additions and 16 deletions
|
|
@ -239,8 +239,10 @@ impl ZoomState {
|
||||||
original_position: Point<f64, Global>,
|
original_position: Point<f64, Global>,
|
||||||
movement: ZoomMovement,
|
movement: ZoomMovement,
|
||||||
) {
|
) {
|
||||||
let output_geometry = output.geometry().to_f64();
|
let cursor_position = cursor_position.to_i32_round();
|
||||||
let mut zoomed_output_geometry = output.zoomed_geometry(self.level).unwrap().to_f64();
|
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 output_state = output.user_data().get::<Mutex<OutputZoomState>>().unwrap();
|
||||||
let mut output_state_ref = output_state.lock().unwrap();
|
let mut output_state_ref = output_state.lock().unwrap();
|
||||||
|
|
@ -253,11 +255,13 @@ impl ZoomState {
|
||||||
|
|
||||||
let cursor_position = cursor_position.to_local(output);
|
let cursor_position = cursor_position.to_local(output);
|
||||||
match movement {
|
match movement {
|
||||||
ZoomMovement::Continuously => output_state_ref.focal_point = cursor_position,
|
ZoomMovement::Continuously => output_state_ref.focal_point = cursor_position.to_f64(),
|
||||||
ZoomMovement::OnEdge => {
|
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.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
|
let mut focal_point = zoomed_output_geometry
|
||||||
.loc
|
.loc
|
||||||
.to_local(&output)
|
.to_local(&output)
|
||||||
|
|
@ -267,19 +271,20 @@ impl ZoomState {
|
||||||
)
|
)
|
||||||
.to_global(&output);
|
.to_global(&output);
|
||||||
focal_point.x = focal_point.x.clamp(
|
focal_point.x = focal_point.x.clamp(
|
||||||
output_geometry.loc.x as f64,
|
output_geometry.loc.x,
|
||||||
((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.size.w - 1,
|
||||||
);
|
);
|
||||||
focal_point.y = focal_point.y.clamp(
|
focal_point.y = focal_point.y.clamp(
|
||||||
output_geometry.loc.y as f64,
|
output_geometry.loc.y,
|
||||||
((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.size.h - 1,
|
||||||
);
|
);
|
||||||
output_state_ref.previous_point =
|
output_state_ref.previous_point =
|
||||||
Some((output_state_ref.focal_point, Instant::now()));
|
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)) {
|
} else if !zoomed_output_geometry.contains(cursor_position.to_global(&output)) {
|
||||||
let mut diff = output_state_ref.focal_point.to_global(&output)
|
let mut diff = output_state_ref.focal_point.to_global(&output)
|
||||||
+ (cursor_position.to_global(&output) - original_position)
|
+ (cursor_position.to_global(&output) - original_position)
|
||||||
|
.to_f64()
|
||||||
.upscale(self.level);
|
.upscale(self.level);
|
||||||
diff.x = diff.x.clamp(
|
diff.x = diff.x.clamp(
|
||||||
output_geometry.loc.x as f64,
|
output_geometry.loc.x as f64,
|
||||||
|
|
@ -296,7 +301,7 @@ impl ZoomState {
|
||||||
}
|
}
|
||||||
ZoomMovement::Centered => {
|
ZoomMovement::Centered => {
|
||||||
zoomed_output_geometry.loc = cursor_position.to_global(&output)
|
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
|
let mut focal_point = zoomed_output_geometry
|
||||||
.loc
|
.loc
|
||||||
|
|
@ -307,14 +312,14 @@ impl ZoomState {
|
||||||
)
|
)
|
||||||
.to_global(&output);
|
.to_global(&output);
|
||||||
focal_point.x = focal_point.x.clamp(
|
focal_point.x = focal_point.x.clamp(
|
||||||
output_geometry.loc.x as f64,
|
output_geometry.loc.x,
|
||||||
((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.size.w - 1,
|
||||||
);
|
);
|
||||||
focal_point.y = focal_point.y.clamp(
|
focal_point.y = focal_point.y.clamp(
|
||||||
output_geometry.loc.y as f64,
|
output_geometry.loc.y,
|
||||||
((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.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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue