diff --git a/crates/layers/src/ui/filter/mod.rs b/crates/layers/src/ui/filter/mod.rs index 70a7973ea..d0a46b70b 100644 --- a/crates/layers/src/ui/filter/mod.rs +++ b/crates/layers/src/ui/filter/mod.rs @@ -821,6 +821,19 @@ impl Outcome for LayerFilterOutput { } } +/// How wide the Objects filter's search field stands in the filter bar. An app sets it once at its root +/// (`RootEnv::values`); the default is `Natural`. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, craft_ui::runtime::env::EnvValue, craft_ui::contract::MemoProps)] +#[env(style)] +#[non_exhaustive] +pub enum ObjectsSearch { + /// The field's own width, with the Filter button right after it. + #[default] + Natural, + /// The field fills the row, with the Filter button at the end edge: VectorCraft's Layers panel. + Fill, +} + /// Whether the Objects filter's popover is open: the bar's memory, so it stays open across passes until a /// click outside or Escape closes it. #[derive(Clone, Default)] @@ -859,7 +872,10 @@ impl<'a> LayerFilterBar<'a> { } let words = Env::of(ui).words::(); let mut edit = None; - let row = Row::new().show(ui, |ui, cx| { + // A filling search field needs a row as wide as the bar to fill. + let fill = Env::of(ui).get::() == ObjectsSearch::Fill; + let row = if fill { Row::new().fill_width() } else { Row::new() }; + let row = row.show(ui, |ui, cx| { let select_name = std::mem::replace(&mut cx.memory::().select, focus_name); let Some(Mixed::Same(current)) = filter.reborrow().read(cx) else { return }; let stored = current; @@ -948,9 +964,12 @@ impl<'a> LayerFilterBar<'a> { // The selected layers pick the artboards; Group lists every group. FilterBy::Artboard | FilterBy::Group => {} FilterBy::Objects => { - let typed = TextField::search(words.search_layers.clone(), Bind::given(current.name.clone())) - .placeholder(words.search_all.clone()) - .show(ui); + let mut field = + TextField::search(words.search_layers.clone(), Bind::given(current.name.clone())).placeholder(words.search_all.clone()); + if fill { + field = field.sizing(Sizing::FillWidth); + } + let typed = field.show(ui); if let Some(text) = typed.value() { next.name.clone_from(text); } diff --git a/crates/layers/src/ui/filter/stories.rs b/crates/layers/src/ui/filter/stories.rs index c648621ec..119d72e1b 100644 --- a/crates/layers/src/ui/filter/stories.rs +++ b/crates/layers/src/ui/filter/stories.rs @@ -1,9 +1,10 @@ //! Stories of `LayerFilterBar`: each filter type in one card, with the count of a document's layers it lets through. -use super::{EffectKind, FilterBy, FilterKind, FilterObject, FilterState, LayerAttribute, LayerFilter, LayerFilterBar, SmartKind}; +use super::{EffectKind, FilterBy, FilterKind, FilterObject, FilterState, LayerAttribute, LayerFilter, LayerFilterBar, ObjectsSearch, SmartKind}; use crate::ui::mock::FakeLayers; use crate::ui::tree::LayerTree as _; use craft_theme::LabelColor; +use craft_ui::runtime::env::with_env; use craft_ui::testing::{Drive, Fixture, StoryData, StoryOutput, ValueAt, story}; use egui::Ui; @@ -103,3 +104,17 @@ fn layer_filter_objects(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { ); show(ui, filter, filter_at) } + +/// The Objects filter in an app whose search field fills the bar (`ObjectsSearch::Fill`, VectorCraft's Layers panel): +/// the Filter button at the end edge. +#[story(LayerFilterBar<'static>, covers = [], drive = Drive::Never, group = "Types", title = "Filter by Objects, filling search")] +fn layer_filter_objects_fill(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + let (filter, filter_at) = data.value_at("filter", LayerFilter { by: FilterBy::Objects, ..LayerFilter::default() }); + with_env( + ui, + |overrides| { + overrides.values.set(ObjectsSearch::Fill); + }, + |ui| show(ui, filter, filter_at), + ) +} diff --git a/crates/layers/tests/it/panel_filter.rs b/crates/layers/tests/it/panel_filter.rs index b1df0c8f4..8430e83cf 100644 --- a/crates/layers/tests/it/panel_filter.rs +++ b/crates/layers/tests/it/panel_filter.rs @@ -338,3 +338,23 @@ fn a_filter_the_bar_applies_deselects_what_it_hides() { fixture.idle(2); assert!(selects(&seen).is_empty(), "a layer selected later, while the filter hides it, stays selected"); } + +/// Where the Objects filter's Filter button ends under `search`. +fn filter_button_end(search: craft_layers::ui::filter::ObjectsSearch) -> f32 { + let mut fixture = Fixture::new(move |ui| { + let mut filter = LayerFilter::default(); + filter.by = FilterBy::Objects; + let _ = craft_layers::ui::filter::LayerFilterBar::new(Bind::bound(&mut filter)).filter_types([FilterBy::Objects]).show(ui); + }); + fixture.root_value(search).room(ONE_PANEL).settle(); + fixture.by_label("Filter").expect("the Objects filter shows its Filter button").rect.right() +} + +/// An app whose Objects search fills the bar (`ObjectsSearch::Fill`, VectorCraft's Layers panel) gets its Filter +/// button further toward the end edge than the field's own width leaves it. +#[trial] +fn a_filling_objects_search_puts_the_filter_button_at_the_end() { + use craft_layers::ui::filter::ObjectsSearch; + let (natural, fill) = (filter_button_end(ObjectsSearch::Natural), filter_button_end(ObjectsSearch::Fill)); + assert!(fill > natural, "the Filter button ends at {fill} under Fill, {natural} under Natural"); +}