wgui: pretty-print tree
This commit is contained in:
@@ -26,4 +26,12 @@ impl WidgetObj for WidgetDiv {
|
||||
fn set_id(&mut self, id: WidgetID) {
|
||||
self.id = id;
|
||||
}
|
||||
|
||||
fn get_type(&self) -> super::WidgetType {
|
||||
super::WidgetType::Div
|
||||
}
|
||||
|
||||
fn debug_print(&self) -> String {
|
||||
String::default()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ use crate::{
|
||||
|
||||
use super::{WidgetObj, WidgetState};
|
||||
|
||||
#[derive(Default)]
|
||||
#[derive(Debug, Default)]
|
||||
pub struct WidgetLabelParams {
|
||||
pub content: Translation,
|
||||
pub style: TextStyle,
|
||||
@@ -160,4 +160,18 @@ impl WidgetObj for WidgetLabel {
|
||||
fn set_id(&mut self, id: WidgetID) {
|
||||
self.id = id;
|
||||
}
|
||||
|
||||
fn get_type(&self) -> super::WidgetType {
|
||||
super::WidgetType::Label
|
||||
}
|
||||
|
||||
fn debug_print(&self) -> String {
|
||||
let color = if let Some(color) = self.params.style.color {
|
||||
format!("[color: {}]", color.debug_ansi_block())
|
||||
} else {
|
||||
String::default()
|
||||
};
|
||||
|
||||
format!("[text: \"{}\"]{}", self.params.content.text, color)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,10 +115,30 @@ pub struct DrawParams<'a> {
|
||||
pub taffy_layout: &'a taffy::Layout,
|
||||
}
|
||||
|
||||
pub enum WidgetType {
|
||||
Div,
|
||||
Label,
|
||||
Sprite,
|
||||
Rectangle,
|
||||
}
|
||||
|
||||
impl WidgetType {
|
||||
pub const fn as_str(&self) -> &str {
|
||||
match self {
|
||||
WidgetType::Div => "div",
|
||||
WidgetType::Label => "label",
|
||||
WidgetType::Sprite => "sprite",
|
||||
WidgetType::Rectangle => "rectangle",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait WidgetObj: AnyTrait {
|
||||
// every widget stores their of id for convenience reasons
|
||||
fn get_id(&self) -> WidgetID;
|
||||
fn set_id(&mut self, id: WidgetID); // always set at insertion
|
||||
fn get_type(&self) -> WidgetType;
|
||||
fn debug_print(&self) -> String;
|
||||
|
||||
fn draw(&mut self, state: &mut DrawState, params: &DrawParams);
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ use crate::{
|
||||
|
||||
use super::{WidgetObj, WidgetState};
|
||||
|
||||
#[derive(Default)]
|
||||
#[derive(Debug, Default)]
|
||||
pub struct WidgetRectangleParams {
|
||||
pub color: drawing::Color,
|
||||
pub color2: drawing::Color,
|
||||
@@ -66,4 +66,17 @@ impl WidgetObj for WidgetRectangle {
|
||||
fn set_id(&mut self, id: WidgetID) {
|
||||
self.id = id;
|
||||
}
|
||||
|
||||
fn get_type(&self) -> super::WidgetType {
|
||||
super::WidgetType::Rectangle
|
||||
}
|
||||
|
||||
fn debug_print(&self) -> String {
|
||||
format!(
|
||||
"[color: {}][color2: {}][gradient: {:?}]",
|
||||
self.params.color.debug_ansi_block(),
|
||||
self.params.color2.debug_ansi_block(),
|
||||
self.params.gradient,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,4 +101,12 @@ impl WidgetObj for WidgetSprite {
|
||||
fn set_id(&mut self, id: WidgetID) {
|
||||
self.id = id;
|
||||
}
|
||||
|
||||
fn get_type(&self) -> super::WidgetType {
|
||||
super::WidgetType::Sprite
|
||||
}
|
||||
|
||||
fn debug_print(&self) -> String {
|
||||
String::default()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user