Aim fit-width zoom at the double-click target
This commit is contained in:
parent
8f361c70c5
commit
29e8671c40
|
|
@ -2245,7 +2245,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "pdf-presenter"
|
||||
version = "0.1.62"
|
||||
version = "0.1.63"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"chrono",
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ default-members = ["crates/pdf-presenter"]
|
|||
resolver = "3"
|
||||
|
||||
[workspace.package]
|
||||
version = "0.1.62"
|
||||
version = "0.1.63"
|
||||
edition = "2024"
|
||||
license = "MIT"
|
||||
repository = "https://proxy.dandaedre.com/gitea/idle-org/pdf-presenter"
|
||||
|
|
|
|||
|
|
@ -172,9 +172,16 @@ pub fn zoom_gestures_in(
|
|||
if response.double_clicked() {
|
||||
next = Default::default();
|
||||
if view.normalized().scale == 1. {
|
||||
let source = response.hover_pos().map_or(Pos2::new(0.5, 0.5), |pos| {
|
||||
uv.min + (pos - target.min) / target.size() * uv.size()
|
||||
});
|
||||
let fitted = fitted_slide(rect, dimensions);
|
||||
if fitted.width() > 0. {
|
||||
next.scale = (rect.width() / fitted.width()).clamp(1., 8.);
|
||||
let (_, fitted_uv) = zoom_geometry(rect, dimensions, next, keep_fitted_area);
|
||||
let half = fitted_uv.size() * 0.5;
|
||||
let center = source.to_vec2().clamp(half, Vec2::splat(1.) - half);
|
||||
next.center = [center.x, center.y];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -603,12 +603,13 @@ fn portrait_screen_adapting_gestures_pan_visible_area_and_reset() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn double_click_fits_width_then_resets_without_stretching() {
|
||||
fn double_click_fits_width_near_target_then_resets_without_stretching() {
|
||||
use pdf_presenter::presenter_ui::{zoom_geometry, zoom_gestures_in};
|
||||
for (dimensions, expected) in [([210, 297], 2.8285716), ([400, 100], 1.), ([10, 1000], 8.)] {
|
||||
let ctx = Context::default();
|
||||
let target = Rect::from_min_size(Pos2::new(40., 40.), Vec2::new(400., 200.));
|
||||
let center = target.center();
|
||||
let page = pdf_presenter::presenter_ui::fitted_slide(target, dimensions);
|
||||
let click_position = Pos2::new(page.center().x, page.top() + page.height() * 0.95);
|
||||
let mut view = View::default();
|
||||
let mut time = 0.;
|
||||
let mut render = |events| {
|
||||
|
|
@ -626,8 +627,8 @@ fn double_click_fits_width_then_resets_without_stretching() {
|
|||
);
|
||||
view
|
||||
};
|
||||
render(vec![egui::Event::PointerMoved(center)]);
|
||||
for expected_scale in [expected, 1.] {
|
||||
render(vec![egui::Event::PointerMoved(click_position)]);
|
||||
for (index, expected_scale) in [expected, 1.].into_iter().enumerate() {
|
||||
for _ in 0..20 {
|
||||
render(vec![]);
|
||||
}
|
||||
|
|
@ -635,7 +636,7 @@ fn double_click_fits_width_then_resets_without_stretching() {
|
|||
for _ in 0..2 {
|
||||
for pressed in [true, false] {
|
||||
actual = render(vec![egui::Event::PointerButton {
|
||||
pos: center,
|
||||
pos: click_position,
|
||||
button: egui::PointerButton::Primary,
|
||||
pressed,
|
||||
modifiers: Default::default(),
|
||||
|
|
@ -643,7 +644,14 @@ fn double_click_fits_width_then_resets_without_stretching() {
|
|||
}
|
||||
}
|
||||
assert!((actual.scale - expected_scale).abs() < 0.0001);
|
||||
assert_eq!(actual.center, [0.5; 2]);
|
||||
if index == 0 && expected_scale > 1. {
|
||||
let (_, uv) = zoom_geometry(target, dimensions, actual, false);
|
||||
let expected_y = 0.95_f32.min(1. - uv.height() * 0.5);
|
||||
assert!((actual.center[1] - expected_y).abs() < 0.0001);
|
||||
assert_eq!(actual.center[0], 0.5);
|
||||
} else {
|
||||
assert_eq!(actual.center, [0.5; 2]);
|
||||
}
|
||||
if actual.scale > 1. && actual.scale < 8. {
|
||||
let (draw, uv) = zoom_geometry(target, dimensions, actual, false);
|
||||
assert!((draw.width() - target.width()).abs() < 0.001);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,14 @@
|
|||
|
||||
## Unreleased
|
||||
|
||||
### 0.1.63
|
||||
|
||||
- Aim double-click fit-width zoom at the clicked page position instead of always
|
||||
centering the page. Clamp the crop at page edges as a best effort; a second
|
||||
double-click still resets to the whole page. Keep shared presenter/output zoom.
|
||||
Linux checks pass with 86.42% whole-application coverage; the release binary
|
||||
is rebuilt. Physical pointer/display acceptance remains separate.
|
||||
|
||||
### 0.1.62
|
||||
|
||||
- Keep the default timer at zero when a deck's initial slide is merely displayed.
|
||||
|
|
|
|||
|
|
@ -337,7 +337,8 @@ the visible area, not the cached image resolution.
|
|||
to zoom in/out (1×–8×). The point under the mouse stays anchored when possible.
|
||||
- Hold the left mouse button and drag to move the enlarged image. Movement stops
|
||||
at the page edges. When viewing the whole page, **double-click to fit its width**
|
||||
to the presentation screen (up to 8×). Double-click again
|
||||
to the presentation screen (up to 8×) and aim the crop near the point clicked.
|
||||
Near page edges, the crop stops at the edge as closely as possible. Double-click again
|
||||
while zoomed to reset to the complete fitted page. Pages already filling the
|
||||
width stay unchanged. The optional fixed page area still applies if enabled.
|
||||
- **Menu → Page zoom** also has a zoom slider and **Reset zoom** button. If the
|
||||
|
|
|
|||
Loading…
Reference in New Issue