From 0d14e431d71289db7472f9bc4ab0fb2240300fd8 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Wed, 18 Nov 2026 08:07:07 -0500 Subject: [PATCH] pdf-workflows-w2: net change of 3 commits - pdf-workflows-w2: finished by an agent - pdf-workflows-w2: finished by an agent - pdf-workflows-w2: review fixes (review-1) --- crates/browse/src/ui/bin/icon.rs | 2 +- crates/font-manager/src/glyphs.rs | 6 +- .../src/patterns/presets/browser.rs | 4 +- crates/ui-widgets/src/tile_grid/grid.rs | 207 ++++++++++++++---- .../ui-widgets/src/tile_grid/grid/stories.rs | 127 +++++++++-- crates/ui-widgets/src/tile_grid/layout.rs | 38 ++++ crates/ui-widgets/src/tile_grid/stories.rs | 68 +++++- crates/ui-widgets/src/tile_grid/tile.rs | 162 ++++++++++---- crates/ui-widgets/tests/it/tile_grid/grid.rs | 174 ++++++++++++++- crates/ui-widgets/tests/it/tile_grid/keys.rs | 60 +++-- migration/api-map/tile-grids.toml | 4 +- 11 files changed, 710 insertions(+), 142 deletions(-) diff --git a/crates/browse/src/ui/bin/icon.rs b/crates/browse/src/ui/bin/icon.rs index eb6273ebc..2a27df3b0 100644 --- a/crates/browse/src/ui/bin/icon.rs +++ b/crates/browse/src/ui/bin/icon.rs @@ -172,7 +172,7 @@ where .caption(CaptionPlace::Below) .detail_line() .aspect(ASPECT) - .zoom(GridZoom::Fixed(f64::from(state.settings.zoom))) // P3(pdf-workflows-w2): WF-W12 + .zoom(GridZoom::Fixed(state.settings.zoom)) .rename(true) .deletable(true) .rows_stamp(stamp_of(state.shown.as_ref(), &state.search, state.settings.icon_sort.as_ref())) diff --git a/crates/font-manager/src/glyphs.rs b/crates/font-manager/src/glyphs.rs index 730ce0d1f..d55fd463b 100644 --- a/crates/font-manager/src/glyphs.rs +++ b/crates/font-manager/src/glyphs.rs @@ -172,7 +172,7 @@ const RECENT_LIMIT: usize = 25; /// The cell size of the grid and its zoom: factors of the medium thumbnail. pub const ZOOM: TileZoom = TileZoom::bounded(1.0, 2.625, 0.125, 1.25); /// The cells of the recents strip, as a factor of the medium thumbnail. -const RECENT_ZOOM: f32 = 0.75; +const RECENT_ZOOM: f64 = 0.75; /// The room round a glyph in its cell, as a fraction of the cell. const GLYPH_INSET_RATIO: f32 = 0.1; @@ -382,7 +382,7 @@ impl<'a> GlyphsPanel<'a> { let mut activated: Option = None; let strip = TileGrid::::new(words.recent.clone()) .thumb_size(ThumbSize::Medium) - .zoom(GridZoom::Fixed(f64::from(RECENT_ZOOM))) // P3(pdf-workflows-w2): WF-W12 + .zoom(GridZoom::Fixed(RECENT_ZOOM)) .caption(CaptionPlace::None) .select(SelectMode::Single) .activate(ActivateOn::Click) @@ -409,7 +409,7 @@ impl<'a> GlyphsPanel<'a> { let mut marked = cx.memory::().clone(); let grid = TileGrid::::new(words.grid.clone()) .thumb_size(ThumbSize::Medium) - .zoom(GridZoom::Fixed(f64::from(size as f32))) // P3(pdf-workflows-w2): WF-W12 + .zoom(GridZoom::Fixed(size)) .caption(CaptionPlace::None) .select(SelectMode::Single) .selection(Bind::bound(&mut marked.0)) diff --git a/crates/ui-patterns/src/patterns/presets/browser.rs b/crates/ui-patterns/src/patterns/presets/browser.rs index 421f10365..4955f79bc 100644 --- a/crates/ui-patterns/src/patterns/presets/browser.rs +++ b/crates/ui-patterns/src/patterns/presets/browser.rs @@ -698,14 +698,14 @@ impl PresetBrowser<'_, K> { let grid = match tile_size { PresetTiles::Thumbnails => { let captions = if has_captions(rows) { CaptionPlace::Below } else { CaptionPlace::None }; - grid.caption(captions).thumb_size(ThumbSize::Large).zoom(GridZoom::Fixed(zoom)) // P3(pdf-workflows-w2): L-64 + grid.caption(captions).thumb_size(ThumbSize::Large).zoom(GridZoom::Fixed(zoom)) } // The zoom is a factor on the picture's width: a wide chip is the small thumbnail high. PresetTiles::Chips => { grid.caption(CaptionPlace::None) .thumb_size(ThumbSize::Small) .zoom(GridZoom::Fixed(f64::from(aspect.max(1.0)))) - .row_height(RowHeight::Text) // P3(pdf-workflows-w2): L-64 + .row_height(RowHeight::Text) } }; let mut grid = grid diff --git a/crates/ui-widgets/src/tile_grid/grid.rs b/crates/ui-widgets/src/tile_grid/grid.rs index d1b415823..ec5f840db 100644 --- a/crates/ui-widgets/src/tile_grid/grid.rs +++ b/crates/ui-widgets/src/tile_grid/grid.rs @@ -2,8 +2,8 @@ //! does the work: virtualisation, lead and selection rules, arrow, Home, End and page keys over the layout, type-ahead, //! drag with drop marks, OS file drops, the rename lifecycle and the context-menu request. The grid adds the layout, //! the pinned group headers and the tail rows after the tiles, which are rows of the grid's outline (section rows of -//! the item step that hold the lead), and the rating keys. It owns what its cards have in common: where the -//! caption goes, whether a detail line is reserved, and the zoom. +//! the item step that hold the lead), the insert gaps between tiles and the rating keys. It owns what its cards have +//! in common: where the caption goes, whether a detail line is reserved, where the hover actions sit, and the zoom. #[cfg(feature = "testing")] mod stories; @@ -18,23 +18,27 @@ use crate::contract::{ Role, RowHeight, RowState, SelectMode, Sizing, SpaceAction, SweepApply, SweepStep, ToggleColumn, section_part, }; use crate::controls::disclosure::Disclosure; -use crate::list::{DropTest, ListRow, ListRowStyle, RowTest, ThumbSize}; -use crate::primitives::{IconSpec, PaintShape, RectSide}; +use crate::list::{DropTest, ListRow, ListRowStyle, RowTest, ThumbSize, ToggleState}; +use crate::primitives::{IconSpec, PaintShape, RectSide, StrokeWidth}; use crate::runtime::access::Name; use crate::runtime::commands::FireSource; use crate::runtime::env::Label; use crate::style::{ComponentStyle, RuleKind, StyleColor, StyleCx}; use craft_behavior::{ - ColumnKey, ColumnWidth, HitLevel, HitPriority, Intent, ItemSource, Metrics, Mixed, PartKey, PointerButton, PressPhase, Selection, Sense, + ColumnKey, ColumnWidth, EditEvent, HitLevel, HitPriority, Intent, ItemLayout as _, ItemSource, Metrics, Mixed, NavShape, PartKey, PointerButton, + PressPhase, Roving, Selection, Sense, }; use craft_keymap::{Chord, Key, Mods}; use egui::{CornerRadius, Pos2, Rect, Response, Ui, Vec2, pos2, vec2}; use std::cell::RefCell; use std::hash::Hash; +use std::sync::Arc; /// The heading level of a group header: the grid's groups are its top-level sections. const GROUP_LEVEL: usize = 1; const TOGGLE: PartKey = PartKey::new("group_toggle"); +/// An insert gap, indexed by the display position it inserts before. +const GAP: PartKey = PartKey::new("insert_gap"); /// The keyboard path of the header parts: the header is a row of the outline, and the lead on it takes these keys. const HEADER_KEYS: &str = "Up and Down move to a group header; Enter picks it and Left and Right close and open it"; /// The keyboard path of a tail row's part: the row is a row of the outline, and the lead on it takes Enter. @@ -58,10 +62,12 @@ pub enum RatingKeys { /// The size of a grid's tiles. #[non_exhaustive] pub enum GridZoom<'a> { - /// A picture side factor the host holds. + /// A picture side factor the host holds; the grid takes no zoom keys or wheel. Fixed(f64), - /// A factor the grid steps itself: Cmd/Ctrl `=`, `-` and `0` and Ctrl/Cmd with the wheel or a pinch, through - /// `TileZoom::step`, keeping the tile under the pointer in place. + /// A factor the grid steps itself: Cmd/Ctrl `=` and `+`, `-` and `0` through `TileZoom::step`, and Ctrl/Cmd with + /// the wheel or a pinch by the gesture's factor, inside the zoom's range, keeping the tile under the pointer in + /// place. Cmd/Ctrl+0 is a rating key under `RatingKeys::CommandDigits`, so it clears the rating there instead of + /// resetting the size. A binding that holds no single value reads as the zoom's default. Bound(Bind<'a, f64>, TileZoom), } @@ -100,9 +106,6 @@ pub enum GridEvent { /// The state asked for. open: bool, }, - /// Cmd/Ctrl with `=` or `+`, `-` or `0` on a grid that `zooms`: a step of the tile size. Cmd/Ctrl+0 is a rating key - /// under `RatingKeys::CommandDigits`, so it clears the rating there instead of resetting the size. - Zoom(ZoomStep), /// The insert gap before display position `at` was activated ([`TileGrid::insert_gaps`]). #[non_exhaustive] Insert { @@ -153,6 +156,10 @@ pub struct TileGridStyle { pinned: StyleColor, /// The look of a group header: a heading row, which places the disclosure the grid declares. header: ListRowStyle, + /// The line down the middle of an insert gap under the pointer. + insert: StyleColor, + /// The width of an insert gap, centred on the edge of the tile it precedes. + insert_width: f32, } /// The sizes the grid lays its tiles out with. @@ -208,7 +215,8 @@ const WHEEL_SHARE: f32 = 1.0 / 3.0; /// menu. A double click on the background reports `CollectionEvent::EmptyActivated` (an import, in FilmCraft). One wheel /// notch scrolls a third of the grid's view. /// -/// The picture side is `zoom` times the thumbnail side (the card thumbnail unless `thumb_size` names one): the factor the app's zoom control holds. A card is the +/// The picture side is `zoom` times the thumbnail side (the card thumbnail unless `thumb_size` names one): a factor the +/// app holds, or one the grid steps itself through a binding (`GridZoom`). A card is the /// picture plus what the tile adds around it, whatever the layout. Pictures are `aspect` wide over high; with /// `justified` the tiles keep their own aspects (the source's `ItemSource::size_hint` as `SizeHint::Aspect`) and fill /// rows. `groups` put headers over runs of tiles; a header stays pinned at the top while its group scrolls. The grid @@ -240,10 +248,16 @@ pub struct TileGrid<'a, K: Clone + Eq + Hash + Send + Sync + 'static> { aspect: f32, /// The picture side as a multiple of the thumbnail side the grid sizes from; 1 is that side. zoom: GridZoom<'a>, + /// The zoom's factor as this pass was built with it: the layout of the pass reads it, and a step the pass takes + /// shows in the next pass's layout, so the anchor is named against the layout the step changes from. + factor: f64, + /// Where the pointer was when `update` took a zoom chord in this pass: the point a key zoom keeps in place. + chord_at: Option, /// Where every tile's hover actions sit. - #[allow(dead_code)] // P3(pdf-workflows-w2): CV-C25 #[prop] action_place: TileActionPlace, + /// The names of the insert gaps, by the display position each inserts before; `None` shows no gaps. + insert_gaps: Option<&'a dyn Fn(usize) -> Label>, /// The thumbnail size the zoom is a factor of; `None` is the card thumbnail. #[prop] thumb_size: Option, @@ -276,10 +290,6 @@ pub struct TileGrid<'a, K: Clone + Eq + Hash + Send + Sync + 'static> { tail: &'a [TailRow], /// Which keys rate the selected tiles. rating_keys: RatingKeys, - /// The grid reports zoom steps: Cmd/Ctrl with `=`, `-` and `0` as `GridEvent::Zoom`, and Ctrl/Cmd with the wheel or a - /// pinch as `CollectionEvent::Zoom`. - #[prop(flag)] - zooms: bool, /// Tiles show a check box and Space toggles the lead tile's check. checks: bool, /// Which tiles may be renamed; a rename request on another tile does nothing. @@ -300,6 +310,8 @@ pub struct TileGrid<'a, K: Clone + Eq + Hash + Send + Sync + 'static> { placed: Vec, /// The tail rows this pass shows, in the grid's layer space: the row's index and its rect. placed_tail: Vec<(usize, Rect)>, + /// The insert gaps this pass shows, in the grid's layer space: the display position and the gap's rect. + placed_gaps: Vec<(usize, Rect)>, /// The tail rows clicked this pass, in order. tail_clicked: Vec, events: Vec>, @@ -318,7 +330,7 @@ struct Placed { impl<'a, K: Clone + Eq + Hash + Send + Sync + 'static> TileGrid<'a, K> { /// A grid named `label`, with multiple selection and equal square cards of the card thumbnail. Space picks the lead and /// no key rates or zooms; Bridge's keys are `rating_keys(RatingKeys::CommandDigits)`, `space(SpaceAction::Preview)` - /// and `zooms()`. + /// and a `GridZoom::Bound` zoom. pub fn new(label: impl Into