fix(ui): the rail's page and zoom fields are wide enough for "6400%", and the sliver size is named (#5636)

At 36 pt the largest zoom was cut off at the right. The fields are 42 pt, set by RAIL_FIELD_SIZE
and pinned in the rail test. The one-pixel tolerance in bookmark_position is the constant SLIVER.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
RiceDeeandClaude Sonnet 5.5 committed 2026-11-01 18:46:01 +11:00
1 parent 461200e74a
commit 3896e6c30a
3 files changed
+11 -3

No files matched your search

+5 -2
View File
@@ -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;
+4 -1
View File
@@ -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
}
+2
View File
@@ -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:?})");