layers filter bar: ObjectsSearch, a root style value; under ObjectsSearch::Fill the Objects filter's search field fills the bar's row and the Filter button stands at its end edge. ObjectsSearch::Natural, the default, keeps the field at its own width, so no other app changes. LayerFilterBar story under Fill; trial

This commit is contained in:
bflatastic
2026-11-25 10:24:16 +07:00
parent e70ddf25cf
commit bf12e584a2
3 changed files with 59 additions and 5 deletions
+23 -4
View File
@@ -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::<LayerFilterWords>();
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>() == 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::<FindName>().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);
}
+16 -1
View File
@@ -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),
)
}
+20
View File
@@ -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");
}