From 0bbfded09b623b2267f9dd9e4a5b2ba50da1d4c2 Mon Sep 17 00:00:00 2001 From: Julia Naomi Date: Sun, 26 Nov 2023 16:14:48 -0600 Subject: [PATCH 1/3] Store components state for each entity --- src/editor/ui/inspector/mod.rs | 46 +++++++++++++++++++++------------- src/editor/ui/tools/gizmo.rs | 12 ++++----- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/src/editor/ui/inspector/mod.rs b/src/editor/ui/inspector/mod.rs index 404919cd..6dfbd080 100644 --- a/src/editor/ui/inspector/mod.rs +++ b/src/editor/ui/inspector/mod.rs @@ -8,6 +8,7 @@ use bevy::{ prelude::*, ptr::PtrMut, reflect::ReflectFromPtr, + utils::HashMap, }; use bevy_egui::*; @@ -55,11 +56,13 @@ impl Plugin for SpaceInspectorPlugin { } #[derive(Resource, Default)] -pub struct InspectorTab {} +pub struct InspectorTab { + open_components: HashMap, +} impl EditorTab for InspectorTab { fn ui(&mut self, ui: &mut egui::Ui, _: &mut Commands, world: &mut World) { - inspect(ui, world); + inspect(ui, world, &mut self.open_components); } fn title(&self) -> egui::WidgetText { @@ -126,7 +129,7 @@ fn execute_inspect_command( } /// System to show inspector panel -pub fn inspect(ui: &mut egui::Ui, world: &mut World) { +pub fn inspect(ui: &mut egui::Ui, world: &mut World, open_components: &mut HashMap) { let selected_entity = world .query_filtered::>() .get_single(world); @@ -207,21 +210,28 @@ pub fn inspect(ui: &mut egui::Ui, world: &mut World) { if !editor_registry.silent.contains(®istration.type_id()) { ui.push_id(format!("{:?}-{}", &e.id(), &name), |ui| { - ui.collapsing(name, |ui| { - ui.push_id( - format!("content-{:?}-{}", &e.id(), &name), - |ui| { - if env.ui_for_reflect_with_options( - value, - ui, - ui.id(), - &(), - ) { - set_changed(); - } - }, - ); - }); + let header = egui::CollapsingHeader::new(name) + .default_open(*open_components.get(name).unwrap_or(&false)) + .show(ui, |ui| { + ui.push_id( + format!("content-{:?}-{}", &e.id(), &name), + |ui| { + if env.ui_for_reflect_with_options( + value, + ui, + ui.id(), + &(), + ) { + set_changed(); + } + }, + ); + }); + if header.header_response.clicked() { + let open_name = + open_components.entry(name.clone()).or_default(); + *open_name = header.fully_open(); + } }); ui.push_id( diff --git a/src/editor/ui/tools/gizmo.rs b/src/editor/ui/tools/gizmo.rs index 00b35573..5e08a87f 100644 --- a/src/editor/ui/tools/gizmo.rs +++ b/src/editor/ui/tools/gizmo.rs @@ -34,12 +34,12 @@ pub enum GizmoHotkey { impl Hotkey for GizmoHotkey { fn name<'a>(&self) -> String { match self { - GizmoHotkey::Translate => "Translate entity".to_string(), - GizmoHotkey::Rotate => "Rotate entity".to_string(), - GizmoHotkey::Scale => "Scale entity".to_string(), - GizmoHotkey::Delete => "Delete entity".to_string(), - GizmoHotkey::Multiple => "Change multiple entities".to_string(), - GizmoHotkey::Clone => "Clone entity".to_string(), + Self::Translate => "Translate entity".to_string(), + Self::Rotate => "Rotate entity".to_string(), + Self::Scale => "Scale entity".to_string(), + Self::Delete => "Delete entity".to_string(), + Self::Multiple => "Change multiple entities".to_string(), + Self::Clone => "Clone entity".to_string(), } } } From c27a3f126754b319eb6ec3e720681f482d7314ff Mon Sep 17 00:00:00 2001 From: "a.yamaev" Date: Mon, 27 Nov 2023 12:08:19 +0300 Subject: [PATCH 2/3] Fix default open setup from header props --- src/editor/ui/inspector/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/editor/ui/inspector/mod.rs b/src/editor/ui/inspector/mod.rs index 6dfbd080..bb653db3 100644 --- a/src/editor/ui/inspector/mod.rs +++ b/src/editor/ui/inspector/mod.rs @@ -230,7 +230,8 @@ pub fn inspect(ui: &mut egui::Ui, world: &mut World, open_components: &mut HashM if header.header_response.clicked() { let open_name = open_components.entry(name.clone()).or_default(); - *open_name = header.fully_open(); + //At click header not opened simultaneously so its need to check percent of opened + *open_name = header.openness < 0.5; } }); From 4abd4981a90921f1b7210ae551d19e71fe929109 Mon Sep 17 00:00:00 2001 From: "a.yamaev" Date: Mon, 27 Nov 2023 12:09:58 +0300 Subject: [PATCH 3/3] cargo fmt --- src/editor/ui/inspector/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/editor/ui/inspector/mod.rs b/src/editor/ui/inspector/mod.rs index bb653db3..f9d94129 100644 --- a/src/editor/ui/inspector/mod.rs +++ b/src/editor/ui/inspector/mod.rs @@ -231,7 +231,7 @@ pub fn inspect(ui: &mut egui::Ui, world: &mut World, open_components: &mut HashM let open_name = open_components.entry(name.clone()).or_default(); //At click header not opened simultaneously so its need to check percent of opened - *open_name = header.openness < 0.5; + *open_name = header.openness < 0.5; } });