diff --git a/crates/ui-egui/src/canvas/navigation.rs b/crates/ui-egui/src/canvas/navigation.rs index b8a53d7c8b..8f88fff7a4 100644 --- a/crates/ui-egui/src/canvas/navigation.rs +++ b/crates/ui-egui/src/canvas/navigation.rs @@ -32,7 +32,7 @@ impl DocView { // of pages of different heights, whose shorter page can start below it), else the // nearest one below. let top = self.viewport_screen.top(); - // A page showing less than a pixel is rounding, not what the reader is looking at: a jump + // A page showing less than SLIVER is rounding, not what the reader is looking at: a jump // to the next page leaves the previous one's bottom edge within a pixel of the top. Such a // sliver still counts when nothing else shows (the last page at the very end). let pick = |slack: f32| { @@ -42,7 +42,7 @@ impl DocView { .min_by_key(|(p, _)| *p) .or_else(|| showing().min_by(|a, b| a.1.rect.top().total_cmp(&b.1.rect.top()).then(a.0.cmp(&b.0)))) }; - let (page, xf) = pick(1.0).or_else(|| pick(0.0))?; + let (page, xf) = pick(SLIVER).or_else(|| pick(0.0))?; let p = info.pages.get(*page)?; // Above the page (in the gap before it) is the page's own top. The window's vertical is // the view's y, or its x when the view is turned a quarter. @@ -460,3 +460,6 @@ pub fn shortcuts(view: &mut DocView, ctx: &egui::Context, speed: crate::scroll_s /// How far ↓ / ↑ scroll at Normal speed (Scroll speed halves or doubles it). Page Down / Page Up /// keep this much of the previous screen in view. const KEY_SCROLL_LINE: f32 = 40.0; +/// How much of a page must show at the window's top edge to count as the page there, in points: less +/// is rounding, since page rectangles snap to whole pixels. +const SLIVER: f32 = 1.0; diff --git a/crates/ui-egui/src/chrome.rs b/crates/ui-egui/src/chrome.rs index eb3074b724..eb795c833a 100644 --- a/crates/ui-egui/src/chrome.rs +++ b/crates/ui-egui/src/chrome.rs @@ -531,6 +531,9 @@ pub fn mode_bar(app: &mut PdfCraftApp, ui: &mut egui::Ui) { }); } +/// The size of the rail's page and zoom fields: wide enough for "6400%", the largest zoom, in the +/// 12 pt font, and inside the 45 pt the rail leaves. +const RAIL_FIELD_SIZE: [f32; 2] = [42.0, 22.0]; /// Padding inside the rail's page and zoom fields. const RAIL_FIELD_MARGIN: egui::Vec2 = egui::vec2(1.0, 4.0); @@ -543,7 +546,7 @@ fn rail_field(ui: &mut egui::Ui, t: &Tokens, edit: egui::TextEdit<'_>) -> egui:: .corner_radius(CornerRadius::same(5)) .show(ui, |ui| { ui.spacing_mut().interact_size.x = 0.0; - ui.add_sized([34.0, 22.0], edit) + ui.add_sized(RAIL_FIELD_SIZE, edit) }) .inner } diff --git a/crates/ui-egui/tests/it/content.rs b/crates/ui-egui/tests/it/content.rs index 55a78dfbab..c65ff47c88 100644 --- a/crates/ui-egui/tests/it/content.rs +++ b/crates/ui-egui/tests/it/content.rs @@ -1438,6 +1438,8 @@ fn rail_page_and_zoom_fields_match_and_fit_the_rail() { let rail = h.get_by_label("Bookmarks").rect(); let (page, zoom) = (h.get_by_label("Current page").rect(), h.get_by_label("Zoom").rect()); assert_eq!((page.width(), page.height()), (zoom.width(), zoom.height()), "{page:?} vs {zoom:?}"); + // The size `RAIL_FIELD_SIZE` sets: wide enough for "6400%", the largest zoom. + assert_eq!((page.width(), page.height()), (42.0, 22.0), "{page:?}"); for r in [page, zoom] { assert!(r.left() >= rail_left && r.right() <= rail_right, "{r:?} is cut off by the rail ({rail_left}..{rail_right})"); assert!((r.center().x - rail.center().x).abs() < 1.0, "{r:?} is off the rail's centre ({rail:?})");