From 009f161cbb959a6edacfbd48355a2cf9d4622d32 Mon Sep 17 00:00:00 2001 From: aiongg Date: Thu, 12 Nov 2026 00:22:49 +0000 Subject: [PATCH] Row slots: a hosted trailing component takes the width it measures (trailing_field, optional_field drops first, trailing_space keeps an absent field's room), lead_text puts a short text in the leading slot whose double click a row reports as LeadClicked, and a trailing part's click carries its count and whether its row held the lead when the press began (RowPressed::Part) PageList shows each row's number and reports Fit on a double click on it; its options open on the active row or on a double click. PaintList hosts the paint chip, hex and opacity fields and the binding's badge, with a solid row named by its hex. RenderQueueList's row actions are small labelled buttons and an encoding row shows its progress bar. LayersPanel::trailing adds the host's component after a row's indicators. A row's progress bar is named after the row. --- crates/color/src/ui/paint_chip/paint_list.rs | 96 +++++++++++++---- crates/color/tests/it/main.rs | 1 + crates/color/tests/it/paint_list.rs | 37 +++++++ crates/layers/src/ui/panel/context.rs | 29 ++++- crates/layers/src/ui/panel/mod.rs | 34 +++++- crates/layers/src/ui/panel/row.rs | 3 + crates/layers/src/ui/panel/stories.rs | 14 ++- crates/pages/src/ui/list.rs | 22 +++- crates/timeline/src/ui/render_queue.rs | 64 ++++++----- .../src/contract/collection/props.rs | 8 +- crates/ui-contract/src/contract/items/drag.rs | 3 + .../ui-contract/src/contract/items/press.rs | 16 +++ crates/ui-widgets/src/list/row.rs | 47 ++++++-- crates/ui-widgets/src/list/row/output.rs | 13 +++ crates/ui-widgets/src/list/row/paint.rs | 7 +- crates/ui-widgets/src/list/row/placement.rs | 101 +++++++++++++----- crates/ui-widgets/src/list/row/show.rs | 69 +++++++++--- crates/ui-widgets/src/list/row/trailing.rs | 58 ++++++++-- crates/ui-widgets/tests/it/list.rs | 81 ++++++++++++++ 19 files changed, 576 insertions(+), 127 deletions(-) create mode 100644 crates/color/tests/it/paint_list.rs diff --git a/crates/color/src/ui/paint_chip/paint_list.rs b/crates/color/src/ui/paint_chip/paint_list.rs index ecea59f1d..522abe2db 100644 --- a/crates/color/src/ui/paint_chip/paint_list.rs +++ b/crates/color/src/ui/paint_chip/paint_list.rs @@ -2,18 +2,22 @@ use craft_behavior::{Axis, EditEvent, IconId, Selection}; use craft_behavior::{DisplayOrder, ItemSource, Mixed, SelectionChange}; +use craft_theme::Rgba; use craft_theme::Srgba; use craft_ui::buttons::Button; use craft_ui::contract::ShowContainer as _; use craft_ui::contract::{Bind, Outcome, Show as _, ShowCollection as _}; use craft_ui::contract::{CollectionEvent, NoValue, Rename}; +use craft_ui::display::Badge; use craft_ui::layout_components::Stack; use craft_ui::list::{List, ListRow, RowEvent, ThumbAspect, ThumbSize, TrailingFace, TrailingPart}; use craft_ui::primitives::{ContentPainterCx, IconSpec, PaintShape}; use craft_ui::runtime::env::Label; +use craft_ui::text::{HexField, NumberField}; use egui::{Color32, Rect, Response, Ui}; +use std::cell::RefCell; -use super::{Paint, PaintWords, paint_image, ramp_stops}; +use super::{Paint, PaintChip, PaintWords, paint_image, ramp_stops}; /// How a paint is bound (FigCraft's colour style or variable). #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] @@ -241,8 +245,9 @@ const ROW_CHIP: (u16, u16) = (3, 2); /// /// With [`options`](Self::options) a row also offers the binding's name with Bind and Detach ([`rows`](Self::rows)), /// "Select layers with this color" and Remove after the name, and Add under the rows. Each reports a -/// [`PaintListEvent`]. The per-row chip edit, hex field and opacity field wait for a row slot that holds field -/// controls. +/// [`PaintListEvent`]. With `edit` a live [`PaintChip`] takes the thumbnail's place among the trailing items, and +/// `hex` and `opacity` add a hex field and a percent field to each solid row; the binding shows as a badge by the +/// name that drops out first in a narrow list. #[derive(craft_ui::contract::Pattern, craft_ui::contract::Props)] pub struct PaintList<'a> { label: Label, @@ -275,42 +280,87 @@ impl<'a> PaintList<'a> { let (paints, rows, options, label) = (self.paints, self.rows, self.options, self.label.clone()); let mut output = None; let mut add = false; + let acted = RefCell::new(Vec::new()); let shown = Stack::new().show(ui, |ui, cx| { let held = match selected_bind.reborrow().read(cx) { Some(Mixed::Same(Some(row))) if row < paints.len() => Selection::single(row), _ => Selection::default(), }; let list = List::::new(label.clone()).selection(Bind::given(held)).can_rename(|_| true); + let first_solid = paints.iter().find_map(|(_, paint)| if let Paint::Solid(color) = paint { Some(*color) } else { None }); + let fallback = self.fallback.or(first_solid).unwrap_or(Self::DEFAULT_SOLID); + let acted = &acted; output = Some(list.show_items(ui, &Paints(paints), &mut |row, _| { - let (name, paint) = &paints[*row]; - let mut item = - ListRow::new(name.clone()).thumb_aspect(ThumbSize::Small, ThumbAspect::new(ROW_CHIP.0, ROW_CHIP.1), move |painter, rect| { + let row = *row; + let (name, paint) = &paints[row]; + let solid = match paint { + Paint::Solid(color) => Some(*color), + _ => None, + }; + let mut item = ListRow::new(name.clone()); + if let Some(color) = solid { + item = item.accessible_name(format!("{name}, {}", color.to_rgba().to_hex())); + } + if !options.edit { + item = item.thumb_aspect(ThumbSize::Small, ThumbAspect::new(ROW_CHIP.0, ROW_CHIP.1), move |painter, rect| { paint_thumb(painter, rect, paint); }); - if let Some(link) = rows.get(*row).and_then(|data| data.link.as_ref()) { - item = item.trailing(link.name.clone()); } + // The first item added is the outermost: Remove closes the row, the binding's badge sits by the name. + if options.remove { + let label = Label::from(words.remove.fill(&[("name", name.as_str())])); + item = item.trailing_part(REMOVE, TrailingFace::Icon(IconSpec::svg(IconId::new("minus"))), label); + } + if options.select_users { + let label = Label::from(words.select_users.fill(&[("name", name.as_str())])); + item = item.trailing_part(SELECT_USERS, TrailingFace::Icon(IconSpec::svg(IconId::new("layers"))), label); + } + let link = rows.get(row).and_then(|data| data.link.as_ref()); if options.bind { - let (name, icon) = match rows.get(*row).and_then(|data| data.link.as_ref()) { + let (label, icon) = match link { Some(PaintLink { kind: PaintLinkKind::Style, .. }) => (words.detach_style.clone(), "unlink"), Some(PaintLink { kind: PaintLinkKind::Variable, .. }) => (words.detach_variable.clone(), "unlink"), None => (words.styles.clone(), "palette"), }; - item = item.trailing_part(BIND, TrailingFace::Icon(IconSpec::svg(IconId::new(icon))), name); + item = item.trailing_part(BIND, TrailingFace::Icon(IconSpec::svg(IconId::new(icon))), label); } - if options.select_users { - item = item.trailing_part( - SELECT_USERS, - TrailingFace::Icon(IconSpec::svg(IconId::new("layers"))), - Label::from(words.select_users.fill(&[("name", name.as_str())])), - ); + // A row without a solid colour keeps the fields' room empty, so the buttons after them line up. + if options.opacity { + let percent = solid.map_or(100.0, |color| f64::from(color.a) * 100.0); + let field = NumberField::new(words.opacity.clone(), Bind::given(Some(percent))).range(0.0..=100.0).unit("%"); + item = match solid { + Some(_) => item.trailing_field(field, move |shown| { + for event in shown.edit.events.iter() { + let event = event.clone().map(|percent| (percent.unwrap_or(100.0) / 100.0) as f32); + acted.borrow_mut().push(PaintListEvent::Opacity { row, event }); + } + }), + None => item.trailing_space(field), + }; } - if options.remove { - item = item.trailing_part( - REMOVE, - TrailingFace::Icon(IconSpec::svg(IconId::new("minus"))), - Label::from(words.remove.fill(&[("name", name.as_str())])), - ); + if options.hex { + // The field shows no alpha digits: a typed colour keeps the row's alpha. + let opaque = solid.map_or(Rgba::rgb(0, 0, 0), |color| Srgba { a: 1.0, ..color }.to_rgba()); + let field = HexField::hex(words.hex.clone(), Bind::given(opaque)); + item = match solid { + Some(color) => item.trailing_field(field, move |shown| { + if let Some(typed) = shown.events.landed() { + acted.borrow_mut().push(PaintListEvent::Hex { row, color: Srgba { a: color.a, ..Srgba::from(*typed) } }); + } + }), + None => item.trailing_space(field), + }; + } + if options.edit { + let chip = PaintChip::new(words.edit.clone(), Bind::given(paint.clone()), solid.unwrap_or(fallback)); + item = item.trailing_field(chip, move |shown| { + for event in shown.edit.events.iter() { + acted.borrow_mut().push(PaintListEvent::Edit { row, event: event.clone() }); + } + }); + } + if let Some(link) = link { + item = item.optional_field(Badge::new(link.name.clone()), |_| {}); } item })); @@ -321,7 +371,7 @@ impl<'a> PaintList<'a> { // A parent's measuring run reuses what it measured and does not run the body. let Some(list) = output else { return PaintListOutput { response: shown.output, selected: None, events: Vec::new() } }; let mut selected = None; - let mut events = Vec::new(); + let mut events = acted.into_inner(); for event in list.events { match event { CollectionEvent::Selection(SelectionChange::Set(keys)) => selected = keys.last().copied().or(selected), diff --git a/crates/color/tests/it/main.rs b/crates/color/tests/it/main.rs index 1728248f6..4bdaa0f3d 100644 --- a/crates/color/tests/it/main.rs +++ b/crates/color/tests/it/main.rs @@ -1,6 +1,7 @@ //! The screen tests of craft-color, folded into the lib's test target. mod color_parts; +mod paint_list; mod panels; mod picker; mod sampling; diff --git a/crates/color/tests/it/paint_list.rs b/crates/color/tests/it/paint_list.rs new file mode 100644 index 000000000..a1b973d31 --- /dev/null +++ b/crates/color/tests/it/paint_list.rs @@ -0,0 +1,37 @@ +//! `PaintList` rows with their fields: a typed hex keeps the paint's alpha. + +use std::cell::RefCell; +use std::rc::Rc; + +use craft_color::ui::{Paint, PaintList, PaintListEvent, PaintListOptions}; +use craft_theme::Srgba; +use craft_ui::contract::Bind; +use craft_ui::testing::{Fixture, trial}; +use egui::{Key, Modifiers, vec2}; + +/// A hex typed into a translucent row's field reports the typed colour with the row's alpha. +#[trial] +fn a_typed_hex_keeps_the_rows_alpha() { + let seen = Rc::new(RefCell::new(Vec::new())); + let held = seen.clone(); + let mut fixture = Fixture::new(move |ui| { + let paints = [(String::from("Shadow"), Paint::Solid(Srgba::new(0.2, 0.4, 0.6, 0.5))), (String::from("Sunrise"), Paint::None)]; + let out = PaintList::new("Paints", &paints, Bind::given(None)).options(PaintListOptions::default().hex(true)).show(ui); + held.borrow_mut().extend(out.events); + }); + fixture.room(vec2(400.0, 200.0)); + fixture.settle(); + let field = fixture.by_label("Color").expect("the solid row has a hex field"); + fixture.click(&field); + fixture.key(Key::A, Modifiers::COMMAND); + fixture.type_text("ff0000"); + fixture.key(Key::Enter, Modifiers::NONE); + fixture.settle(); + let hex = seen.borrow().iter().find_map(|event| match event { + PaintListEvent::Hex { row: 0, color } => Some(*color), + _ => None, + }); + let hex = hex.unwrap_or_else(|| panic!("the field reports the typed colour: {:?}", seen.borrow())); + assert!(hex.r > 0.99 && hex.g < 0.01 && hex.b < 0.01, "the typed colour: {hex:?}"); + assert!((hex.a - 0.5).abs() < 0.01, "the row's alpha is kept: {hex:?}"); +} diff --git a/crates/layers/src/ui/panel/context.rs b/crates/layers/src/ui/panel/context.rs index 4f93f3086..688efdef0 100644 --- a/crates/layers/src/ui/panel/context.rs +++ b/crates/layers/src/ui/panel/context.rs @@ -1,13 +1,16 @@ //! What the panel's parts share in one pass: the tree, the settings, the thumbnails and the words. -use craft_ui::list::ListWords; +use craft_ui::contract::Show; +use craft_ui::list::{ListRow, ListWords}; use craft_ui::primitives::textures::{ThumbSource, Thumbnails}; use egui::Id; use super::LayersPanelWords; use crate::ui::options::LayersOptions; use crate::ui::thumbs::LayerThumb; -use crate::ui::tree::{LayerSelection, LayerTree}; +use crate::ui::tree::{LayerInfo, LayerSelection, LayerTree}; +use std::cell::RefCell; +use std::marker::PhantomData; /// The thumbnail cache and the app's source of the rows' pictures. pub(super) struct ThumbHost<'a, Id: Clone + Eq + std::hash::Hash + Send + Sync + 'static> { @@ -23,6 +26,26 @@ impl Clone for ThumbHo impl Copy for ThumbHost<'_, Id> {} +/// The host's component at each layer row's trailing end (`LayersPanel::trailing`), with its output handed back. +pub(super) trait TrailingCell { + /// Adds the cell of the layer `id` to its row. + fn add<'r>(&'r self, row: ListRow<'r>, id: &Id, info: &LayerInfo) -> ListRow<'r>; +} + +/// A [`TrailingCell`] of the host's `build` and `output`. +pub(super) struct HostCell { + pub(super) build: B, + pub(super) output: RefCell, + pub(super) component: PhantomData C>, +} + +impl C, O: FnMut(&Id, C::Output)> TrailingCell for HostCell { + fn add<'r>(&'r self, row: ListRow<'r>, id: &Id, info: &LayerInfo) -> ListRow<'r> { + let layer = id.clone(); + row.trailing_field((self.build)(id, info), move |shown| (self.output.borrow_mut())(&layer, shown)) + } +} + /// The pass's shared state, lent to the row mapping, the drag rules, the footer and the menus. pub(super) struct PanelContext<'a, T: LayerTree> { /// The rows' list, which drags name. @@ -36,4 +59,6 @@ pub(super) struct PanelContext<'a, T: LayerTree> { pub(super) lock_column: bool, /// The app's key that flips the selected layers' eyes. pub(super) visibility_key: Option, + /// The host's component at each layer row's trailing end. + pub(super) trailing: Option<&'a (dyn TrailingCell + 'a)>, } diff --git a/crates/layers/src/ui/panel/mod.rs b/crates/layers/src/ui/panel/mod.rs index 298958158..5b981a44e 100644 --- a/crates/layers/src/ui/panel/mod.rs +++ b/crates/layers/src/ui/panel/mod.rs @@ -22,7 +22,7 @@ pub use menu::{LayersMenuAction, LayersPanelCommands, LayersPanelKeys, panel_row use std::cell::RefCell; -use craft_ui::contract::{Bind, CommandSet as _, Commands as _, NoValue, Outcome, ShowContainer as _}; +use craft_ui::contract::{Bind, CommandSet as _, Commands as _, NoValue, Outcome, Show, ShowContainer as _}; use craft_ui::layout_components::Stack; use craft_ui::list::ListWords; use craft_ui::primitives::textures::{ThumbSource, Thumbnails}; @@ -31,15 +31,16 @@ use craft_ui::runtime::memory::Remember as _; use egui::{Response, Ui}; use body::{LayerRows, ToggleSweeps, reveal_plan, show_body, start_rename}; -use context::{PanelContext, ThumbHost}; +use context::{HostCell, PanelContext, ThumbHost, TrailingCell}; use footer::show_footer; use menu::{OpenMenu, RowMenu, show_row_menus}; +use std::marker::PhantomData; use super::filter::{LayerFilter, LayerFilterBar}; use super::options::LayersSettings; use super::rows::BlendRows; use super::thumbs::LayerThumb; -use super::tree::{LayerRowKey, LayerTree}; +use super::tree::{LayerInfo, LayerRowKey, LayerTree}; craft_ui::words! { /// The words of the Layers panel's rows, footer and menus. Patterns with `{row}`, `{layer}` and @@ -160,6 +161,7 @@ pub struct LayersPanel<'a, T: LayerTree> { blend_rows: bool, filter_bar: bool, row_menu: Option>>, + trailing: Option + 'a>>, reveal: Option, rename: Option, } @@ -199,6 +201,7 @@ impl<'a, T: LayerTree> LayersPanel<'a, T> { blend_rows: true, filter_bar: true, row_menu: None, + trailing: None, reveal: None, rename: None, } @@ -260,6 +263,14 @@ impl<'a, T: LayerTree> LayersPanel<'a, T> { self } + /// The host's component at each layer row's trailing end, after the indicators and never dropped for the name + /// (Illustrator's target circle, a selection square): `build` makes the layer's component and `output` gets what + /// it reports, with the layer, in the pass it is shown. + pub fn trailing(mut self, build: impl Fn(&T::Id, &LayerInfo) -> C + 'a, output: impl FnMut(&T::Id, C::Output) + 'a) -> Self { + self.trailing = Some(Box::new(HostCell { build, output: RefCell::new(output), component: PhantomData })); + self + } + /// Reveals `layer` this pass: its closed ancestors open ([`LayersEvent::Open`]) and its row /// scrolls into view when hidden. The active layer is revealed by itself when it changes. pub fn reveal(mut self, layer: T::Id) -> Self { @@ -277,8 +288,20 @@ impl<'a, T: LayerTree> LayersPanel<'a, T> { /// Draws the panel over the available rect: the filter bar and [`BlendRows`] in the header, the /// rows, the footer. Events are reported in that order. pub fn show(self, ui: &mut Ui) -> LayersOutput { - let LayersPanel { tree, settings, thumbnails, mut filter, lock_column, visibility_key, blend_rows, filter_bar, row_menu, reveal, rename } = - self; + let LayersPanel { + tree, + settings, + thumbnails, + mut filter, + lock_column, + visibility_key, + blend_rows, + filter_bar, + row_menu, + trailing, + reveal, + rename, + } = self; let env = Env::of(ui); let words = env.words::(); let list_words = env.words::(); @@ -295,6 +318,7 @@ impl<'a, T: LayerTree> LayersPanel<'a, T> { list_words: &list_words, lock_column, visibility_key, + trailing: trailing.as_deref(), }; let events = RefCell::new(Vec::new()); let current = RefCell::new(LayerFilter::default()); diff --git a/crates/layers/src/ui/panel/row.rs b/crates/layers/src/ui/panel/row.rs index b5f713f88..13c0fbaee 100644 --- a/crates/layers/src/ui/panel/row.rs +++ b/crates/layers/src/ui/panel/row.rs @@ -235,6 +235,9 @@ fn layer_row<'r, T: LayerTree>(cx: &'r PanelContext<'r, T>, id: &T::Id) -> ListR if let Some(warning) = info.warning.clone() { row = row.trailing_icon(IconSpec::svg(IconId::new("warning")), warning); } + if let Some(cell) = cx.trailing { + row = cell.add(row, id, &info); + } row.description(row_description(words, &info, active.then_some(cx.selection.target))) } diff --git a/crates/layers/src/ui/panel/stories.rs b/crates/layers/src/ui/panel/stories.rs index 966c6ef34..9f5f1b4a2 100644 --- a/crates/layers/src/ui/panel/stories.rs +++ b/crates/layers/src/ui/panel/stories.rs @@ -8,7 +8,10 @@ use egui::Ui; use super::{LayersOutput, LayersPanel}; use crate::ui::filter::{FilterBy, LayerFilter}; use crate::ui::mock::FakeLayers; -use crate::ui::tree::{LayerPart, LayerSelection}; +use crate::ui::tree::{LayerInfo, LayerPart, LayerSelection}; +use craft_behavior::IconId; +use craft_ui::display::Icon; +use craft_ui::primitives::IconSpec; /// The sample tree with the masked layer active and its mask targeted. fn selected() -> FakeLayers { @@ -51,6 +54,15 @@ fn layers_panel_filtered(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { with_readout(data, shown) } +/// Illustrator's target circle after each row's indicators: filled while the layer is shown. +#[story(LayersPanel<'static, FakeLayers>, covers = [], drive = Drive::Never)] +fn layers_panel_target_cell(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + let tree = selected(); + let target = |_: &u32, info: &LayerInfo| Icon::new(IconSpec::svg(IconId::new(if info.visible { "target" } else { "circle" }))); + let shown = LayersPanel::new(&tree).trailing(target, |_, _| {}).show(ui); + with_readout(data, shown) +} + #[story(LayersPanel<'static, FakeLayers>, covers = [], drive = Drive::Never)] fn layers_panel_extra_columns(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { let tree = selected(); diff --git a/crates/pages/src/ui/list.rs b/crates/pages/src/ui/list.rs index 0be28731a..d4bc843d2 100644 --- a/crates/pages/src/ui/list.rs +++ b/crates/pages/src/ui/list.rs @@ -101,6 +101,8 @@ pub enum PageListEvent { Go(usize), /// Enter on the lead row, or a double-click on a row. Activate(usize), + /// A double-click on a row's number: fit that page or artboard in the window. + Fit(usize), /// A name typed in place (F2, a double-click on the name, the context menu's Rename): trimmed, never empty. /// With several rows picked the app gives the name to all of them numbered in list order as `{text}-1`, /// `{text}-2` (VectorCraft `artboards.rs:243`). @@ -131,7 +133,8 @@ pub enum PageListEvent { /// Delete (the button, the Delete key, or rows dropped on it): the picked rows that aren't locked, or the /// dropped rows. Delete(Vec), - /// The options icon of a row. + /// The options icon of the active row, or a double-click on another row's (a single click on it makes the row + /// active, as a click on the row does). Options(usize), /// The app's menu is asked for. ContextMenu(ContextMenuRequest), @@ -181,8 +184,9 @@ fn toggle_column(edit: &EditEvent>) -> Option<&ColumnKey> { /// The list, built per pass. /// -/// - Rows are `ListRow`s: the name, an eye and a lock toggle column (sweepable), the options icon as a trailing -/// part. The active row is the list's current item and its lead. +/// - Rows are `ListRow`s: the number, the name, an eye and a lock toggle column (sweepable), the options icon as a +/// trailing part. The active row is the list's current item and its lead. A double click on the number fits the +/// row (`Fit`). /// - Pointer, keys, rename and drag are the table's: click activates and picks; Shift-click extends, /// Cmd/Ctrl-click toggles; one Tab stop, up and down move the active row, F2 renames, Enter activates, Delete and /// Backspace delete, Cmd/Ctrl+] and [ move the picked rows, the Menu key and Shift+F10 open the menu. @@ -229,6 +233,8 @@ impl<'a> PageList<'a> { let events = RefCell::new(Vec::new()); let list_id: RefCell> = RefCell::new(None); let order: Vec = (0..rows.len()).collect(); + let number = |row: usize| env.format().integer(row as u64 + 1); + let widest = number(rows.len().saturating_sub(1)); let source = keyed(&order, |&row| row) .with_text(|&row| Cow::Owned(rows[row].name.clone())) .with_toggled(|&row, column| (*column == VISIBLE && !rows[row].hidden) || (*column == LOCKED && rows[row].locked)); @@ -276,6 +282,7 @@ impl<'a> PageList<'a> { let options = IconSpec::svg(IconId::new("settings")); ListRow::new(rows[row].name.clone()) .cells(icx.cells()) + .lead_text(number(row), widest.clone()) .toggle(ToggleCell::eye(VISIBLE, !rows[row].hidden).name(words.visibility.clone())) .toggle(ToggleCell::lock(LOCKED, rows[row].locked).name(words.locking.clone())) .trailing_part(OPTIONS, TrailingFace::Icon(options), words.options.clone()) @@ -312,7 +319,14 @@ impl<'a> PageList<'a> { events.push(PageListEvent::Delete(rows)); } } - CollectionEvent::Item(row, RowEvent::Trailing { part, .. }) if part == OPTIONS => events.push(PageListEvent::Options(row)), + // The press moved the lead, which reported Go: a click opens the options when the row was + // already active, or as the second click of a double click. + CollectionEvent::Item(row, RowEvent::Trailing { part, clicks, was_lead, .. }) + if part == OPTIONS && (was_lead || clicks >= 2) => + { + events.push(PageListEvent::Options(row)); + } + CollectionEvent::Item(row, RowEvent::LeadClicked { clicks: 2.., .. }) => events.push(PageListEvent::Fit(row)), _ => {} } } diff --git a/crates/timeline/src/ui/render_queue.rs b/crates/timeline/src/ui/render_queue.rs index 7105f8226..38694bad9 100644 --- a/crates/timeline/src/ui/render_queue.rs +++ b/crates/timeline/src/ui/render_queue.rs @@ -7,25 +7,19 @@ use std::borrow::Cow; use std::cell::RefCell; use std::time::Duration; -use craft_behavior::{DisplayOrder, EditEvent, IconId, ItemSource, Selection, SelectionChange}; -use craft_theme::Variant; -use craft_ui::buttons::Button; +use craft_behavior::{DisplayOrder, EditEvent, ItemSource, Selection, SelectionChange}; +use craft_theme::{ControlSize, Variant}; +use craft_ui::buttons::{Button, ButtonOutput}; use craft_ui::contract::{ Bind, BodyCx, CollectionEvent, Held, NoValue, Outcome, Pattern, Props, ReorderMove, ReorderRule, SelectMode, Show as _, ShowCollection as _, ShowContainer as _, clicked, }; use craft_ui::display::{Shade, Text}; use craft_ui::layout_components::{Row, Stack}; -use craft_ui::list::{List, ListRow, RowEvent, TrailingFace, TrailingPart}; -use craft_ui::primitives::IconSpec; +use craft_ui::list::{List, ListRow}; use craft_ui::runtime::env::{Env, Label}; use egui::{Response, Ui}; -/// The pressable part that cancels or retries an item. -const ACTION: TrailingPart = TrailingPart::new(0); -/// The pressable part that removes an item. -const REMOVE: TrailingPart = TrailingPart::new(1); - craft_ui::words! { /// The queue's words, English by default (FilmCraft's). #[non_exhaustive] @@ -191,9 +185,10 @@ pub fn format_eta(env: &Env, time: Duration) -> String { } } -/// The row of `item`: "source \u{2192} file", the preset and status as its detail, the time left of an encoding -/// item, and the row's action buttons. -fn queue_row(env: &Env, words: &RenderQueueWords, item: &RenderQueueItem) -> ListRow<'static> { +/// The row of `item`: "source \u{2192} file", the preset and status as its detail, an encoding item's progress bar +/// under it with its time left at the end, and the row's buttons: Cancel or Retry, then Remove (disabled while +/// encoding), whose clicks go to `events`. +fn queue_row<'r>(env: &Env, words: &RenderQueueWords, item: &RenderQueueItem, events: &'r RefCell>) -> ListRow<'r> { let format = env.format(); let status = match &item.status { RenderStatus::Ready => words.ready.as_str().to_owned(), @@ -205,19 +200,29 @@ fn queue_row(env: &Env, words: &RenderQueueWords, item: &RenderQueueItem) -> Lis RenderStatus::Failed(error) => words.failed.fill(&[("e", error)]), RenderStatus::Cancelled => words.cancelled.as_str().to_owned(), }; - let mut row = ListRow::new(format!("{} \u{2192} {}", item.source, item.file)).detail(format!("{} \u{b7} {status}", item.preset)); - if let RenderStatus::Encoding { remaining: Some(time), .. } = item.status { - row = row.optional(words.time_left.fill(&[("time", &format_eta(env, time))])); - } - if !item.status.is_encoding() { - row = row.trailing_part(REMOVE, TrailingFace::Icon(IconSpec::svg(IconId::new("trash"))), words.remove.clone()); - } - match item.status { - RenderStatus::Ready | RenderStatus::Encoding { .. } => { - row.trailing_part(ACTION, TrailingFace::Icon(IconSpec::svg(IconId::new("close"))), words.cancel.clone()) + let id = item.id; + let button = |text: &Label| Button::new(text.clone()).size(ControlSize::Sm); + let on_click = move |event: RenderQueueEvent| { + move |shown: ButtonOutput| { + if clicked(&shown) { + events.borrow_mut().push(event); + } + } + }; + let mut row = ListRow::new(format!("{} \u{2192} {}", item.source, item.file)) + .detail(format!("{} \u{b7} {status}", item.preset)) + .trailing_field(button(&words.remove).enabled(!item.status.is_encoding()), on_click(RenderQueueEvent::Remove(id))); + row = match item.status { + RenderStatus::Ready | RenderStatus::Encoding { .. } => row.trailing_field(button(&words.cancel), on_click(RenderQueueEvent::Cancel(id))), + _ => row.trailing_field(button(&words.retry), on_click(RenderQueueEvent::Retry(id))), + }; + if let RenderStatus::Encoding { progress, remaining } = item.status { + row = row.progress(progress); + if let Some(time) = remaining { + row = row.optional(words.time_left.fill(&[("time", &format_eta(env, time))])); } - _ => row.trailing_part(ACTION, TrailingFace::Icon(IconSpec::svg(IconId::new("refresh"))), words.retry.clone()), } + row } /// FilmCraft's export queue (Premiere's queue in Export mode): a `List` of the items, each row "source \u{2192} @@ -269,7 +274,7 @@ impl<'a> RenderQueueList<'a> { .selection(Bind::bound(&mut selected)) .show_items(ui, &source, &mut |key, _| { let item = items.iter().find(|item| item.id == *key).expect("the list asks for its own keys"); - queue_row(&env, &words, item) + queue_row(&env, &words, item, &events) }); let mut out_events = events.borrow_mut(); for event in out.events { @@ -280,15 +285,6 @@ impl<'a> RenderQueueList<'a> { let removable = |key: &RenderItemId| items.iter().any(|item| item.id == *key && !item.status.is_encoding()); out_events.extend(keys.into_iter().filter(removable).map(RenderQueueEvent::Remove)); } - CollectionEvent::Item(key, RowEvent::Trailing { part, .. }) => { - let item = items.iter().find(|item| item.id == key); - match (part, item.map(|item| &item.status)) { - (REMOVE, _) => out_events.push(RenderQueueEvent::Remove(key)), - (ACTION, Some(RenderStatus::Ready | RenderStatus::Encoding { .. })) => out_events.push(RenderQueueEvent::Cancel(key)), - (ACTION, Some(_)) => out_events.push(RenderQueueEvent::Retry(key)), - _ => {} - } - } _ => {} } } diff --git a/crates/ui-contract/src/contract/collection/props.rs b/crates/ui-contract/src/contract/collection/props.rs index 73f4d3a10..61e5dc235 100644 --- a/crates/ui-contract/src/contract/collection/props.rs +++ b/crates/ui-contract/src/contract/collection/props.rs @@ -544,7 +544,7 @@ impl CollectionProps { } } -/// Where the collection holds a primary press on a row, within slop. +/// Where the collection holds a primary press on a row, within slop, or the press a part of the row holds. #[derive(Clone, Debug, PartialEq, Eq)] #[non_exhaustive] pub enum RowPressed { @@ -552,6 +552,12 @@ pub enum RowPressed { Row, /// On the cell of this toggle column, which the press flips. Cell(ColumnKey), + /// On a part of the item that took the press itself (a row's trailing button). + #[non_exhaustive] + Part { + /// The row held the lead when the press began: a press on a part moves the lead to its row. + was_lead: bool, + }, } /// What an item reads of its place in the collection; the item step joins it to the item's flags at step 12. diff --git a/crates/ui-contract/src/contract/items/drag.rs b/crates/ui-contract/src/contract/items/drag.rs index c8b344b88..6e990068c 100644 --- a/crates/ui-contract/src/contract/items/drag.rs +++ b/crates/ui-contract/src/contract/items/drag.rs @@ -167,6 +167,8 @@ pub(super) struct Drags { pub(super) marquee: Option>, /// A plain press on the only selected item of a `slow_click_rename` collection, waiting to become a rename. pub(super) slow: Option>, + /// The row a press an item part won landed on, and whether the row held the lead when the press began. + pub(super) part_press: Option<(K, bool)>, } /// A press that opens a rename when it ends as a click on the item's label and no second press follows within the @@ -195,6 +197,7 @@ impl Default for Drags { command: None, marquee: None, slow: None, + part_press: None, } } } diff --git a/crates/ui-contract/src/contract/items/press.rs b/crates/ui-contract/src/contract/items/press.rs index b94e6120d..3ac6f1ab4 100644 --- a/crates/ui-contract/src/contract/items/press.rs +++ b/crates/ui-contract/src/contract/items/press.rs @@ -156,11 +156,27 @@ impl ItemsHooks<'_, '_, C> { && let Some(at) = layout.hit(local(start.origin), offset).filter(|&at| self.source.enabled(at) && layout.shown(at)) && (target.owner != cx.core.id || target.part.is_some_and(|part| part.key == SECTION)) { + let key = self.source.key(at); + self.drags.part_press = Some((key.clone(), self.lead.key.as_ref() == Some(&key))); self.move_lead(at, LeadSource::Pointer); if props.focus_on_press && !target.sense.intersects(Sense::TAKE_FOCUS | Sense::KEEP_FOCUS) { focus::request_now(&ctx, focus::FocusTarget::Id(cx.core.id)); } } + // While a part of an item holds the press, and in the pass it ends, the row reads it with whether it held the lead + // when the press began. + match outcome.phase { + Some(PressPhase::Down { .. } | PressPhase::Held { .. } | PressPhase::Release { .. }) + if outcome.target.is_some_and(|target| target.part.is_some()) => + { + if let Some((key, was_lead)) = self.drags.part_press.clone() + && let Some(at) = self.index_of(&key) + { + self.pressed = Some((at, RowPressed::Part { was_lead })); + } + } + _ => self.drags.part_press = None, + } // A click on a row's thumbnail is also a click on the row: the item reports the thumbnail's click and an unmodified click picks // in the same pass. if let (Some(PressPhase::Release { click: true, start, .. }), Some(target)) = (outcome.phase, outcome.target) diff --git a/crates/ui-widgets/src/list/row.rs b/crates/ui-widgets/src/list/row.rs index d74fc0901..45e3c2f02 100644 --- a/crates/ui-widgets/src/list/row.rs +++ b/crates/ui-widgets/src/list/row.rs @@ -41,7 +41,7 @@ pub(crate) use thumb::RowThumb; pub(super) use thumb::Thumb; use thumb::ThumbPayload; pub use thumb::{ThumbAspect, ThumbPaint, ThumbSize, ThumbTarget}; -use trailing::HostedShow; +use trailing::{Hosted, Hosting}; pub(super) use trailing::{Trailing, TrailingItem}; pub use trailing::{TrailingFace, TrailingPart}; @@ -199,6 +199,8 @@ pub struct ListRow<'a> { pub(super) lead_paint: Option>, pub(super) thumb: ThumbSize, pub(super) thumb_aspect: ThumbAspect, + /// The leading text and the widest text its slot is sized for (`lead_text`). + pub(super) lead_text: Option<(Label, Label)>, pub(super) first: Option>, pub(super) extras: Vec>, /// The thumbnail the row's editing is aimed at: framed with corner brackets whether or not the row is selected. @@ -270,6 +272,7 @@ impl<'a> ListRow<'a> { thumb: ThumbSize::None, thumb_aspect: ThumbAspect::SQUARE, first: None, + lead_text: None, extras: Vec::new(), target: None, trailing: Vec::new(), @@ -460,14 +463,42 @@ impl<'a> ListRow<'a> { self.trailing_part_revealed(TrailingPart::MENU, TrailingFace::Icon(IconSpec::svg(craft_behavior::IconId::new("more"))), Label::Empty) } - /// A component at the trailing end, in the width of a short field, that always shows: a field that edits a - /// value of the row. The row shows `field` in its slot and hands its output to `output` in the pass it is shown. The - /// field's stop joins the row's roving group like the row's focusable parts (Forward from the row enters it, Tab leaves the collection); it takes the keys it - /// declares. + /// A component at the trailing end, as wide as it measures, that always shows: a field that edits a value of the + /// row, or a button. The row shows `field` in its slot and hands its output to `output` in the pass it is shown. + /// The field's stop joins the row's roving group like the row's focusable parts (Forward from the row enters it, + /// Tab leaves the collection); it takes the keys it declares. #[must_use] - pub fn trailing_field(mut self, field: C, output: impl FnOnce(C::Output) + 'a) -> Self { - let show: HostedShow<'a> = Box::new(move |ui, at, rect| output(ui.child(("field", at), rect, field))); - self.trailing.push(Trailing { item: TrailingItem::Hosted(Some(show)), optional: false }); + pub fn trailing_field(self, field: C, output: impl FnOnce(C::Output) + 'a) -> Self { + self.hosted(Hosting { component: field, output, shown: true }, false) + } + + /// A component at the trailing end as [`trailing_field`](Self::trailing_field) adds one, that drops out when the + /// label would get narrower than its least width with it (a binding's badge). + #[must_use] + pub fn optional_field(self, field: C, output: impl FnOnce(C::Output) + 'a) -> Self { + self.hosted(Hosting { component: field, output, shown: true }, true) + } + + /// Empty room at the trailing end, as wide as `component` measures: a row that lacks a field the other rows have + /// keeps the items after it in line with theirs. Nothing is shown. + #[must_use] + pub fn trailing_space(self, component: C) -> Self { + self.hosted(Hosting { component, output: |_| {}, shown: false }, false) + } + + fn hosted(mut self, hosting: impl trailing::HostedItem + 'a, optional: bool) -> Self { + let item = Hosted { item: Some(Box::new(hosting)), size: None }; + self.trailing.push(Trailing { item: TrailingItem::Hosted(item), optional }); + self + } + + /// A short text in the leading slot (a page number), in the detail's role and ink, at the slot's end so the labels + /// after it line up: the slot is as wide as `widest` measures. It takes the icon's place; thumbnails replace it. + /// A click on it picks the row as a click on the row does and reports [`RowEvent::LeadClicked`]; a double click + /// there does not activate the row. + #[must_use] + pub fn lead_text(mut self, text: impl Into