From 4ce921dd1b3778e7dd3f12f7516ffd25911aa10b Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 29 Nov 2026 00:59:38 -0800 Subject: [PATCH] Export for Screens: the items sit in a framed view, and checked items show selected The Artboards and Assets panes drew their list and grid with no frame and only as tall as their items, so with one artboard the view buttons, Clear Selection and Prefix sat right under the thumbnail with empty space below. The views were also shown without a selection, and the grid draws a tile's check from the tile's selection, so a checked artboard had no outline and its check box drew empty. - The list and the grid sit on a sunken surface with control padding, and keep their height (9 rows, 4 tiles) when fewer items are shown. - The checked items are bound as the view's selection, so they draw the selection outline and a checked box. The lead and anchor are kept per tab from pass to pass; the checks still decide which items are exported. --- .../ui-egui/src/dialogs/export_for_screens.rs | 46 +++++++++---- crates/ui-egui/src/dialogs/tests_screens.rs | 64 +++++++++++++++++++ 2 files changed, 98 insertions(+), 12 deletions(-) diff --git a/crates/ui-egui/src/dialogs/export_for_screens.rs b/crates/ui-egui/src/dialogs/export_for_screens.rs index bef9fda0f9..bfedfd4d7d 100644 --- a/crates/ui-egui/src/dialogs/export_for_screens.rs +++ b/crates/ui-egui/src/dialogs/export_for_screens.rs @@ -30,13 +30,13 @@ use std::borrow::Cow; use std::sync::Arc; -use craft::behavior::{ColumnKey, ColumnWidth, DisplayOrder, GesturePhase, IconId, ItemSource, SelectionChange}; +use craft::behavior::{ColumnKey, ColumnWidth, DisplayOrder, GesturePhase, IconId, ItemSource, Selection, SelectionChange}; use craft::host::PickRequest; use craft::ui::buttons::Button; use craft::ui::choice::{Checkbox, Radio, RadioGroup, Segmented}; use craft::ui::contract::{ - Bind, CollectionEvent, ColumnSpec, Entry, Props as _, Show as _, ShowCollection as _, ShowContainer as _, SpaceAction, SweepApply, SweepStep, - ToggleColumn, + Bind, CollectionEvent, ColumnSpec, Entry, Pad, Props as _, Show as _, ShowCollection as _, ShowContainer as _, SpaceAction, SweepApply, + SweepStep, ToggleColumn, }; use craft::ui::dialog::{DialogId, DialogResult, DialogStack, FieldRefusal, HeldAnswer, HeldOk, StackDialog, dialog_id}; use craft::ui::display::{Shade, Text}; @@ -46,6 +46,7 @@ use craft::ui::patterns::form_dialogs::{FormDialog, PathRow}; use craft::ui::primitives::{ContentPainterCx, fit_rect}; use craft::ui::runtime::env::Label; use craft::ui::runtime::focus::Initial; +use craft::ui::style::SurfaceKind; use craft::ui::tabs::{Tab, TabKind, TabStrip}; use craft::ui::text::TextField; use craft::ui::tile_grid::{Tile, TileGrid, TilePartEvent}; @@ -93,10 +94,11 @@ const SETTABLE: [&str; 20] = [ /// The check column of the list view and its name column. const CHECK: ColumnKey = ColumnKey::new("check"); const NAME: ColumnKey = ColumnKey::new("name"); -/// Rows of the list view and of the grid view the items pane shows before it scrolls, a pane as tall as the options -/// column's first sections. +/// How many items the list view and the grid view hold before they scroll, and how tall they are with fewer: a +/// missing item counts a control row, so the pane stays about as tall as the options column's first sections with +/// one artboard. The framework counts a grid's items, not its rows of tiles. const LIST_ROWS: u16 = 9; -const GRID_ROWS: u16 = 3; +const GRID_ITEMS: u16 = 4; /// The longest side of an artboard thumbnail, in pixels. const THUMB_PX: u32 = 92; @@ -219,6 +221,7 @@ pub fn open(app: &mut VectorcraftApp) { pending: None, renaming_in: None, rename: None, + leads: Default::default(), held: HeldAnswer::new(), }; if let Some(dialogs) = app.dialogs() { @@ -541,6 +544,8 @@ pub(crate) struct ExportForScreensDialog { renaming_in: Option<(u64, u64)>, /// A committed artboard name: ((document uid, reverts), artboard id, name), for the pump to run. rename: Option<((u64, u64), u32, String)>, + /// The lead and anchor of the Artboards and the Assets view, by tab. + leads: [Selection; 2], held: HeldAnswer>, } @@ -616,7 +621,7 @@ impl ExportForScreensDialog { let checked = |at: usize| on.get(at).copied().unwrap_or(false); let shelf = Shelf { items: &items, enabled: text(fields, "select") != "full", reveal: None, caption: &caption, checked: &checked, paint: &paint }; - let picks = shelf.show(ui, text(fields, "view") == "list"); + let picks = shelf.show(ui, text(fields, "view") == "list", &mut self.leads[0]); for key in picks.toggled { if let Some(b) = items.index_of(&key).and_then(|at| on.get_mut(at)) { *b ^= true; @@ -654,7 +659,7 @@ impl ExportForScreensDialog { let checked = |at: usize| items.0.get(at).is_some_and(|(id, _)| on.contains(id)); let reveal = fields.get("__scrollTo").and_then(Value::as_u64).filter(|id| items.index_of(id).is_some()); let shelf = Shelf { items: &items, enabled: true, reveal, caption: &caption, checked: &checked, paint: &paint }; - let picks = shelf.show(ui, text(fields, "view") == "list"); + let picks = shelf.show(ui, text(fields, "view") == "list", &mut self.leads[1]); for id in picks.toggled { if on.contains(&id) { on.retain(|a| *a != id); @@ -724,23 +729,30 @@ struct Shelf<'a> { } impl Shelf<'_> { - /// Shows the items as a list of rows (`list`) or a grid of tiles → what the user did to them. - fn show(self, ui: &mut Ui, list: bool) -> Picks { + /// Shows the items as a list of rows (`list`) or a grid of tiles in a sunken frame, with the checked items + /// selected → what the user did to them. `lead` holds the selection's lead and anchor from pass to pass; its + /// items are the checked ones. + fn show(self, ui: &mut Ui, list: bool, lead: &mut Selection) -> Picks { let Shelf { items, enabled, reveal, caption, checked, paint } = self; let mut picks = Picks::default(); let rename = reveal.is_none(); let at = |key: &u64| items.index_of(key).unwrap_or(usize::MAX); let state = |at: usize| if checked(at) { ToggleState::On } else { ToggleState::Off }; + let mut selection = Selection::new((0..items.len()).filter(|at| checked(*at)).map(|at| items.key(at)).collect(), lead.lead, lead.anchor); if list { let columns = vec![ColumnSpec::toggle(CHECK, Label::Empty, ToggleColumn::default()), ColumnSpec::new(NAME, Label::Empty, ColumnWidth::fill(1.0))]; let mut view = List::::new(tl!("Export for Screens")) + .surface(SurfaceKind::Sunken) + .pad(Pad::Control) .header(false) .space(SpaceAction::ToggleCell) .columns(columns) .rename(rename) .enabled(enabled) - .max_rows(LIST_ROWS); + .min_rows(LIST_ROWS) + .max_rows(LIST_ROWS) + .selection(Bind::bound(&mut selection)); if rename { view = view.rename_column(NAME); } @@ -763,7 +775,15 @@ impl Shelf<'_> { } } } else { - let mut grid = TileGrid::::new(tl!("Export for Screens")).checks(true).rename(rename).enabled(enabled).max_rows(GRID_ROWS); + let mut grid = TileGrid::::new(tl!("Export for Screens")) + .surface(SurfaceKind::Sunken) + .pad(Pad::Control) + .checks(true) + .rename(rename) + .enabled(enabled) + .min_rows(GRID_ITEMS) + .max_rows(GRID_ITEMS) + .selection(Bind::bound(&mut selection)); if let Some(key) = reveal { grid = grid.reveal(key); } @@ -778,6 +798,8 @@ impl Shelf<'_> { } } } + // A click picks the item it lands on as the lead; the checks alone say which items are selected. + (lead.lead, lead.anchor) = (selection.lead, selection.anchor); picks } } diff --git a/crates/ui-egui/src/dialogs/tests_screens.rs b/crates/ui-egui/src/dialogs/tests_screens.rs index b4ae88d15a..8e6c139a68 100644 --- a/crates/ui-egui/src/dialogs/tests_screens.rs +++ b/crates/ui-egui/src/dialogs/tests_screens.rs @@ -1670,3 +1670,67 @@ fn the_format_rows_fit_the_right_column_at_the_default_and_least_window_sizes() } } } + +/// The items pane, in the grid and in the list, with one artboard and with many: the artboards sit in a sunken frame +/// at least one and a half tiles or five rows tall, the view buttons and the prefix sit under the frame, and the checked +/// artboards are the selected ones. +#[test] +fn the_artboards_sit_in_a_framed_view_as_tall_as_the_pane_and_the_checked_ones_are_selected() { + for (boards, view) in [(1, "grid"), (1, "list"), (12, "grid"), (12, "list")] { + let (mut app, _) = app(boards, false); + let mut w = Window::default(); + w.run(&mut app, vec![]); + open(&mut app); + set(&mut app, "view", json!(view)); + let shown = |w: &mut Window, app: &mut VectorcraftApp| { + w.run(app, vec![]); + let out = w.run(app, vec![]); + let nodes = out.platform_output.accesskit_update.map(|u| u.nodes).unwrap_or_default(); + (out.shapes, nodes) + }; + let rect = |n: &egui::accesskit::Node| { + n.bounds().map(|b| egui::Rect::from_min_max(egui::pos2(b.x0 as f32, b.y0 as f32), egui::pos2(b.x1 as f32, b.y1 as f32))) + }; + let (shapes, nodes) = shown(&mut w, &mut app); + let find = |label: &str, role: Role| { + nodes + .iter() + .find(|(_, n)| n.label() == Some(label) && n.role() == role) + .and_then(|(_, n)| rect(n)) + .unwrap_or_else(|| panic!("{view}: no {role:?} {label:?}")) + }; + let pane = nodes + .iter() + .find(|(_, n)| n.label() == Some("Export for Screens") && matches!(n.role(), Role::ListBox | Role::List)) + .and_then(|(_, n)| rect(n)) + .unwrap_or_else(|| panic!("{boards} {view}: no items view")); + let clear = find("Clear Selection", Role::Button); + let tile = find("1 Artboard 1", Role::ListItem); + // The frame: a filled or outlined rectangle that holds the items view. + fn rects(shape: &egui::Shape, out: &mut Vec) { + match shape { + egui::Shape::Rect(r) => out.push(r.clone()), + egui::Shape::Vec(v) => v.iter().for_each(|s| rects(s, out)), + _ => {} + } + } + let mut painted = Vec::new(); + shapes.iter().for_each(|c| rects(&c.shape, &mut painted)); + let near: Vec<_> = painted.iter().filter(|r| r.rect.expand(4.0).contains_rect(pane) && pane.expand(4.0).contains_rect(r.rect)).collect(); + let framed = near.iter().any(|r| r.stroke.width > 0.0 || r.fill.a() > 0); + assert!(framed, "{boards} {view}: the items view at {pane:?} has a frame: {near:?}"); + assert!(clear.top() >= pane.bottom(), "{boards} {view}: Clear Selection {clear:?} is under the items {pane:?}"); + // One and a half tiles tall in the grid, five rows in the list, whatever the count of artboards. + let least = if view == "grid" { 1.5 } else { 5.0 } * tile.height(); + assert!(pane.height() >= least, "{boards} {view}: the items view {pane:?} is at least {least} tall (an item is {tile:?})"); + let selected = |nodes: &[(egui::accesskit::NodeId, egui::accesskit::Node)]| { + nodes.iter().find(|(_, n)| n.label() == Some("1 Artboard 1") && n.role() == Role::ListItem).and_then(|(_, n)| n.is_selected()) + }; + assert_eq!(selected(&nodes), Some(true), "{boards} {view}: the checked artboard is selected"); + let mut off = vec![true; boards]; + off[0] = false; + set(&mut app, "boards", json!(off)); + let (_, nodes) = shown(&mut w, &mut app); + assert_ne!(selected(&nodes), Some(true), "{boards} {view}: an artboard that is not checked is not selected"); + } +}