framework: setters that only store their argument are #[prop] fields the Props derive writes (TaskBar, FloatingGroup, ToolbarDrawer, CommandPalette, PresetBrowser, PresetPicker, AppShell, Radio, Swatch, Text, ListRow); ToolbarDrawer::mark and reveal take the tool, as ToolRail's do

This commit is contained in:
bflatastic
2026-11-22 20:07:27 +07:00
parent eaa3433662
commit 9a4b9efb48
13 changed files with 60 additions and 120 deletions
@@ -92,6 +92,9 @@ pub struct TaskBar<'a> {
/// The side of the anchor the bar hangs on; `None` gives the kind's side: above for `Selection`, below for `Task`.
side: Option<Side>,
align: Align,
/// A moved bar whose offset place would cover this point (a document point, like the anchor) shows at its unmoved
/// place and keeps its offset.
#[prop]
keep_clear: Option<Point>,
/// What an outside press does to the bar.
#[prop]
@@ -256,14 +259,6 @@ impl<'a> TaskBar<'a> {
self
}
/// A moved bar whose offset place would cover `point` (a document point, like the anchor) shows at its unmoved
/// place and keeps its offset.
#[must_use]
pub fn keep_clear(mut self, point: Point) -> Self {
self.keep_clear = Some(point);
self
}
/// Shows the bar inside `area`; `body` fills its members.
pub fn show<R>(self, ui: &mut Ui, area: Rect, mut body: impl FnMut(&mut Ui, &mut TaskBarCx<'_>) -> R) -> Inner<TaskBarOutput, R> {
let TaskBar { label, anchor, mut place, rows, kind, side, align, keep_clear, dismiss } = self;
+7 -14
View File
@@ -287,8 +287,13 @@ pub struct FloatingGroup<'a> {
take_drop: Option<TakeDrop<'a>>,
/// A move by the title began this pass.
moving: bool,
/// Where the pointer is inside the window whose move band takes over the held press this pass; set by
/// `continue_move`.
/// The window takes over the held primary press in this pass: its own move gesture begins from that press with the
/// pointer at this point inside the window, so the window follows the pointer and, with
/// [`window_of`](FloatingGroup::window_of), docks where it would dock on release. A request of the pass, for the
/// pass after a rail's `torn_off`; without a held press it does nothing. Only a window on a layer takes the press:
/// the OS keeps a held button's moves with the window it went down in, so a group shown in an OS window
/// ([`native`](FloatingGroup::native)) moves only when pressed again.
#[prop(quantity = "grab point")]
continue_move: Option<Vec2>,
/// The files dropped on the group's OS window that no target there took.
files: Vec<OsFile>,
@@ -368,18 +373,6 @@ impl<'a> FloatingGroup<'a> {
self
}
/// The window takes over the held primary press in this pass: its own move gesture begins from that press with the
/// pointer at `grab` inside the window, so the window follows the pointer and, with
/// [`window_of`](FloatingGroup::window_of), docks where it would dock on release. A request of the pass, for the
/// pass after a rail's `torn_off`; without a held press it does nothing. Only a window on a layer takes the press:
/// the OS keeps a held button's moves with the window it went down in, so a group shown in an OS window
/// ([`native`](FloatingGroup::native)) moves only when pressed again.
#[must_use]
pub fn continue_move(mut self, grab: Vec2) -> Self {
self.continue_move = Some(grab);
self
}
/// The action parts at the end of the title row, in reading order.
#[must_use]
pub fn actions(mut self, actions: impl IntoIterator<Item = HeaderAction>) -> Self {
+6 -21
View File
@@ -148,10 +148,14 @@ pub struct ToolbarDrawer<'a, T: Value + 'static> {
#[prop]
opens: Side,
/// The tool whose row wears the target mark.
#[prop]
mark: Option<&'a T>,
/// A request of the pass: scrolls the tool's row into the list's view.
/// A request of the pass: scrolls the tool's row into the list's view. Send it in the pass that needs it, not every
/// pass.
#[prop]
reveal: Option<&'a T>,
/// The rows of the menu the header's menu button opens; no button without rows.
/// With rows, an icon button after the title opens a menu of them.
#[prop]
menu: Vec<PanelRow>,
dropped: Option<ToolDropped>,
opener: Option<Response>,
@@ -170,18 +174,6 @@ impl<'a, T: Value + 'static> ToolbarDrawer<'a, T> {
self.opener = Some(opener.clone());
self
}
/// The tool whose row wears the target mark; `None` marks none.
pub fn mark(mut self, tool: Option<&'a T>) -> Self {
self.mark = tool;
self
}
/// A request: scrolls the row of `tool` into the list's view. Send it in the pass that needs it, not every pass.
pub fn reveal(mut self, tool: Option<&'a T>) -> Self {
self.reveal = tool;
self
}
}
/// A row of the drawer's list.
@@ -262,13 +254,6 @@ fn on_toolbar<T: PartialEq>(toolbar: &[ToolSlot<T>], id: &T) -> bool {
}
impl<T: Value + 'static> ToolbarDrawer<'_, T> {
/// With rows, an icon button after the title opens a menu of `rows`.
#[must_use]
pub fn menu(mut self, rows: Vec<PanelRow>) -> Self {
self.menu = rows;
self
}
/// Shows the drawer and reports what the user changed.
pub fn show(self, ui: &mut Ui) -> ToolbarDrawerOutput<T> {
self.show_with(ui, |_| {})
+11 -1
View File
@@ -80,5 +80,15 @@ fn toolbar_drawer_menu_footer_and_runs(ui: &mut Ui, data: &mut StoryData) -> Sto
fn toolbar_drawer_marked_tool(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let marked = 4_u8;
let groups = [DrawerGroup::new("Drawing", tools(&[0, 1, 2])), DrawerGroup::new("Retouching", tools(&[3, 4]))];
staged(ui, data, &groups, &toolbar(), |drawer, fresh| drawer.mark(Some(&marked)).reveal(fresh.then_some(&marked)), |_| {})
staged(
ui,
data,
&groups,
&toolbar(),
|drawer, fresh| {
let drawer = drawer.mark(&marked);
if fresh { drawer.reveal(&marked) } else { drawer }
},
|_| {},
)
}
+8 -2
View File
@@ -178,8 +178,14 @@ fn a_revealed_tool_scrolls_into_view_and_wears_the_mark() {
let toolbar = [slot(0, &[UNDO])];
let rail = Rect::from_min_size(Pos2::ZERO, Vec2::new(48.0, ROOM.y));
let target = CUT;
let reveal = pending.replace(false).then_some(&target);
ToolbarDrawer::new(rail, &groups, &toolbar, None).reveal(reveal).mark(marked.then_some(&target)).show(ui);
let mut drawer = ToolbarDrawer::new(rail, &groups, &toolbar, None);
if pending.replace(false) {
drawer = drawer.reveal(&target);
}
if marked {
drawer = drawer.mark(&target);
}
drawer.show(ui);
});
fixture.room(ROOM).idle(60);
// The drawer is a popover over the window, which is larger than the room: its list scrolls inside it.
@@ -140,6 +140,8 @@ pub struct CommandPalette<'a> {
entries: &'a [HelpEntry],
index: &'a SearchIndex,
open: Bind<'a, bool>,
/// The pick counts that rank the results, 0 for a command never picked.
#[prop]
uses: Option<&'a dyn Fn(&CommandRef) -> u32>,
/// The commands last run, newest first.
#[prop]
@@ -176,13 +178,6 @@ impl<'a> CommandPalette<'a> {
}
}
/// The pick counts that rank the results, 0 for a command never picked.
#[must_use]
pub fn uses(mut self, uses: &'a dyn Fn(&CommandRef) -> u32) -> Self {
self.uses = Some(uses);
self
}
/// Puts `command` first in `recents`, once, keeping the newest `RECENT_KEPT`.
pub fn remember(recents: &mut Vec<CommandRef>, command: CommandRef) {
recents.retain(|held| *held != command);
@@ -344,6 +344,8 @@ pub struct PresetBrowser<'a, K: Clone + Eq + Hash + Send + Sync + MemoProps + 's
#[prop]
drop_zone: Option<DropZone>,
actions: Vec<Label>,
/// Paints the tip that shows on hover over a tile or row.
#[prop(boxed = "Fn(&mut Ui, &K) + 'a")]
tip: Option<TipFn<'a, K>>,
drops: Vec<PresetDrop<'a, K>>,
/// The search field is its scope's default stop (`Initial::Default`): a picker's popover opens with the focus in
@@ -415,13 +417,6 @@ impl<'a, K: Clone + Eq + Hash + Send + Sync + MemoProps + 'static> PresetBrowser
self
}
/// Paints the tip that shows on hover over a tile or row.
#[must_use]
pub fn tip(mut self, f: impl Fn(&mut Ui, &K) + 'a) -> Self {
self.tip = Some(Box::new(f));
self
}
/// The id of the browser's list, the `ListDrag::list` of its drags: a footer action accepts only drags from its own
/// browser.
pub fn list_id(browser: Id) -> Id {
@@ -183,6 +183,8 @@ pub struct PresetPicker<'a, K: Value + Eq + Hash + MemoProps + 'static> {
/// Whether a secondary click or the context-menu key opens the browser's row menu.
#[prop]
row_menu: PresetRowMenu,
/// Paints the tip that shows on hover over a tile or row of the picker's browser.
#[prop(boxed = "Fn(&mut Ui, &K) + 'a")]
tip: Option<TipFn<'a, K>>,
/// Shown, muted, while the value is no preset of the rows.
#[prop(into)]
@@ -245,13 +247,6 @@ struct Session {
}
impl<'a, K: Value + Eq + Hash + MemoProps + 'static> PresetPicker<'a, K> {
/// Paints the tip that shows on hover over a tile or row of the picker's browser.
#[must_use]
pub fn tip(mut self, f: impl Fn(&mut Ui, &K) + 'a) -> Self {
self.tip = Some(Box::new(f));
self
}
/// A picker with the same settings that borrows this one, so a composite whose body runs more than once in a
/// pass (a wrapping row measures before it shows) shows a fresh picker in each run, as [`Bind::reborrowed`]
/// hands on a binding. Bindings and the host's closures are borrowed; the rest is copied.
+4 -9
View File
@@ -428,7 +428,10 @@ pub struct AppShell<'a, S> {
body_label: Option<Label>,
title: Option<Placed<'a, S>>,
slots: Vec<Placed<'a, S>>,
/// Where the options bar sits; the top slot without a binding.
/// The options bar follows the bound place: the top or the bottom slot, or, while floating, a movable modeless layer over
/// the body that takes no room. A drag of a [`BarGrip`](super::BarGrip) writes the place on the release. Without the
/// call the bar is the top slot, as [`options_bar`](Self::options_bar) shows it.
#[prop(name = "options_place")]
place: Bind<'a, OptionsBarPlace>,
/// The body, shown in what the slots leave.
#[prop(func = "FnMut(&mut Ui, &mut BodyCx<'_>, &mut S)")]
@@ -506,14 +509,6 @@ impl<'a, S> AppShell<'a, S> {
self
}
/// The options bar follows `place`: the top or the bottom slot, or, while floating, a movable modeless layer over
/// the body that takes no room. A drag of a [`BarGrip`](super::BarGrip) writes the place on the release. Without the
/// call the bar is the top slot, as [`options_bar`](Self::options_bar) shows it.
pub fn options_place(mut self, place: Bind<'a, OptionsBarPlace>) -> Self {
self.place = place;
self
}
/// The status bar, a bottom slot keyed `"status"` that never reveals.
pub fn status(mut self, visible: bool, add: impl FnMut(&mut Ui, &mut BodyCx<'_>, &mut S) + 'a) -> Self {
let slot = Slot::new(keys::STATUS).visible(visible);
+4 -10
View File
@@ -152,7 +152,7 @@ pub struct RadioStyle {
}
/// A member of a `RadioGroup`: selected when the group's pick is its value.
#[derive(crate::contract::Component)]
#[derive(crate::contract::Component, crate::contract::Props)]
#[component(probe(Radio<u8>))]
pub struct Radio<T: Value + 'static> {
#[common]
@@ -160,7 +160,9 @@ pub struct Radio<T: Value + 'static> {
value: T,
checked: bool,
invalid: bool,
/// The line after the label ([`Radio::detail`]).
/// A dimmed line after the label (the label's detail: muted text), inside the radio's hit area; it joins the
/// radio's description.
#[prop(into)]
detail: Option<crate::runtime::env::Label>,
}
@@ -169,14 +171,6 @@ impl<T: Value + 'static> Radio<T> {
pub fn new(value: T) -> Self {
Radio { common: Common::new(), value, checked: false, invalid: false, detail: None }
}
/// A dimmed line after the label (the label's detail: muted text), inside the radio's hit area; it joins the
/// radio's description.
#[must_use]
pub fn detail(mut self, text: impl Into<crate::runtime::env::Label>) -> Self {
self.detail = Some(text.into());
self
}
}
impl<T: Value + 'static> Component for Radio<T> {
+3 -8
View File
@@ -157,7 +157,9 @@ pub struct Swatch<T: Value + 'static = ()> {
#[style_key]
#[prop(flag)]
well: bool,
/// The marks drawn on the well.
/// Paints these marks on the well: the edge mark, a locked corner square, a web-safe centre diamond, the
/// transparent checker half and the source-colour corner triangle, each from tokens.
#[prop]
marks: CellMarks,
/// The well shows its colour as a ring: a band of the colour round the edge, open in the middle.
#[style_key]
@@ -215,13 +217,6 @@ impl<T: Value + 'static> Swatch<T> {
activation: None,
}
}
/// Paints the marks of `marks` on the well: the edge mark, a locked corner square, a web-safe centre diamond, the
/// transparent checker half and the source-colour corner triangle, each from tokens.
#[must_use]
pub fn marks(self, marks: CellMarks) -> Self {
Self { marks, ..self }
}
}
/// The marks of a swatch cell: each is painted from tokens. Other crates build them with the builders, as
+2 -8
View File
@@ -80,7 +80,8 @@ pub struct Text {
spans: Vec<DocRun<'static>>,
/// The interface spans that replace the label's text, in the type role, shade and tone of the text; empty for plain text.
styled: Vec<Span<'static>>,
/// The text whose width stands for the label's ideal and least width.
/// Sets the text's ideal and least width to those of this text, so a readout keeps its width while its value changes.
#[prop(into)]
sample: Option<Label>,
/// Whether every span is italic, a value set apart from the words around it.
italic: bool,
@@ -122,13 +123,6 @@ impl Text {
text
}
/// Sets the text's ideal and least width to those of `sample`, so a readout keeps its width while its value changes.
#[must_use]
pub fn sample(mut self, sample: impl Into<Label>) -> Self {
self.sample = Some(sample.into());
self
}
/// Sets the text in italics: a value set apart from the words around it. The resolved label is what is set, so a
/// catalogue word shows in its own language.
pub fn italic(mut self) -> Self {
+6 -18
View File
@@ -206,7 +206,9 @@ pub struct ListRow<'a> {
pub(super) thumbnails_only: bool,
/// The full-height bar at the start of the row's content (`stripe`).
pub(super) stripe: Option<(crate::style::DataColor, crate::primitives::StrokeWidth)>,
/// The row's place in a run of rows that share one outline (`run`).
/// One outline per run in the divider stroke and `radius.control`, inside each row's rect, for the row at this place
/// in a run of rows.
#[prop]
pub(super) run: Option<RowRun>,
/// The row is the divider that sets a group off (`GroupHeads::Rule`): a rule across the row, no title, no disclosure
/// and no focus stop; the label stays its accessible name.
@@ -286,6 +288,9 @@ pub struct ListRow<'a> {
/// The type role of the leading text: `Caption` unless set.
#[prop]
pub(super) lead_role: TypeRole,
/// The row is as tall as a row with a thumbnail of this size and draws no thumbnail; its icon stands in the thumbnail's
/// place.
#[prop(name = "thumb_height")]
pub(super) thumb: ThumbSize,
pub(super) thumb_aspect: ThumbAspect,
pub(super) first: Option<ThumbPaint<'a>>,
@@ -330,14 +335,6 @@ pub struct ListRow<'a> {
}
impl<'a> ListRow<'a> {
/// One outline per run in the divider stroke and `radius.control`, inside each row's rect, for the row at `run`'s
/// place in a run of rows.
#[must_use]
pub fn run(mut self, run: RowRun) -> Self {
self.run = Some(run);
self
}
/// A full-height bar at the start of the row's content, after its toggle cells and before the indent. It takes no
/// room from the label and mirrors in right-to-left. It is not the `striped` list tint.
#[must_use]
@@ -346,15 +343,6 @@ impl<'a> ListRow<'a> {
self
}
/// The row is as tall as a row with a `size` thumbnail and draws no thumbnail; its icon stands in the thumbnail's
/// place.
#[must_use]
pub fn thumb_height(mut self, size: ThumbSize) -> Self {
// Without a first thumbnail nothing is placed or painted, but the row's height follows `thumb`.
self.thumb = size;
self
}
/// Makes the row the divider of a group head under `GroupHeads::Rule`.
#[must_use]
pub(super) fn rule_head(mut self) -> Self {