PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust
fix(ui): dialog buttons hug their content; no page cursors under modals
alehelfb1054099018
diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rsindex bf21cd38c..bfb8d9aa7 100644--- a/crates/ui-egui/src/dialogs.rs+++ b/crates/ui-egui/src/dialogs.rs@@ -10,6 +10,12 @@ use crate::{CloseRequest, Dialog, PdfCraftApp, PropsTab, panels::human_size, widconst INFO_KEYS: [&str; 4] = ["Title", "Author", "Subject", "Keywords"];pub fn show(app: &mut PdfCraftApp, ctx: &egui::Context) {+ // The page sets hover cursors from the raw pointer position (form fields, links, comments)+ // before any dialog is drawn, and nothing under a modal's backdrop takes clicks. Start from+ // the arrow; the modal's own widgets set theirs as they are drawn.+ if app.modal_open() || ctx.memory(|m| m.top_modal_layer().is_some()) {+ ctx.set_cursor_icon(egui::CursorIcon::Default);+ }dialogs(app, ctx);// Last, so it sits above Document Properties when Security's Unlock… asked for it.unlock(app, ctx);@@ -1201,43 +1207,47 @@ fn dialogs(app: &mut PdfCraftApp, ctx: &egui::Context) {}ui.add_space(16.0);let changed = draft_changes(app).is_some_and(|c| !c.is_empty());- ui.with_layout(Layout::right_to_left(Align::Center), |ui| {- if dialog == Dialog::Recovery {- if widgets::pill_button(ui, tl!("Recover"), true).clicked() {- recover = Some(true);- close = true;- }- if widgets::pill_button(ui, tl!("Discard"), false).clicked() {- recover = Some(false);- close = true;- }- } else if dialog == Dialog::NumberPages {- if widgets::pill_button(ui, tl!("OK"), true).clicked() {- apply_number = true;- close = true;- }- if widgets::pill_button(ui, tl!("Cancel"), false).clicked() {- close = true;- }- } else if dialog == Dialog::Split {- if ui.add_enabled_ui(split_ready.is_some(), |ui| widgets::pill_button(ui, tl!("Split"), true)).inner.clicked() {- split_now = split_ready.clone();- close = true;- }- if widgets::pill_button(ui, tl!("Cancel"), false).clicked() {- close = true;- }- } else if changed {- if widgets::pill_button(ui, tl!("OK"), true).clicked() {- apply = true;- close = true;- }- if widgets::pill_button(ui, tl!("Cancel"), false).clicked() {+ // One row high: on its own, a right-to-left layout centres the buttons in all the height+ // left, which after a taller Properties tab is the room that tab left behind.+ ui.horizontal(|ui| {+ ui.with_layout(Layout::right_to_left(Align::Center), |ui| {+ if dialog == Dialog::Recovery {+ if widgets::pill_button(ui, tl!("Recover"), true).clicked() {+ recover = Some(true);+ close = true;+ }+ if widgets::pill_button(ui, tl!("Discard"), false).clicked() {+ recover = Some(false);+ close = true;+ }+ } else if dialog == Dialog::NumberPages {+ if widgets::pill_button(ui, tl!("OK"), true).clicked() {+ apply_number = true;+ close = true;+ }+ if widgets::pill_button(ui, tl!("Cancel"), false).clicked() {+ close = true;+ }+ } else if dialog == Dialog::Split {+ if ui.add_enabled_ui(split_ready.is_some(), |ui| widgets::pill_button(ui, tl!("Split"), true)).inner.clicked() {+ split_now = split_ready.clone();+ close = true;+ }+ if widgets::pill_button(ui, tl!("Cancel"), false).clicked() {+ close = true;+ }+ } else if changed {+ if widgets::pill_button(ui, tl!("OK"), true).clicked() {+ apply = true;+ close = true;+ }+ if widgets::pill_button(ui, tl!("Cancel"), false).clicked() {+ close = true;+ }+ } else if widgets::pill_button(ui, tl!("Close"), true).clicked() {close = true;}- } else if widgets::pill_button(ui, tl!("Close"), true).clicked() {- close = true;- }+ })});});if let Some(yes) = recover {diff --git a/crates/ui-egui/tests/dialog_chrome.rs b/crates/ui-egui/tests/dialog_chrome.rsindex e21363535..ce8c9d5a6 100644--- a/crates/ui-egui/tests/dialog_chrome.rs+++ b/crates/ui-egui/tests/dialog_chrome.rs@@ -167,3 +167,54 @@ fn space_audit_tab_measures_the_file_and_stays_in_the_card() {assert!(pct.right() <= card.right() - 16.0, "Percentage {pct:?} in {card:?}");}}++#[test]+fn dialog_buttons_follow_the_content_after_a_taller_tab() {+ use pdfcraft_ui_egui::{Dialog, PropsTab};+ let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(|_cc| {+ let mut app = PdfCraftApp::new();+ app.set_option("language", "en").unwrap();+ app.open_bytes("doc.pdf", None, fixture()).unwrap();+ app.dialog = Some(Dialog::Properties(PropsTab::InitialView));+ app+ });+ h.run_steps(4);+ h.state_mut().dialog = Some(Dialog::Properties(PropsTab::Description));+ h.run_steps(4);+ // The card shrinks back to the shorter tab: Close sits under the last row, not halfway+ // down the room the taller tab left behind.+ let last = h.get_by_label("PDF producer").rect();+ let close = h.get_by_role_and_label(Role::Button, "Close").rect();+ assert!(close.top() - last.bottom() <= 40.0, "Close {close:?} under the last row {last:?}");+ let card = card(&h, "dialog");+ assert!(card.bottom() - close.bottom() <= 24.0, "Close {close:?} at the foot of {card:?}");+}++#[test]+fn page_hover_cursors_stay_off_while_a_dialog_is_open() {+ let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(|_cc| {+ let mut app = PdfCraftApp::new();+ app.set_option("language", "en").unwrap();+ app.open_bytes("form.pdf", None, include_bytes!("data/form.pdf").to_vec()).unwrap();+ // Small enough that the check box sits above the dialog card.+ app.set_option("zoom", "100").unwrap();+ app+ });+ for _ in 0..30 {+ h.run_steps(2);+ }+ // The middle of the "agree" check box (/Rect [20 310 36 326] on a 300 × 400 page).+ let page = h.state().views[0].page_screen_rect(0).expect("on screen");+ let k = page.width() / 300.0;+ let check = page.min + egui::vec2(28.0 * k, (400.0 - 318.0) * k);+ h.hover_at(check);+ h.run_steps(2);+ assert_eq!(h.output().platform_output.cursor_icon, egui::CursorIcon::PointingHand, "the check box takes clicks");+ h.state_mut().set_option("dialog", "security").unwrap();+ h.run_steps(4);+ let card = card(&h, "dialog");+ assert!(!card.contains(check), "the check box {check:?} is beside the dialog {card:?}, under its backdrop");+ h.hover_at(check + egui::vec2(1.0, 0.0));+ h.run_steps(2);+ assert_eq!(h.output().platform_output.cursor_icon, egui::CursorIcon::Default, "nothing under the dialog's backdrop can be clicked");+}