Center page navigation and fit page size hint (#8989)

This commit is contained in:
FredApps committed 2026-12-01 17:38:22 +01:00
1 parent 4b570930e5
commit 04c0aa7c73
3 files changed
+41 -8

No files matched your search

+5 -8
View File
@@ -21,14 +21,11 @@ pub(super) fn page_size_hint(ui: &mut egui::Ui, body: &PageBody<'_>, page: &pdfc
return;
}
let text = units.size(f64::from(page.width), f64::from(page.height));
// PLAN: a card notice is the framework's floating label with no interaction; its own surface padding is the inset.
// Shrink-wrapped to its text, a little in from the corner, as production's pill sits.
let font = egui::TextStyle::Body.resolve(ui.style());
let wide = ui.painter().layout_no_wrap(text.to_string(), font, egui::Color32::WHITE).size().x + 40.0;
let corner = egui::Rect::from_min_max(
egui::pos2(body.rect.min.x + 10.0, body.rect.min.y),
egui::pos2(body.rect.min.x + 10.0 + wide, body.rect.max.y - 10.0),
);
// The card measures its own text and surface padding in the active theme. Give it the
// available document width instead of guessing that width with egui's unrelated Body font.
let left = (body.rect.min.x + 10.0).min(body.rect.max.x);
let right = (body.rect.max.x - 10.0).max(left);
let corner = egui::Rect::from_min_max(egui::pos2(left, body.rect.min.y), egui::pos2(right, (body.rect.max.y - 10.0).max(body.rect.min.y)));
let builder = egui::UiBuilder::new().max_rect(corner).layout(egui::Layout::bottom_up(egui::Align::Min)).sense(egui::Sense::hover());
ui.scope_builder(builder, |ui| {
Bar::new(Tone::Neutral, text).layout(NoticeLayout::Card).icon(NoticeIcon::None).show(ui);
+1
View File
@@ -42,6 +42,7 @@ fn controls(app: &mut PdfCraftApp, ui: &mut Ui) {
let (field_rect, _) = ui.allocate_exact_size(field_size, egui::Sense::hover());
let edit = TextField::new("Current page", Bind::bound(&mut view.page_input))
.id(input_id)
.centred()
.select_on_focus()
.select_all(reselect)
.submits()
+35
View File
@@ -2116,6 +2116,41 @@ fn the_edit_panel_keeps_the_add_update_remove_menu() {
h.get_by_label("Cancel");
}
/// #8989: the editable page label is centred in its rail field without changing navigation,
/// and the page-size hint has room for its whole text inside the document area.
#[test]
fn page_rail_value_is_centred_and_page_size_hint_fits() {
let mut h = harness(|app| {
app.open_bytes(&egui::Context::default(), "rail.pdf", None, FIXTURE.to_vec()).unwrap();
});
let page_field = |h: &Harness<'static, PdfCraftApp>| h.get(By::new().role(egui::accesskit::Role::TextInput).label("Current page")).rect();
let check = |h: &Harness<'static, PdfCraftApp>, value: &str| {
let field = page_field(h);
let text = painted_text(h).into_iter().find(|(s, _, r)| s == value && field.contains_rect(*r)).expect("the page value is painted");
assert!(!text.1 && (text.2.center().x - field.center().x).abs() <= 3.0, "{text:?} in {field:?}");
assert!((text.2.center().y - field.center().y).abs() <= 2.0, "{text:?} in {field:?}");
};
check(&h, "1");
h.get(By::new().role(egui::accesskit::Role::TextInput).label("Current page")).focus();
h.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::A);
h.get(By::new().role(egui::accesskit::Role::TextInput).label("Current page")).type_text("2");
h.key_press(egui::Key::Enter);
h.run_steps(3);
assert_eq!(h.state().views[0].current(), 1, "the centred field still navigates");
check(&h, "2");
let area = h.state().views[0].viewport_rect();
let size = {
let app = h.state();
let p = &app.session.get(app.views[0].id).unwrap().info.pages[1];
app.units.size(f64::from(p.width), f64::from(p.height))
};
h.event(egui::Event::PointerMoved(area.left_bottom() + egui::vec2(80.0, -80.0)));
h.run_steps(3);
let text = painted_text(&h).into_iter().find(|(s, _, _)| s == &size).expect("the page size is painted");
assert!(!text.1 && area.contains_rect(text.2), "whole size {text:?} inside {area:?}");
}
/// #3282: in a short window the rail's panel buttons scroll above the page navigation instead of
/// being drawn under the page number field.
#[test]