Design lint: Bar and CommandPalette setters come from the props macro

CommandPalette::state and Bar::background_press are #[prop] fields. Bar::look(BarLook) becomes Bar::over_picture(), since choosing the look also clears the container surface; Bar forwards no container builders, so its own surface() stays. The bar stories stand the bar over the stage with Stack::show_at and read clicks with contract::clicked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Dylan M. TaylorandClaude Opus 5.5 committed 2026-11-29 15:18:46 +00:00
1 parent 878ebe405b
commit 3e06f8189d
4 files changed
+51 -44

No files matched your search

@@ -163,7 +163,9 @@ pub struct CommandPalette<'a> {
entries: &'a [HelpEntry],
index: &'a SearchIndex,
open: Bind<'a, bool>,
/// The optional query and selection shared with the host.
/// The query and selection shared with the host: the bound state is the palette's query and selection authority,
/// read and written each pass. Without this binding, the palette keeps its own state.
#[prop]
state: Option<Bind<'a, PaletteState>>,
/// The pick counts that rank the results, 0 for a command never picked.
#[prop]
@@ -214,13 +216,6 @@ impl<'a> CommandPalette<'a> {
}
}
/// Uses the bound state as the palette's query and selection authority, read and written each pass.
/// Without this binding, the palette keeps its own state.
pub fn state(mut self, state: Bind<'a, PaletteState>) -> Self {
self.state = Some(state);
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);
+10 -11
View File
@@ -117,18 +117,21 @@ impl Outcome for BarOutput {
/// The bar is a plain container; its members are the host's. A host memoizes them with a `MemoView` inside the body
/// closure, over props that hold what the members read (`BarItem`, `StatusMessage`, `StatusProgress` and the other
/// member types derive `MemoProps`), and sends the members' events through an `Outbox`.
#[derive(crate::contract::Component)]
#[derive(crate::contract::Component, crate::contract::Props)]
#[component(container)]
pub struct Bar<'a> {
#[common]
common: Common,
#[container]
// The bar writes its container props itself (`surface` keeps the over-picture scrim): no builder is forwarded.
#[container()]
props: ContainerProps,
kind: BarKind,
/// The surface and member placement of the bar.
#[style_key]
look: BarLook,
chrome_surface: SurfaceKind,
/// Whether empty bar space owns background presses through drag and release.
#[prop]
background_press: BarBackgroundPress,
commit_cancel: Option<(Label, Label)>,
committed: bool,
@@ -137,15 +140,11 @@ pub struct Bar<'a> {
}
impl<'a> Bar<'a> {
/// Chooses whether empty bar space owns background presses through drag and release.
pub fn background_press(mut self, policy: BarBackgroundPress) -> Self {
self.background_press = policy;
self
}
/// Sets a chrome or over-picture surface with the same member arrangement.
pub fn look(mut self, look: BarLook) -> Self {
self.look = look;
/// Stands the bar over a picture ([`BarLook::OverPicture`]): a pill scrim with ghost members in place of the
/// chrome surface, with the same member arrangement.
#[must_use]
pub fn over_picture(mut self) -> Self {
self.look = BarLook::OverPicture;
self.apply_surface();
self
}
+35 -22
View File
@@ -1,16 +1,16 @@
//! Stories of the bars.
use super::{
Bar, BarBackgroundPress, BarHome, BarItem, BarItems, BarKind, BarLook, BarTool, ItemDisplay, StatusItem, StatusMessage, StatusProgress,
StatusReadout, StatusValues,
Bar, BarBackgroundPress, BarHome, BarItem, BarItems, BarKind, BarTool, ItemDisplay, StatusItem, StatusMessage, StatusProgress, StatusReadout,
StatusValues,
};
use crate::buttons::{Button, Link};
use crate::choice::{Checkbox, Segmented};
use crate::contract::{Bind, Entry, Props as _};
use crate::contract::{Bind, Entry, Props as _, clicked};
use crate::contract::{Show as _, ShowContainer as _};
use crate::display::{Divider, Picture, PictureSize, Shade, Text};
use crate::form::Field;
use crate::layout_components::Row;
use crate::layout_components::{Row, Stack};
use crate::list::{ThumbAspect, ThumbSize};
use crate::menu::{Menu, MenuItem};
use crate::pickers::Select;
@@ -58,13 +58,19 @@ fn over_picture(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
.extent(PictureSize::Thumb(ThumbSize::Large))
.show(ui)
.rect;
let mut overlay = ui.new_child(egui::UiBuilder::new().max_rect(stage));
Bar::new("Picture tools", BarKind::Tool)
.look(BarLook::OverPicture)
.show(&mut overlay, |ui, _| {
BarItems::new(items()).show(ui);
})
.into()
// The bar stands at the top of the stage, over the picture.
let shown = Stack::new().show_at(ui, stage, |ui, _| {
Bar::new("Picture tools", BarKind::Tool)
.over_picture()
.show(ui, |ui, _| {
BarItems::new(items()).show(ui);
})
.output
});
match shown.inner {
Some(bar) => bar.into(),
None => shown.output.into(),
}
}
/// Empty bar space owns the press while the member still activates; the stage remains a separate target.
@@ -76,21 +82,28 @@ fn bar_background_press(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
.extent(PictureSize::Thumb(ThumbSize::Large))
.show(ui)
.rect;
if Button::new("Stage").show_at(ui, stage).clicked() {
if clicked(&Button::new("Stage").show_at(ui, stage)) {
stage_clicks += 1;
}
let mut overlay = ui.new_child(egui::UiBuilder::new().max_rect(stage));
let shown = Bar::new("Absorbing bar", BarKind::Tool).look(BarLook::OverPicture).background_press(BarBackgroundPress::Absorb).show(
&mut overlay,
|ui, _| {
if Button::new("Member").show(ui).clicked() {
member_clicks += 1;
}
},
);
// The bar stands at the top of the stage, over the stage's button.
let shown = Stack::new().show_at(ui, stage, |ui, _| {
Bar::new("Absorbing bar", BarKind::Tool)
.over_picture()
.background_press(BarBackgroundPress::Absorb)
.show(ui, |ui, _| {
if clicked(&Button::new("Member").show(ui)) {
member_clicks += 1;
}
})
.output
});
*data.value("stage clicks", 0usize) = stage_clicks;
*data.value("member clicks", 0usize) = member_clicks;
StoryOutput::from(shown).readout(format!("Stage activations: {stage_clicks}; member activations: {member_clicks}"))
let output = match shown.inner {
Some(bar) => StoryOutput::from(bar),
None => StoryOutput::from(shown.output),
};
output.readout(format!("Stage activations: {stage_clicks}; member activations: {member_clicks}"))
}
/// A bar made to wrap: its members continue on a new line in a narrow stage instead of scrolling.
+3 -3
View File
@@ -5,7 +5,7 @@
use craft_behavior::IconId;
use craft_behavior::kurbo::Size;
use craft_theme::variant::Tone;
use craft_ui::bars::{Bar, BarKind, BarLook, BreadcrumbBar, StatusItem, StatusMessage, StatusProgress, StatusReadout, StatusValues, path_crumbs};
use craft_ui::bars::{Bar, BarKind, BreadcrumbBar, StatusItem, StatusMessage, StatusProgress, StatusReadout, StatusValues, path_crumbs};
use craft_ui::buttons::{Button, IconButton, Link};
use craft_ui::choice::Checkbox;
use craft_ui::contract::{Bind, Entry, Props as _, Show as _, ShowContainer as _, Sizing};
@@ -40,7 +40,7 @@ fn an_over_picture_bar_and_a_painted_hint_share_their_surface() {
Bar::new("Chrome tools", BarKind::Tool).show(ui, |ui, _| {
Button::new("Chrome action").show(ui);
});
let bar = Bar::new("Picture tools", BarKind::Tool).look(BarLook::OverPicture).show(ui, |ui, _| {
let bar = Bar::new("Picture tools", BarKind::Tool).over_picture().show(ui, |ui, _| {
Button::new("Picture action").show(ui);
});
let env = Env::of(ui);
@@ -71,7 +71,7 @@ fn an_over_picture_bars_members_read_on_its_scrim() {
use craft_ui::testing::style::tokens;
let mut fixture = Fixture::new(|ui| {
Bar::new("Picture tools", BarKind::Tool).look(BarLook::OverPicture).show(ui, |ui, _| {
Bar::new("Picture tools", BarKind::Tool).over_picture().show(ui, |ui, _| {
IconButton::new(IconId::new("chevron_left")).label("Previous").show(ui);
ToggleButton::new("Pen", Bind::given(false)).icon(IconId::new("pencil")).icon_only().show(ui);
ToggleButton::new("Black", Bind::given(false)).show(ui);