#2958: the Print page's button leads the settings, in the primary accent

File › Print put "Print" between the printer settings and the page
settings, styled like every other button there, so the page's one action
was hard to find and didn't read as an immediate action.

The button now comes first in the settings column, above the printer and
the settings it prints with, as Word has it, and wears the accent the app
gives a dialog's primary button (the file browser's Open and Save, OK and
Save in dialogs): the first thing seen, and plainly the action. It still
prints through `ui.print`, and it is still disabled while a native print
job is busy.
This commit is contained in:
SlavenDj committed 2026-10-19 20:09:16 +02:00
1 parent e6c5a701dd
commit 7360d50e72
2 files changed
+44 -12

No files matched your search

+33
View File
@@ -5270,6 +5270,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]
+11 -12
View File
@@ -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()