mirror of
https://github.com/FyroxEngine/Fyrox.git
synced 2026-10-11 22:50:08 +00:00
fixed filtering in inspector
This commit is contained in:
@@ -41,7 +41,7 @@ use crate::{
|
||||
stack_panel::StackPanelBuilder,
|
||||
widget::{WidgetBuilder, WidgetMessage},
|
||||
window::{WindowBuilder, WindowMessage, WindowTitle},
|
||||
HorizontalAlignment, Orientation, Thickness, UiNode, UserInterface,
|
||||
HorizontalAlignment, Orientation, Thickness, UserInterface,
|
||||
},
|
||||
},
|
||||
load_image,
|
||||
@@ -49,7 +49,6 @@ use crate::{
|
||||
settings::Settings,
|
||||
Editor,
|
||||
};
|
||||
use fyrox::core::ok_or_return;
|
||||
use fyrox::core::uuid::{uuid, Uuid};
|
||||
use fyrox::engine::GraphicsContext;
|
||||
use fyrox::gui::button::Button;
|
||||
@@ -61,7 +60,6 @@ use fyrox::gui::stack_panel::StackPanel;
|
||||
use fyrox::gui::text_box::EmptyTextPlaceholder;
|
||||
use fyrox::gui::widget::UserData;
|
||||
use fyrox::gui::window::{Window, WindowAlignment};
|
||||
use rust_fuzzy_search::fuzzy_compare;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
|
||||
@@ -718,7 +718,21 @@ crate::define_widget_deref!(Inspector);
|
||||
|
||||
impl Inspector {
|
||||
pub fn apply_filter(&self, filter_text: &str, ui: &UserInterface) {
|
||||
fn apply_recursive(
|
||||
fn make_visible_recursive(inspector: Handle<UiNode>, ui: &UserInterface) {
|
||||
let inspector = ok_or_return!(ui.try_get_of_type::<Inspector>(inspector));
|
||||
for entry in inspector.context.entries.iter() {
|
||||
let sub_inspector = ui.find_handle(entry.property_editor, &mut |node| {
|
||||
node.is_or_has_field::<Inspector>()
|
||||
});
|
||||
if sub_inspector.is_some() {
|
||||
make_visible_recursive(sub_inspector, ui);
|
||||
}
|
||||
|
||||
ui.send(entry.property_container, WidgetMessage::Visibility(true));
|
||||
}
|
||||
}
|
||||
|
||||
fn filter_recursive(
|
||||
filter_text: &str,
|
||||
inspector: Handle<UiNode>,
|
||||
ui: &UserInterface,
|
||||
@@ -727,32 +741,35 @@ impl Inspector {
|
||||
|
||||
let mut is_any_match = false;
|
||||
for entry in inspector.context.entries.iter() {
|
||||
// First look at any inner inspectors, because they could also contain properties
|
||||
// matching search criteria.
|
||||
let mut inner_match = false;
|
||||
let sub_inspector = ui.find_handle(entry.property_editor, &mut |node| {
|
||||
node.is_or_has_field::<Inspector>()
|
||||
});
|
||||
if sub_inspector.is_some() {
|
||||
inner_match |= apply_recursive(filter_text, sub_inspector, ui);
|
||||
}
|
||||
|
||||
let display_name = entry.property_display_name.to_lowercase();
|
||||
inner_match |= display_name.contains(filter_text)
|
||||
let mut is_visible = filter_text.is_empty()
|
||||
|| display_name.contains(filter_text)
|
||||
|| rust_fuzzy_search::fuzzy_compare(filter_text, display_name.as_str()) >= 0.5;
|
||||
|
||||
ui.send(
|
||||
entry.property_container,
|
||||
WidgetMessage::Visibility(inner_match),
|
||||
);
|
||||
if !is_visible {
|
||||
let sub_inspector = ui.find_handle(entry.property_editor, &mut |node| {
|
||||
node.is_or_has_field::<Inspector>()
|
||||
});
|
||||
if sub_inspector.is_some() {
|
||||
is_visible |= filter_recursive(filter_text, sub_inspector, ui);
|
||||
}
|
||||
}
|
||||
|
||||
is_any_match |= inner_match;
|
||||
if !is_visible {
|
||||
ui.send(
|
||||
entry.property_container,
|
||||
WidgetMessage::Visibility(is_visible),
|
||||
);
|
||||
}
|
||||
|
||||
is_any_match |= is_visible;
|
||||
}
|
||||
|
||||
is_any_match
|
||||
}
|
||||
|
||||
apply_recursive(filter_text, self.handle, ui);
|
||||
make_visible_recursive(self.handle, ui);
|
||||
filter_recursive(filter_text, self.handle, ui);
|
||||
}
|
||||
|
||||
pub fn handle_context_menu_message(
|
||||
|
||||
Reference in New Issue
Block a user