From 874efb45762130eaafa2f7f5f43e485acdadb2a6 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Mon, 23 Nov 2026 08:27:17 -0500 Subject: [PATCH] fw sync: F-P4: PrintPanel/PrintDialog/HostedPrint printer_search opt-in (Search printers field, No printers match., Save as PDF kept, 430 pt list); Select search_label, no_matches, search_kept, list_width; trials printer_picker_filters_a_large_fleet_without_changing_the_selection, printer_picker_keeps_save_as_pdf_available_when_the_filter_matches_nothing, printer_picker_scrolls_long_names_without_losing_the_search_or_pdf_choice --- crates/print/src/ui/dialog.rs | 14 ++++ crates/print/src/ui/panel.rs | 30 ++++++- crates/print/tests/it/panel.rs | 100 ++++++++++++++++++++++++ crates/ui-widgets/src/pickers/search.rs | 19 ++++- crates/ui-widgets/src/pickers/select.rs | 58 +++++++++++++- 5 files changed, 211 insertions(+), 10 deletions(-) diff --git a/crates/print/src/ui/dialog.rs b/crates/print/src/ui/dialog.rs index 1e3aa2613..ed20fad3a 100644 --- a/crates/print/src/ui/dialog.rs +++ b/crates/print/src/ui/dialog.rs @@ -733,6 +733,9 @@ pub struct PrintDialog<'a> { /// The pager under the sheet preview in the `Document` layout. #[prop] preview_pager: Option, + /// The printer list searches a long fleet ([`PrintPanel::printer_search`]). + #[prop] + printer_search: bool, /// Makes Print keep the dialog open and report its press in `PrintDialogOutput::held`. #[prop(vis = "pub(crate)")] hold_ok: bool, @@ -801,6 +804,7 @@ impl<'a> PrintDialog<'a> { driver: DriverControls::None, duplex_by_layout: false, preview_pager: None, + printer_search: false, hold_ok: false, finish_held: false, refusal: None, @@ -826,6 +830,7 @@ impl<'a> PrintDialog<'a> { driver, duplex_by_layout, preview_pager, + printer_search, hold_ok, finish_held, refusal, @@ -883,6 +888,7 @@ impl<'a> PrintDialog<'a> { .destinations(destinations) .duplex_by_layout(duplex_by_layout) .inline(document) + .printer_search(printer_search) .show(ui); refresh |= panel.refresh; settings_clicked |= panel.settings_clicked; @@ -1005,6 +1011,7 @@ pub struct HostedPrint { driver: DriverControls, duplex_by_layout: bool, preview_pager: Option, + printer_search: bool, /// The destination the user picked, or automation set, not taken yet. printer_chosen: Option, /// Whether Print files its answer for the app instead of closing. @@ -1038,6 +1045,7 @@ impl HostedPrint { driver: DriverControls::None, duplex_by_layout: false, preview_pager: None, + printer_search: false, printer_chosen: None, hold: false, held: HeldAnswer::new(), @@ -1146,6 +1154,11 @@ impl HostedPrint { self.preview_pager = pager; } + /// Whether the printer list searches a long fleet ([`PrintPanel::printer_search`]). + pub fn set_printer_search(&mut self, on: bool) { + self.printer_search = on; + } + /// The pager press since the last call. pub fn take_preview_step(&mut self) -> Option { self.requests.take_preview_step() @@ -1248,6 +1261,7 @@ impl StackDialog for HostedPrint { .layout(self.layout) .driver(self.driver) .duplex_by_layout(self.duplex_by_layout) + .printer_search(self.printer_search) .hold_ok(self.hold) .finish_held(finish_held); if let Some(pager) = self.preview_pager.clone() { diff --git a/crates/print/src/ui/panel.rs b/crates/print/src/ui/panel.rs index d6bfb7c68..092080fc8 100644 --- a/crates/print/src/ui/panel.rs +++ b/crates/print/src/ui/panel.rs @@ -42,6 +42,8 @@ craft_ui::words! { save_as_pdf: "printPanel.saveAsPdf" = "Save as PDF"; default_mark: "printPanel.defaultMark" = "(default)"; finding: "printPanel.finding" = "Finding printers…"; + search_printers: "printPanel.searchPrinters" = "Search printers"; + no_printers_match: "printPanel.noPrintersMatch" = "No printers match."; } } @@ -138,8 +140,16 @@ pub struct PrintPanel<'a> { /// Why the driver gave no page. #[prop] page_error: Option, + /// The printer list is for a long fleet: a "Search printers" field heads it, focused as it opens, and narrows the + /// printers by their names (case and accents ignored) while Save as PDF stays at the end; typing changes no choice, + /// only a pick does, and the open list is wide enough for long names (PRINTER_LIST_WIDTH, within the screen). + #[prop] + printer_search: bool, } +/// How wide a searchable printer list opens, in points: room for a long network queue's name. +pub const PRINTER_LIST_WIDTH: f32 = 430.0; + impl<'a> PrintPanel<'a> { /// The panel over `settings`, offering `printers`. pub fn new(settings: Bind<'a, Settings>, printers: &'a [Printer]) -> Self { @@ -154,12 +164,14 @@ impl<'a> PrintPanel<'a> { inline: false, page: None, page_error: None, + printer_search: false, } } /// Shows the panel. pub fn show(self, ui: &mut Ui) -> PrintPanelOutput { - let PrintPanel { settings, printers, discovering, busy, driver, destinations, duplex_by_layout, inline, page, page_error } = self; + let PrintPanel { settings, printers, discovering, busy, driver, destinations, duplex_by_layout, inline, page, page_error, printer_search } = + self; let env = Env::of(ui); let words = env.words::(); let mut queues: Vec> = printers @@ -193,10 +205,20 @@ impl<'a> PrintPanel<'a> { let mut now = before.clone(); Field::new(words.printer.clone()).id_salt("printer").show(ui, |ui, _| { Row::new().show(ui, |ui, _| { - let picked = Select::new(words.printer.clone(), Bind::given(now.destination.clone()), &queues) + let select = Select::new(words.printer.clone(), Bind::given(now.destination.clone()), &queues) .placeholder(placeholder.clone()) - .id_salt("queue") - .show(ui); + .id_salt("queue"); + let select = if printer_search { + select + .searchable() + .search_label(words.search_printers.clone()) + .no_matches(words.no_printers_match.clone()) + .search_kept(|destination: &Destination| *destination == Destination::File) + .list_width(PRINTER_LIST_WIDTH) + } else { + select + }; + let picked = select.show(ui); if let Some(destination) = picked.value() { if *destination != now.destination { printer_chosen = Some(destination.clone()); diff --git a/crates/print/tests/it/panel.rs b/crates/print/tests/it/panel.rs index 9965f7eb5..cfdd874ef 100644 --- a/crates/print/tests/it/panel.rs +++ b/crates/print/tests/it/panel.rs @@ -53,3 +53,103 @@ fn a_printer_with_its_own_dialog_disables_the_job_controls() { pick(&mut fixture, "Browser", "Office"); assert_eq!(disabled(&fixture), [false; 4], "a printer without its own dialog enables them again"); } + +/// The long last queue of the trial fleet. +const LAST: &str = "München Satellite 119 - Engineering floor 4 (network queue) - colour duplex device, Building North"; + +/// A searchable panel over a fleet of 120 queues, Save as PDF after them, the first queue the default and chosen; the +/// settings it edits. +fn fleet(room: Vec2) -> (Fixture, Rc>) { + use craft_print::ui::Destinations; + let settings = Rc::new(RefCell::new(Settings::default())); + let first = "Office 000 - Engineering floor 4 (network queue)"; + settings.borrow_mut().destination = Destination::Printer(first.into()); + let shown = Rc::clone(&settings); + let mut printers: Vec = + (0..119).map(|i| Printer::new(format!("Office {i:03} - Engineering floor 4 (network queue)")).is_default(i == 0)).collect(); + printers.push(Printer::new(LAST)); + let mut fixture = Fixture::new(move |ui| { + let _ = PrintPanel::new(Bind::bound(&mut *shown.borrow_mut()), &printers) + .destinations(Destinations::PrintersAndFile) + .printer_search(true) + .show(ui); + }); + fixture.room(room); + fixture.settle(); + (fixture, settings) +} + +/// Opens the printer list, which shows `value`. +fn open_list(fixture: &mut Fixture, value: &str) { + let list = + fixture.by_role(Role::COMBO_BOX).into_iter().find(|list| fixture.tree().value_of(list.node).is_some_and(|shown| shown.starts_with(value))); + let list = list.unwrap_or_else(|| panic!("the printer list shows {value}")); + fixture.click(&list).idle(3); +} + +/// Searching folds the names and changes no choice; a pick chooses and closes the list, and the list opens again on +/// the whole fleet (upstream PdfCraft printer_picker_filters_a_large_fleet_without_changing_the_selection). +#[trial] +fn printer_picker_filters_a_large_fleet_without_changing_the_selection() { + let (mut fixture, settings) = fleet(Vec2::new(1400.0, 900.0)); + let initial = settings.borrow().destination.clone(); + open_list(&mut fixture, "Office 000"); + let search = fixture.by_label("Search printers").expect("the search field heads the list"); + assert!(search.rect.width() > 350.0, "room for long device names: {:?}", search.rect); + fixture.type_text(" MÜNCHEN satellite ").idle(3); + assert_eq!(settings.borrow().destination, initial, "typing is not a printer choice"); + assert!(fixture.by_label("Office 001 - Engineering floor 4 (network queue)").is_none(), "the search hides the other queues"); + let last = fixture.by_label(LAST).expect("the search finds the queue"); + fixture.click(&last).idle(3); + assert_eq!(settings.borrow().destination, Destination::Printer(LAST.into()), "the pick chooses the queue"); + assert!(fixture.by_label("Search printers").is_none(), "choosing closes the list"); + + open_list(&mut fixture, "München"); + let search = fixture.by_label("Search printers").expect("the list opens again"); + assert!(fixture.tree().value_of(search.node).is_none_or(str::is_empty), "the search starts empty: the whole fleet shows again"); + assert!(fixture.by_label("No printers match.").is_none()); +} + +/// Save as PDF stays a destination when no queue matches the search, and choosing it does not print +/// (upstream printer_picker_keeps_save_as_pdf_available_when_the_filter_matches_nothing). +#[trial] +fn printer_picker_keeps_save_as_pdf_available_when_the_filter_matches_nothing() { + let (mut fixture, settings) = fleet(Vec2::new(1400.0, 900.0)); + let initial = settings.borrow().destination.clone(); + open_list(&mut fixture, "Office 000"); + let search = fixture.by_label("Search printers").expect("the search field heads the list"); + fixture.click(&search).idle(2); + assert!(fixture.by_label("Search printers").is_some(), "a click in the search keeps the list open"); + fixture.type_text("no-such-printer").idle(3); + assert!(fixture.by_label("No printers match.").is_some(), "the list says no queue matches"); + assert_eq!(settings.borrow().destination, initial); + let pdf = fixture.by_label("Save as PDF").expect("Save as PDF stays in the list"); + fixture.click(&pdf).idle(3); + assert_eq!(settings.borrow().destination, Destination::File, "the pick chooses Save as PDF"); + assert!(fixture.by_label("Search printers").is_none(), "choosing closes the list"); +} + +/// In a smaller window the list keeps long names within the screen, the search and Save as PDF on it, and reopens +/// with the chosen queue in sight (upstream printer_picker_scrolls_long_names_without_losing_the_search_or_pdf_choice). +#[trial] +fn printer_picker_scrolls_long_names_without_losing_the_search_or_pdf_choice() { + let size = Vec2::new(1024.0, 768.0); + let (mut fixture, settings) = fleet(size); + open_list(&mut fixture, "Office 000"); + fixture.type_text("münchen").idle(3); + let last = fixture.by_label(LAST).expect("the search finds the queue"); + assert!(last.rect.left() >= 0.0 && last.rect.right() <= size.x, "the long name stays within the screen: {:?}", last.rect); + fixture.click(&last).idle(3); + assert_eq!(settings.borrow().destination, Destination::Printer(LAST.into())); + + open_list(&mut fixture, "München"); + let search = fixture.by_label("Search printers").expect("the search field heads the list").rect; + let row = fixture.by_label(LAST).expect("the chosen queue shows").rect; + assert!(search.top() >= 0.0 && row.top() >= search.bottom() && row.bottom() <= size.y, "the chosen queue {row:?} is in sight on reopening"); + fixture.key(egui::Key::End, egui::Modifiers::NONE).idle(3); + let pdf = fixture.by_label("Save as PDF").expect("Save as PDF ends the list").rect; + assert!(pdf.bottom() <= size.y, "Save as PDF is on screen: {pdf:?}"); + let pdf = fixture.by_label("Save as PDF").expect("Save as PDF ends the list"); + fixture.click(&pdf).idle(3); + assert_eq!(settings.borrow().destination, Destination::File, "the PDF row is clickable with the whole fleet shown"); +} diff --git a/crates/ui-widgets/src/pickers/search.rs b/crates/ui-widgets/src/pickers/search.rs index 9a808e3c6..70e9b9926 100644 --- a/crates/ui-widgets/src/pickers/search.rs +++ b/crates/ui-widgets/src/pickers/search.rs @@ -3,7 +3,7 @@ use super::words::PickerWords; use crate::contract::overlay::Popup; -use crate::contract::{Bind, BodyCx, Component, Cx, PopupHandle, Remember as _, Show as _, WordSetCx as _}; +use crate::contract::{Bind, BodyCx, Component, Cx, PopupHandle, Props as _, Remember as _, Show as _, Sizing, WordSetCx as _}; use crate::runtime::env::Label; use crate::runtime::focus::{self, FocusTarget}; use crate::text::TextField; @@ -21,13 +21,28 @@ struct Query { /// the query. The dropdown leaves the key focus on the picker; the field takes it once the layer has recorded the /// picker as its opener, so typing reaches the field. pub(super) fn show(ui: &mut Ui, body: &mut BodyCx<'_>, popup: PopupHandle, cx: &Cx<'_, C>, owner: &Label, list: Id) -> String { + show_named(ui, body, popup, cx, owner, (None, false), list) +} + +/// [`show`] with the field named `named` when given, filling the popup's width with `fill`. +pub(super) fn show_named( + ui: &mut Ui, + body: &mut BodyCx<'_>, + popup: PopupHandle, + cx: &Cx<'_, C>, + owner: &Label, + (named, fill): (Option<&Label>, bool), + list: Id, +) -> String { let words = cx.words::(); let opening = Popup::opening(popup, cx); let typed = body.memory::(); if opening { *typed = Query::default(); } - let field = TextField::search(name(&words, owner), Bind::bound(&mut typed.text)).drives(list).show(ui); + let label = named.cloned().unwrap_or_else(|| name(&words, owner)); + let field = TextField::search(label, Bind::bound(&mut typed.text)).drives(list); + let field = if fill { field.sizing(Sizing::FillWidth) } else { field }.show(ui); let query = typed.text.clone(); let taken = &mut body.memory::().focused; if field.response.has_focus() { diff --git a/crates/ui-widgets/src/pickers/select.rs b/crates/ui-widgets/src/pickers/select.rs index 3a434196f..d59d0e544 100644 --- a/crates/ui-widgets/src/pickers/select.rs +++ b/crates/ui-widgets/src/pickers/select.rs @@ -16,6 +16,7 @@ use crate::contract::{ MeasureCx, Numeric, Overlay, OverlayUi, Overlays as _, PaintUi, PartsCx, Pointer as _, PopupHandle, PopupKind, Props as _, Role, Show as _, ShowCollection as _, ShowContainer as _, Sizing, WordSetCx as _, step_stop, step_stops, }; +use crate::display::{Shade, Text}; use crate::layout_components::Row; use crate::list::{List, ListRow, ThumbAspect}; use crate::menu::Menu; @@ -25,6 +26,7 @@ use crate::runtime::focus::FocusMove; use crate::runtime::overlay::CloseReason; use crate::style::{ComponentStyle, Ink, StyleCx, SurfaceLook, TextLook, TypeRole}; use craft_behavior::nav::{StepResult, ValueAxes, ValueSteps}; +use craft_behavior::overlay::MinWidth; use craft_behavior::{ CancelReason, GesturePhase, HitLevel, HitPriority, IconId, Metrics, NavMove, PartKey, Selection, Sense, TypeAhead, Value, WheelPhase, wheel_step, }; @@ -59,6 +61,17 @@ pub struct SelectStyle { /// The icon of the button in the popup header that opens the header menu. const HEADER_MENU_ICON: &str = "more"; +/// The options a searchable select keeps whatever the query: a destination of its own beside the searched ones (Save +/// as PDF among the printers). +struct SearchKept<'a, T>(Box bool + 'a>); + +impl<'a, T> SearchKept<'a, T> { + /// Keeps the options `kept` answers true for. + fn new(kept: impl Fn(&T) -> bool + 'a) -> Self { + SearchKept(Box::new(kept)) + } +} + /// The rows of the menu a select's popup header opens: the host's menu body. struct HeaderMenu<'a>(Box>); @@ -94,6 +107,18 @@ pub struct Select<'a, T: Value + 'static> { /// A filter field above the entries narrows them as the user types. #[prop(flag)] searchable: bool, + /// The search field's name; "{label} Search" without it. + #[prop(into)] + search_label: Option