From 625d176516d1d8005493516c49834f4343f3e650 Mon Sep 17 00:00:00 2001 From: Paris DOUADY Date: Wed, 14 Feb 2024 14:55:56 +0100 Subject: [PATCH] downgrade inspect to debug_inspect --- .../src/inspect_macro/args/mod.rs | 2 +- egui-inspect-derive/src/inspect_macro/mod.rs | 2 +- egui-inspect/src/impls/mod.rs | 2 +- .../inspect_debug.rs => debug_inspect.rs} | 38 +++++++++++++++++-- native_app/src/gui/hud.rs | 4 +- native_app/src/gui/inspect/mod.rs | 35 ----------------- native_app/src/gui/mod.rs | 2 +- 7 files changed, 40 insertions(+), 45 deletions(-) rename native_app/src/gui/{inspect/inspect_debug.rs => debug_inspect.rs} (83%) delete mode 100644 native_app/src/gui/inspect/mod.rs diff --git a/egui-inspect-derive/src/inspect_macro/args/mod.rs b/egui-inspect-derive/src/inspect_macro/args/mod.rs index 8805dee02..152baa032 100644 --- a/egui-inspect-derive/src/inspect_macro/args/mod.rs +++ b/egui-inspect-derive/src/inspect_macro/args/mod.rs @@ -21,7 +21,7 @@ pub struct InspectStructArgs { pub ident: syn::Ident, } -// We support multiple distinct inspect annotations (i.e. inspect_slider, inspect_text) +// We support multiple distinct debug_inspect annotations (i.e. inspect_slider, inspect_text) // Each distinct type will have a struct for capturing the metadata. These metadata structs // must implement this trait pub trait InspectFieldArgs { diff --git a/egui-inspect-derive/src/inspect_macro/mod.rs b/egui-inspect-derive/src/inspect_macro/mod.rs index 7fc677ef8..1b871785f 100644 --- a/egui-inspect-derive/src/inspect_macro/mod.rs +++ b/egui-inspect-derive/src/inspect_macro/mod.rs @@ -113,7 +113,7 @@ fn handle_inspect_type< ) { if parsed_field.is_some() { panic!( - "Too many inspect attributes on a single member {:?}", + "Too many debug_inspect attributes on a single member {:?}", f.ident ); } diff --git a/egui-inspect/src/impls/mod.rs b/egui-inspect/src/impls/mod.rs index ae8d21f84..1a9aaf184 100644 --- a/egui-inspect/src/impls/mod.rs +++ b/egui-inspect/src/impls/mod.rs @@ -26,7 +26,7 @@ pub use option::OptionDefault; /// So, not all elements will necessarily be used/respected. Use the non-default traits for typesafe /// changes. /// -/// Marking a struct element with something like `#[inspect(min_value = 5.0, max_value = 53.0)]` +/// Marking a struct element with something like `#[debug_inspect(min_value = 5.0, max_value = 53.0)]` /// will make the widget for that member default to those values. #[derive(Clone, Default, Debug)] pub struct InspectArgs { diff --git a/native_app/src/gui/inspect/inspect_debug.rs b/native_app/src/gui/debug_inspect.rs similarity index 83% rename from native_app/src/gui/inspect/inspect_debug.rs rename to native_app/src/gui/debug_inspect.rs index ae9da6b03..4647f1b1a 100644 --- a/native_app/src/gui/inspect/inspect_debug.rs +++ b/native_app/src/gui/debug_inspect.rs @@ -1,6 +1,6 @@ -use crate::newgui::follow::FollowEntity; -use crate::uiworld::UiWorld; use egui::Ui; +use egui::{Context, Window}; + use egui_inspect::{Inspect, InspectArgs}; use simulation::economy::Market; use simulation::transportation::Location; @@ -9,8 +9,38 @@ use simulation::{ WagonEnt, }; +use crate::gui::windows::debug::DebugState; +use crate::newgui::follow::FollowEntity; +use crate::newgui::InspectedEntity; +use crate::uiworld::UiWorld; + +pub fn debug_inspector(ui: &Context, uiworld: &UiWorld, sim: &Simulation) { + profiling::scope!("hud::inspector"); + let e = unwrap_or!(uiworld.read::().e, return); + + let force_debug_inspect = uiworld.read::().debug_inspector; + + let mut is_open = true; + if force_debug_inspect { + Window::new("Inspect") + .default_size([400.0, 500.0]) + .default_pos([30.0, 160.0]) + .resizable(true) + .open(&mut is_open) + .show(ui, |ui| { + let mut ins = InspectRenderer { entity: e }; + ins.render(uiworld, sim, ui); + uiworld.write::().e = Some(ins.entity); + }); + } + + if !is_open { + uiworld.write::().e = None; + } +} + /// Inspect window -/// Allows to inspect an entity +/// Allows to debug_inspect an entity pub struct InspectRenderer { pub entity: AnyEntity, } @@ -55,7 +85,7 @@ impl InspectRenderer { for (hid, h) in sim.world().humans.iter() { if h.location == Location::Vehicle(id) && ui - .small_button(&*format!("inspect inside vehicle: {hid:?}")) + .small_button(&*format!("debug_inspect inside vehicle: {hid:?}")) .clicked() { self.entity = hid.into(); diff --git a/native_app/src/gui/hud.rs b/native_app/src/gui/hud.rs index 481aea5f3..278dce032 100644 --- a/native_app/src/gui/hud.rs +++ b/native_app/src/gui/hud.rs @@ -5,7 +5,7 @@ use simulation::economy::Government; use simulation::Simulation; use crate::gui::chat::chat; -use crate::gui::inspect::inspector; +use crate::gui::debug_inspect::debug_inspector; use crate::newgui::{ErrorTooltip, GuiState, PotentialCommands}; use crate::uiworld::UiWorld; @@ -16,7 +16,7 @@ pub fn render_oldgui(ui: &Context, uiworld: &UiWorld, sim: &Simulation) { return; } - inspector(ui, uiworld, sim); + debug_inspector(ui, uiworld, sim); chat(ui, uiworld, sim); diff --git a/native_app/src/gui/inspect/mod.rs b/native_app/src/gui/inspect/mod.rs deleted file mode 100644 index 148619c33..000000000 --- a/native_app/src/gui/inspect/mod.rs +++ /dev/null @@ -1,35 +0,0 @@ -use egui::{Context, Window}; - -use inspect_debug::InspectRenderer; -use simulation::Simulation; - -use crate::gui::windows::debug::DebugState; -use crate::newgui::InspectedEntity; -use crate::uiworld::UiWorld; - -mod inspect_debug; - -pub fn inspector(ui: &Context, uiworld: &UiWorld, sim: &Simulation) { - profiling::scope!("hud::inspector"); - let e = unwrap_or!(uiworld.read::().e, return); - - let force_debug_inspect = uiworld.read::().debug_inspector; - - let mut is_open = true; - if force_debug_inspect { - Window::new("Inspect") - .default_size([400.0, 500.0]) - .default_pos([30.0, 160.0]) - .resizable(true) - .open(&mut is_open) - .show(ui, |ui| { - let mut ins = InspectRenderer { entity: e }; - ins.render(uiworld, sim, ui); - uiworld.write::().e = Some(ins.entity); - }); - } - - if !is_open { - uiworld.write::().e = None; - } -} diff --git a/native_app/src/gui/mod.rs b/native_app/src/gui/mod.rs index b0661a425..acbe92128 100644 --- a/native_app/src/gui/mod.rs +++ b/native_app/src/gui/mod.rs @@ -1,6 +1,6 @@ pub mod chat; +pub mod debug_inspect; pub mod hud; -pub mod inspect; pub mod windows; pub use hud::*;