diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 6c9cde7b4..9a94f4427 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -5585,6 +5585,39 @@ mod tests { } } + /// #2958: the Print button leads the settings, above the printer and the settings it prints + /// with (as in Word), and it wears the accent the app gives a dialog's primary button, so the + /// page's one action is found first and reads as one rather than as another setting. + #[test] + fn the_print_button_leads_the_settings_and_is_the_primary_action() { + use egui::accesskit::Role; + use egui_kittest::kittest::{By, Queryable}; + const BLURB: &str = "Send the document straight to the system print dialog, or save a copy in another format below."; + let mut a = app(); + a.services.print = Some(Box::new(|_| Ok(()))); + a.run("file.print", json!({})).unwrap(); + let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_ui_state( + |ui, app: &mut WordApp| { + let ctx = ui.ctx().clone(); + app.logic(&ctx); + app.ui(ui); + }, + a, + ); + for _ in 0..4 { + h.step(); + } + // The page's own Print button (the backstage list has a Print entry too): the last. + let print = h.query_all(By::new().role(Role::Button).label("Print")).last().expect("a Print button").rect(); + let blurb = h.get_by_label(BLURB).rect(); + assert!(print.min.y < blurb.min.y, "the Print button leads the settings: {print:?} above {blurb:?}"); + let accent = crate::theme::Tokens::get(&h.ctx).accent; + assert!( + h.output().shapes.iter().any(|s| matches!(&s.shape, egui::Shape::Rect(r) if r.rect == print && r.fill == accent)), + "the Print button is the primary (accent) button" + ); + } + /// #1156: the Print page's preview fills the pane beside the settings, zooms from its own /// bar, scrolls both ways once the page outgrows the pane, and One Page fits it again. #[test] diff --git a/crates/ui-egui/src/print_page.rs b/crates/ui-egui/src/print_page.rs index 9d093887f..a963bc57e 100644 --- a/crates/ui-egui/src/print_page.rs +++ b/crates/ui-egui/src/print_page.rs @@ -147,6 +147,17 @@ pub fn show(app: &mut WordApp, ui: &mut Ui) { ui.spacing_mut().item_spacing.y = 8.0; let native = app.services.print_native.is_some(); let hook = native || app.services.print.is_some(); + // #2958: as in Word, the page's action leads the settings, in the accent the app + // gives a dialog's primary button: the first thing seen, and plainly a button + // that prints now rather than one more setting in the list below. + if hook + && ui + .add_enabled(!native || app.printing.ready(), crate::widgets::primary_button(ui, tl!("Print")).min_size(vec2(320.0, 34.0))) + .clicked() + { + let params = app.ui.print.params(); + let _ = app.run("ui.print", params); + } if native { if let Some(discover) = &app.services.printers { crate::printing::show(&mut app.printing, ui, discover, |label| crate::i18n::t(label).to_owned()); @@ -160,18 +171,6 @@ pub fn show(app: &mut WordApp, ui: &mut Ui) { } else { ui.label(tl!("Save a copy in another format. Printing goes through a PDF you can print from any viewer.")); } - ui.add_space(4.0); - if hook - && ui - .add_enabled( - !native || app.printing.ready(), - egui::Button::new(egui::RichText::new(tl!("Print")).font(medium(13.5))).min_size(vec2(320.0, 34.0)), - ) - .clicked() - { - let params = app.ui.print.params(); - let _ = app.run("ui.print", params); - } if ui .add(egui::Button::new(egui::RichText::new(tl!("Save these pages as PDF…")).font(medium(13.5))).min_size(vec2(320.0, 34.0))) .clicked()