From b3970d12a121a9be70a9a53cb798efb8fa5cf4b9 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 22 Nov 2026 15:06:18 -0500 Subject: [PATCH] PageRangeOptions: document dialogs stack the radios and end the range in 'of N'; SelectedFromTo arrangement; subset_select for a row of its own (trial ...stack_under_their_heading_and_count_the_pages, does not compile on the old code) --- crates/pages/src/ui/range.rs | 37 +++++++++++++++++++++++++++------- crates/pages/tests/it/range.rs | 20 +++++++++--------- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/crates/pages/src/ui/range.rs b/crates/pages/src/ui/range.rs index e636dc4e2..500a00b10 100644 --- a/crates/pages/src/ui/range.rs +++ b/crates/pages/src/ui/range.rs @@ -47,7 +47,10 @@ craft_ui::words! { selection: "pageRangeOptions.selection" = "Selected pages"; pages_from: "pageRangeOptions.pagesFrom" = "Pages from"; to: "pageRangeOptions.to" = "to"; + /// After the last page field of a document dialog; `{count}` is the number of pages. + of_count: template "pageRangeOptions.ofCount" = "of {count}"; subset: "pageRangeOptions.subset" = "Subset"; + even_and_odd: "pageRangeOptions.evenAndOdd" = "Even and Odd Pages"; all_in_range: "pageRangeOptions.allInRange" = "All pages in range"; even_only: "pageRangeOptions.evenOnly" = "Even pages only"; odd_only: "pageRangeOptions.oddOnly" = "Odd pages only"; @@ -249,6 +252,9 @@ pub enum PageRangeChoices { FromTo, /// All pages, Current page and From and To, with no Subset. CurrentFromTo, + /// All pages, Selected pages and From and To, with no Subset (its own row, [`PageRangeOptions::subset_select`], + /// stands elsewhere in the dialog). + SelectedFromTo, } impl PageRangeChoices { @@ -259,7 +265,7 @@ impl PageRangeChoices { /// Whether the rows offer Selected pages. fn selection(self) -> bool { - self == PageRangeChoices::Selection + matches!(self, PageRangeChoices::Selection | PageRangeChoices::SelectedFromTo) } /// Whether the rows end with the Subset list. @@ -313,6 +319,23 @@ impl PageRangeOptions { } } + /// The Subset list alone, for a dialog row of its own (production's Rotate puts it first under "Rotate:"): it edits + /// the subset of the range kept under `key` (see [`param`](Self::param)). + pub fn subset_select(ui: &mut Ui, fields: &mut DialogFields, key: &str) -> Response { + let words = Env::of(ui).words::(); + let range = Self::value(fields, key).unwrap_or_default(); + let entries = [ + Entry::new(Subset::All, words.even_and_odd.clone()), + Entry::new(Subset::Even, words.even_only.clone()), + Entry::new(Subset::Odd, words.odd_only.clone()), + ]; + let picked = Select::new(words.subset.clone(), Bind::given(range.subset), &entries).show(ui); + if let Some(chosen) = picked.value().copied() { + fields.set(key.to_owned(), Self::field_value(&PageRange { subset: chosen, ..range })); + } + picked.response + } + /// The row's stored form of `range`, for the row's `opens_with`. pub fn field_value(range: &PageRange) -> FieldValue { // A `PageRange` is plain fields and enums, which always serialize; `Null` would read back as no range. @@ -375,6 +398,10 @@ impl PageRangeOptions { Row::new().show(ui, |ui, _| { Text::new(words.to.clone()).show(ui); to = whole(&field(&words.to, shown_to).show(ui).edit, shown_to); + if inline { + let count = env.format().integer(last as u64); + Text::new(words.of_count.fill(&[("count", count.as_str())])).show(ui); + } }); if inline && choices.subset() { Row::new().show(ui, |ui, _| { @@ -384,12 +411,8 @@ impl PageRangeOptions { } }); }; - if inline { - // One line: the radio buttons side by side as far as the room goes. - Row::new().wrap(true).show(ui, |ui, _| body(ui)); - } else { - Stack::new().show(ui, |ui, _| body(ui)); - } + // The radio buttons stack, in a document dialog as elsewhere: production's Pages group is a column. + Stack::new().show(ui, |ui, _| body(ui)); }); if let Some(scope) = group.output.value().copied() { next.scope = scope; diff --git a/crates/pages/tests/it/range.rs b/crates/pages/tests/it/range.rs index a60fb6060..34a1003b3 100644 --- a/crates/pages/tests/it/range.rs +++ b/crates/pages/tests/it/range.rs @@ -98,21 +98,23 @@ fn editing_to_preserves_from() { assert_eq!(range.pages(12, 2, &[]), vec![7], "a committed end below From still selects the starting page"); } -/// In a document dialog the page range options read as production's: the heading over one line holding the radio -/// buttons, the page fields and the subset, rather than a label beside a column of radio buttons. +/// In a document dialog the page range options read as production's: the heading over a column of radio buttons, the +/// page fields ending in "of N", and no Subset where the dialog keeps it in a row of its own. #[trial] -fn the_page_range_options_of_a_document_dialog_share_one_line_under_their_heading() { +fn the_page_range_options_of_a_document_dialog_stack_under_their_heading_and_count_the_pages() { use craft_ui::patterns::form_dialogs::{ParamDialog, ParamLayout}; let mut fixture = Fixture::new(|ui| { let mut fields = DialogFields::new(); - ParamDialog::new("range", "Add Watermark", vec![PageRangeOptions::param("pages", "Page range", 12, 2, PageRangeChoices::Acrobat)]).layout(ParamLayout::Document).values(Bind::bound(&mut fields)).show(ui); + ParamDialog::new("range", "Rotate", vec![PageRangeOptions::param("pages", "Pages", 12, 2, PageRangeChoices::SelectedFromTo)]) + .layout(ParamLayout::Document) + .values(Bind::bound(&mut fields)) + .show(ui); }); fixture.room(egui::vec2(1100.0, 700.0)); fixture.settle(); let at = |name: &str| fixture.by_label(name).unwrap_or_else(|| panic!("{name:?} is shown")).rect; - let (all, from, subset) = (at("All pages"), at("Pages from"), at("Subset")); - assert!((all.center().y - subset.center().y).abs() < 6.0, "All pages and Subset share a line: {all:?} {subset:?}"); - assert!((all.center().y - from.center().y).abs() < 6.0, "Pages from is on that line too: {all:?} {from:?}"); - let heading = fixture.texts().iter().find(|run| run.text.starts_with("Page range")).map(|run| run.rect).expect("the heading is painted"); - assert!(heading.max.y <= all.min.y + 2.0, "the heading is over the line: {heading:?} {all:?}"); + let (all, selected, from) = (at("All pages"), at("Selected pages"), at("Pages from")); + assert!(selected.min.y > all.max.y - 2.0 && from.min.y > selected.max.y - 2.0, "the radios stack: {all:?} {selected:?} {from:?}"); + assert!(fixture.texts().iter().any(|run| run.text == "of 12"), "the range ends in the page count"); + assert!(fixture.by_label("Subset").is_none(), "this arrangement has no Subset"); }