Skip to content

Commit 3a3e9d2

Browse files
committed
Inspector component search/filter with clear button
1 parent b7b104a commit 3a3e9d2

3 files changed

Lines changed: 682 additions & 0 deletions

File tree

crates/renzora_inspector/src/lib.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,36 @@ impl EditorPanel for InspectorPanel {
117117
}
118118
}
119119

120+
// Component search/filter bar
121+
ui.add_space(4.0);
122+
ui.horizontal(|ui| {
123+
ui.add_space(4.0);
124+
let has_filter = !state.component_filter.is_empty();
125+
let clear_width = if has_filter { 20.0 } else { 0.0 };
126+
let search_width = ui.available_width() - clear_width - 12.0;
127+
ui.add(
128+
egui::TextEdit::singleline(&mut state.component_filter)
129+
.desired_width(search_width)
130+
.hint_text(format!("{} Filter components...", regular::MAGNIFYING_GLASS)),
131+
);
132+
if has_filter
133+
&& ui
134+
.add(
135+
egui::Button::new(
136+
RichText::new(regular::X)
137+
.size(11.0)
138+
.color(theme.text.muted.to_color32()),
139+
)
140+
.frame(false),
141+
)
142+
.clicked()
143+
{
144+
state.component_filter.clear();
145+
}
146+
});
147+
148+
let filter = state.component_filter.to_lowercase();
149+
120150
// Render each component section
121151
egui::ScrollArea::vertical()
122152
.id_salt("inspector_scroll")
@@ -129,6 +159,12 @@ impl EditorPanel for InspectorPanel {
129159
if !(entry.has_fn)(world, entity) {
130160
continue;
131161
}
162+
if !filter.is_empty()
163+
&& !entry.display_name.to_lowercase().contains(&filter)
164+
&& !entry.category.to_lowercase().contains(&filter)
165+
{
166+
continue;
167+
}
132168
any_shown = true;
133169

134170
if let Some(remove_fn) = entry.remove_fn {

crates/renzora_inspector/src/state.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
pub struct InspectorState {
44
pub show_add_overlay: bool,
55
pub add_search: String,
6+
pub component_filter: String,
67
}

0 commit comments

Comments
 (0)