Skip to content

Commit

Permalink
Add more debug info
Browse files Browse the repository at this point in the history
  • Loading branch information
Zerthox committed Aug 5, 2024
1 parent 81f582f commit bc884c7
Show file tree
Hide file tree
Showing 13 changed files with 114 additions and 32 deletions.
8 changes: 7 additions & 1 deletion src/elements/bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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 {
Expand Down
16 changes: 9 additions & 7 deletions src/elements/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
11 changes: 9 additions & 2 deletions src/elements/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand Down Expand Up @@ -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<Element>> {
self.kind.children()
Expand Down
14 changes: 13 additions & 1 deletion src/elements/element_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())
Expand Down
8 changes: 7 additions & 1 deletion src/elements/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()));
}
}
8 changes: 7 additions & 1 deletion src/elements/icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion src/elements/icon_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 11 additions & 1 deletion src/elements/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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 {
Expand Down
20 changes: 13 additions & 7 deletions src/elements/list_icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,7 +20,7 @@ pub struct ListIcon {
pub trigger: ProgressTrigger,

#[serde(flatten)]
pub inner: Icon,
pub icon: Icon,
}

impl ListIcon {
Expand All @@ -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)
}

Expand All @@ -48,7 +48,7 @@ impl ListIcon {
..Common::default()
},
kind: ElementType::Icon(IconElement {
icon: self.inner,
icon: self.icon,
size,
}),
..Element::default()
Expand All @@ -60,7 +60,7 @@ impl ListIcon {
enabled: common.enabled,
name: common.name,
trigger: common.trigger,
inner: element.icon,
icon: element.icon,
}
}
}
Expand All @@ -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)
}
}

Expand All @@ -86,7 +92,7 @@ impl Default for ListIcon {
enabled: true,
name: "Unnamed".into(),
trigger: ProgressTrigger::effect(),
inner: Icon::default(),
icon: Icon::default(),
}
}
}
24 changes: 16 additions & 8 deletions src/elements/pack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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<Element>> {
Some(&mut self.elements)
Expand Down
9 changes: 8 additions & 1 deletion src/elements/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ pub trait RenderOptions<T = ()> {
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.
Expand Down
2 changes: 1 addition & 1 deletion src/tree/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down

0 comments on commit bc884c7

Please sign in to comment.