diff --git a/crates/pages/src/ui/thumbnails.rs b/crates/pages/src/ui/thumbnails.rs index efaef58d4..60f8b8445 100644 --- a/crates/pages/src/ui/thumbnails.rs +++ b/crates/pages/src/ui/thumbnails.rs @@ -304,7 +304,7 @@ impl<'a> PageThumbnails<'a> { grid = grid.collapsible(); } if editable { - grid = grid.reorder(ReorderRule::new()).takes_files(true).deletable(true); + grid = grid.reorder(ReorderRule::new()).drag_count(words.count.counted()).takes_files(true).deletable(true); } let ctx = ui.ctx().clone(); let thumbnails = Thumbnails::::in_context(&ctx, "page-thumbnails", ThumbnailOptions::new()); diff --git a/crates/ui-contract/src/contract/collection/props.rs b/crates/ui-contract/src/contract/collection/props.rs index ed9252890..a317f1a1b 100644 --- a/crates/ui-contract/src/contract/collection/props.rs +++ b/crates/ui-contract/src/contract/collection/props.rs @@ -2,7 +2,7 @@ use super::columns::{ColumnSort, ColumnSpec}; use super::events::ListDrag; -use crate::runtime::env::Label; +use crate::runtime::env::{Counted, Label}; use craft_behavior::{Axis, ColumnKey}; use std::any::Any; use std::sync::Arc; @@ -182,6 +182,9 @@ pub struct CollectionProps { /// Maps a row drag to the payload that other drop targets take (8.4). A map starts row drags by itself, with or /// without a reorder rule. pub drag_payload: Option, + /// The count word the drag badge shows for the dragged items, one item included ("1 page", "3 pages"); `None` + /// shows the number of items for several and the item's text for one. + pub drag_count: Option, /// The collection takes the full height of its rows and owns no scroll, so it can sit inside a scrolling page: /// every row is built, the wheel and the keys that move past an end act on the page's scroll owner, and moving /// the lead scrolls the page to keep the row in view. For short collections only; a long one keeps its own @@ -268,6 +271,7 @@ impl CollectionProps { marquee: false, deletable: false, drag_payload: None, + drag_count: None, natural_height: false, overflow: Axis::Y, pages: false, @@ -297,6 +301,13 @@ impl CollectionProps { self } + /// The drag badge reads `count` for the number of dragged items. + #[must_use] + pub const fn drag_count(mut self, count: Counted) -> Self { + self.drag_count = Some(count); + self + } + /// The items are pages (`CollectionProps::pages`). #[must_use] pub const fn pages(mut self, on: bool) -> Self { diff --git a/crates/ui-contract/src/contract/items/drag.rs b/crates/ui-contract/src/contract/items/drag.rs index 837c97287..c5d9e10f5 100644 --- a/crates/ui-contract/src/contract/items/drag.rs +++ b/crates/ui-contract/src/contract/items/drag.rs @@ -368,10 +368,11 @@ impl ItemsHooks<'_, '_, C> { let id = cx.core.id; let key = self.source.key(at); let keys: Vec = if self.holds(at) { self.selected_keys(&self.selection) } else { vec![key.clone()] }; - let preview = if keys.len() > 1 { - DragPreview::Badge(Label::from(keys.len().to_string())) - } else { - self.source.text(at).map_or(DragPreview::None, |text| DragPreview::Badge(Label::from(text.into_owned()))) + let count = keys.len() as u64; + let preview = match props.drag_count { + Some(word) => DragPreview::Badge(Label::from(cx.env.counted(word, count))), + None if count > 1 => DragPreview::Badge(Label::from(count.to_string())), + None => self.source.text(at).map_or(DragPreview::None, |text| DragPreview::Badge(Label::from(text.into_owned()))), }; let drag = ListDrag::new(id, keys, key.clone()); match props.drag_payload.as_ref().and_then(|map| map.of(&drag)) { diff --git a/crates/ui-contract/src/runtime/env/view.rs b/crates/ui-contract/src/runtime/env/view.rs index 12fbcb330..8193fd175 100644 --- a/crates/ui-contract/src/runtime/env/view.rs +++ b/crates/ui-contract/src/runtime/env/view.rs @@ -8,7 +8,7 @@ use super::{ItemFacts, Scoped}; use crate::runtime::commands::CommandChain; use craft_host::Host; use craft_host::target::ShellInfo; -use craft_i18n::{AgeStyle, Direction, WordSet}; +use craft_i18n::{AgeStyle, Counted, Direction, WordSet}; use craft_i18n::{CalendarDate, DateFormat, Format}; use craft_theme::Mode; use egui::Id; @@ -135,6 +135,11 @@ impl<'a> EnvView<'a> { craft_i18n::relative_age(&self.scoped.words, &self.scoped.format, seconds, style) } + /// `n` things by the count word `count`, in the scope's language and digits: "1 page", "3 pages". + pub fn counted(&self, count: Counted, n: u64) -> String { + self.scoped.words.counted(count, n, &self.scoped.format.integer(n)) + } + /// `label` with a `Word` replaced by its text in the scope's language: what domain code that draws a `Label` /// itself shows. pub fn resolve(&self, label: &Label) -> Label { diff --git a/crates/ui-macros/src/props.rs b/crates/ui-macros/src/props.rs index ceb3bae8e..9651527f4 100644 --- a/crates/ui-macros/src/props.rs +++ b/crates/ui-macros/src/props.rs @@ -187,6 +187,7 @@ const COLLECTION: &[Forwarded] = &[ ("item_keys", "::craft_ui::contract::ItemKeys", "Who takes the arrow keys: the collection (moves the lead) or the component around it."), ("marquee", "bool", "A drag on the background selects the rows it covers."), ("deletable", "bool", "Delete and Backspace at the lead report the items to delete."), + ("drag_count", "::craft_ui::runtime::env::Counted", "The drag badge reads this count word for the dragged items, one included."), ("natural_height", "bool", "The collection takes its full content height and owns no scroll: for a short collection inside a scrolling page."), ( "current", diff --git a/crates/ui-panels/src/sections/section.rs b/crates/ui-panels/src/sections/section.rs index d1aa92f38..1f82595ad 100644 --- a/crates/ui-panels/src/sections/section.rs +++ b/crates/ui-panels/src/sections/section.rs @@ -35,8 +35,8 @@ pub struct SectionOutput { pub response: Response, /// The header action part taken this pass. pub action: Option, - /// The header band was press-dragged past the drag threshold this pass. - pub grabbed: bool, + /// The header band was press-dragged past the drag threshold this pass: the section's title, for the drag badge. + pub grabbed: Option