From bc884c71b1bc55a93571afc045efda2971fb87db Mon Sep 17 00:00:00 2001 From: Zerthox Date: Mon, 5 Aug 2024 14:15:30 +0200 Subject: [PATCH] Add more debug info --- src/elements/bar.rs | 8 +++++++- src/elements/common.rs | 16 +++++++++------- src/elements/element.rs | 11 +++++++++-- src/elements/element_type.rs | 14 +++++++++++++- src/elements/group.rs | 8 +++++++- src/elements/icon.rs | 8 +++++++- src/elements/icon_element.rs | 8 +++++++- src/elements/list.rs | 12 +++++++++++- src/elements/list_icon.rs | 20 +++++++++++++------- src/elements/pack.rs | 24 ++++++++++++++++-------- src/elements/text.rs | 9 ++++++++- src/traits.rs | 6 ++++++ src/tree/load.rs | 2 +- 13 files changed, 114 insertions(+), 32 deletions(-) diff --git a/src/elements/bar.rs b/src/elements/bar.rs index 3589631..59f80ff 100644 --- a/src/elements/bar.rs +++ b/src/elements/bar.rs @@ -9,7 +9,7 @@ use crate::{ enum_combo, helper, helper_slider, input_color_alpha, input_float_with_format, input_percent, input_size, input_u32, slider_percent, Rect, }, - traits::{Render, RenderOptions}, + traits::{Render, RenderDebug, RenderOptions}, tree::TreeLeaf, }; use nexus::imgui::{ComboBoxFlags, InputTextFlags, Ui}; @@ -215,6 +215,12 @@ impl RenderOptions for Bar { } } +impl RenderDebug for Bar { + fn render_debug(&mut self, ui: &Ui) { + ui.text(format!("Progress factor: {}", self.progress_factor)); + } +} + impl Default for Bar { fn default() -> Self { Self { diff --git a/src/elements/common.rs b/src/elements/common.rs index 9e5a162..c0a3f25 100644 --- a/src/elements/common.rs +++ b/src/elements/common.rs @@ -8,7 +8,7 @@ use crate::{ render_util::{ helper_slider, input_pos, push_alpha_change, slider_percent, EnumStaticVariants, Rect, }, - traits::RenderOptions, + traits::{RenderDebug, RenderOptions}, trigger::ProgressTrigger, }; use nexus::imgui::{Condition, MenuItem, MouseButton, StyleVar, Ui, Window}; @@ -205,12 +205,6 @@ impl Common { } } } - - pub fn render_debug(&mut self, ui: &Ui) { - ui.text("Id:"); - ui.same_line(); - ui.text_disabled(self.id_string()); - } } impl RenderOptions for Common { @@ -230,6 +224,14 @@ impl RenderOptions for Common { } } +impl RenderDebug for Common { + fn render_debug(&mut self, ui: &Ui) { + ui.text("Id:"); + ui.same_line(); + ui.text(self.id_string()); + } +} + impl Default for Common { fn default() -> Self { Self { diff --git a/src/elements/element.rs b/src/elements/element.rs index a80e3ee..53e7581 100644 --- a/src/elements/element.rs +++ b/src/elements/element.rs @@ -7,7 +7,7 @@ use crate::{ render_util::{ delete_confirm_modal, item_context_menu, style_disabled_if, tree_select_empty, Rect, }, - traits::{Render, RenderOptions}, + traits::{Render, RenderDebug, RenderOptions}, tree::{Loader, TreeNode, VisitMut}, trigger::{FilterTrigger, Trigger}, }; @@ -180,12 +180,19 @@ impl Element { } if let Some(_token) = ui.tab_item("?") { - self.common.render_debug(ui); + self.render_debug(ui) } } } } +impl RenderDebug for Element { + fn render_debug(&mut self, ui: &Ui) { + self.common.render_debug(ui); + self.kind.render_debug(ui); + } +} + impl TreeNode for Element { fn children(&mut self) -> Option<&mut Vec> { self.kind.children() diff --git a/src/elements/element_type.rs b/src/elements/element_type.rs index dc37bec..9608fd8 100644 --- a/src/elements/element_type.rs +++ b/src/elements/element_type.rs @@ -3,7 +3,7 @@ use crate::{ bounds::Bounds, context::{Context, EditState}, render_util::{impl_static_variants, Rect}, - traits::{Render, RenderOptions}, + traits::{Render, RenderDebug, RenderOptions}, tree::TreeNode, }; use nexus::imgui::Ui; @@ -86,6 +86,18 @@ impl RenderOptions for ElementType { } } +impl RenderDebug for ElementType { + fn render_debug(&mut self, ui: &Ui) { + match self { + Self::Group(group) => group.render_debug(ui), + Self::Icon(icon) => icon.render_debug(ui), + Self::IconList(list) => list.render_debug(ui), + Self::Text(text) => text.render_debug(ui), + Self::Bar(bar) => bar.render_debug(ui), + } + } +} + impl Default for ElementType { fn default() -> Self { Self::Icon(IconElement::default()) diff --git a/src/elements/group.rs b/src/elements/group.rs index bc80dde..48024bc 100644 --- a/src/elements/group.rs +++ b/src/elements/group.rs @@ -3,7 +3,7 @@ use crate::{ bounds::Bounds, context::{Context, EditState}, render_util::Rect, - traits::{Render, RenderOptions}, + traits::{Render, RenderDebug, RenderOptions}, tree::TreeNode, }; use nexus::imgui::Ui; @@ -38,3 +38,9 @@ impl Bounds for Group { impl RenderOptions for Group { fn render_options(&mut self, _ui: &Ui, _state: &mut EditState) {} } + +impl RenderDebug for Group { + fn render_debug(&mut self, ui: &Ui) { + ui.text(format!("Members: {}", self.members.len())); + } +} diff --git a/src/elements/icon.rs b/src/elements/icon.rs index 07f3988..fb2c117 100644 --- a/src/elements/icon.rs +++ b/src/elements/icon.rs @@ -5,7 +5,7 @@ use crate::{ context::{Context, EditState}, render_util::{draw_spinner_bg, draw_text_bg, input_color_alpha, Rect}, settings::icon::{DurationBarSettings, DurationTextSettings, StackTextSettings}, - traits::RenderOptions, + traits::{RenderDebug, RenderOptions}, trigger::ProgressActive, }; use nexus::imgui::Ui; @@ -178,6 +178,12 @@ impl RenderOptions for Icon { } } +impl RenderDebug for Icon { + fn render_debug(&mut self, ui: &Ui) { + ui.text(format!("Texture: {:x?}", self.source.get_texture())); + } +} + impl Default for Icon { fn default() -> Self { Self { diff --git a/src/elements/icon_element.rs b/src/elements/icon_element.rs index 98fb0dc..7d08936 100644 --- a/src/elements/icon_element.rs +++ b/src/elements/icon_element.rs @@ -3,7 +3,7 @@ use crate::{ bounds::Bounds, context::{Context, EditState}, render_util::{input_size, Rect}, - traits::{Render, RenderOptions}, + traits::{Render, RenderDebug, RenderOptions}, tree::TreeLeaf, }; use nexus::imgui::Ui; @@ -40,6 +40,12 @@ impl RenderOptions for IconElement { } } +impl RenderDebug for IconElement { + fn render_debug(&mut self, ui: &Ui) { + self.icon.render_debug(ui) + } +} + impl Default for IconElement { fn default() -> Self { Self { diff --git a/src/elements/list.rs b/src/elements/list.rs index d0687c7..f019fef 100644 --- a/src/elements/list.rs +++ b/src/elements/list.rs @@ -9,7 +9,7 @@ use crate::{ collapsing_header_same_line_end, delete_confirm_modal, enum_combo, input_float_with_format, input_size, item_context_menu, style_disabled_if, Rect, }, - traits::{Render, RenderOptions}, + traits::{Render, RenderDebug, RenderOptions}, tree::TreeLeaf, }; use nexus::imgui::{ @@ -180,6 +180,16 @@ impl RenderOptions for IconList { } } +impl RenderDebug for IconList { + fn render_debug(&mut self, ui: &Ui) { + ui.text(format!("Icons: {}", self.icons.len())); + for icon in &mut self.icons { + ui.spacing(); + icon.render_debug(ui); + } + } +} + impl Default for IconList { fn default() -> Self { Self { diff --git a/src/elements/list_icon.rs b/src/elements/list_icon.rs index 2f8bc15..4c9a3a8 100644 --- a/src/elements/list_icon.rs +++ b/src/elements/list_icon.rs @@ -2,7 +2,7 @@ use super::{Common, Element, ElementType, Icon, IconElement, RenderState}; use crate::{ context::{Context, EditState}, render_util::Rect, - traits::RenderOptions, + traits::{RenderDebug, RenderOptions}, trigger::ProgressTrigger, }; use nexus::imgui::Ui; @@ -20,7 +20,7 @@ pub struct ListIcon { pub trigger: ProgressTrigger, #[serde(flatten)] - pub inner: Icon, + pub icon: Icon, } impl ListIcon { @@ -31,7 +31,7 @@ impl ListIcon { } pub fn render(&mut self, ui: &Ui, ctx: &Context, state: &RenderState, size: [f32; 2]) { - self.inner + self.icon .render(ui, ctx, state, self.trigger.active(), size) } @@ -48,7 +48,7 @@ impl ListIcon { ..Common::default() }, kind: ElementType::Icon(IconElement { - icon: self.inner, + icon: self.icon, size, }), ..Element::default() @@ -60,7 +60,7 @@ impl ListIcon { enabled: common.enabled, name: common.name, trigger: common.trigger, - inner: element.icon, + icon: element.icon, } } } @@ -76,7 +76,13 @@ impl RenderOptions for ListIcon { ui.spacing(); - self.inner.render_options(ui, state); + self.icon.render_options(ui, state); + } +} + +impl RenderDebug for ListIcon { + fn render_debug(&mut self, ui: &Ui) { + self.icon.render_debug(ui) } } @@ -86,7 +92,7 @@ impl Default for ListIcon { enabled: true, name: "Unnamed".into(), trigger: ProgressTrigger::effect(), - inner: Icon::default(), + icon: Icon::default(), } } } diff --git a/src/elements/pack.rs b/src/elements/pack.rs index 18bd38e..8d07100 100644 --- a/src/elements/pack.rs +++ b/src/elements/pack.rs @@ -8,7 +8,7 @@ use crate::{ tree_select_empty, }, schema::Schema, - traits::RenderOptions, + traits::{RenderDebug, RenderOptions}, tree::{Loader, TreeNode, VisitMut}, }; use nexus::imgui::{ComboBoxFlags, MenuItem, Ui}; @@ -155,18 +155,26 @@ impl Pack { } } if let Some(_token) = ui.tab_item("?") { - self.common.render_debug(ui); - - ui.text("File:"); - if let Some(file) = self.file.file_name().and_then(|file| file.to_str()) { - ui.same_line(); - ui.text_disabled(file); - } + self.render_debug(ui); } } } } +impl RenderDebug for Pack { + fn render_debug(&mut self, ui: &Ui) { + self.common.render_debug(ui); + + ui.text("File:"); + if let Some(file) = self.file.file_name().and_then(|file| file.to_str()) { + ui.same_line(); + ui.text(file); + } + + ui.text(format!("Children: {}", self.elements.len())); + } +} + impl TreeNode for Pack { fn children(&mut self) -> Option<&mut Vec> { Some(&mut self.elements) diff --git a/src/elements/text.rs b/src/elements/text.rs index 5f59644..81eddb6 100644 --- a/src/elements/text.rs +++ b/src/elements/text.rs @@ -4,7 +4,7 @@ use crate::{ component_wise::ComponentWise, context::{Context, ContextUpdate, EditState}, render_util::{draw_text_bg, font_select, helper, input_text_multi_with_menu, Font, Rect}, - traits::{Render, RenderOptions}, + traits::{Render, RenderDebug, RenderOptions}, tree::TreeLeaf, trigger::ProgressActive, }; @@ -174,6 +174,13 @@ impl RenderOptions for Text { } } +impl RenderDebug for Text { + fn render_debug(&mut self, ui: &Ui) { + ui.text(format!("Font: {:x?}", self.loaded_font)); + ui.text(format!("Frequent: {}", self.frequent)); + } +} + impl Default for Text { fn default() -> Self { Self { diff --git a/src/traits.rs b/src/traits.rs index 99b7ea4..6ec2f40 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -20,6 +20,12 @@ pub trait RenderOptions { fn render_tabs(&mut self, _ui: &Ui, _state: &mut EditState) {} } +/// Render debug UI. +pub trait RenderDebug { + /// Renders debug info for the type. + fn render_debug(&mut self, ui: &Ui); +} + /// Associated color. pub trait Colored { /// Returns the color. diff --git a/src/tree/load.rs b/src/tree/load.rs index aadeb67..2debd66 100644 --- a/src/tree/load.rs +++ b/src/tree/load.rs @@ -10,7 +10,7 @@ pub struct Loader; impl VisitMut for Loader { fn visit_icon_list(&mut self, el: &mut IconList) { for icon in &mut el.icons { - icon.inner.load(); + icon.icon.load(); } }