wgui: custom attribs

This commit is contained in:
Aleksander
2025-08-16 22:55:40 +02:00
parent 481db7f23c
commit d54f74ed3c
13 changed files with 158 additions and 75 deletions

View File

@@ -8,12 +8,13 @@ use wgui::{
button::{ButtonClickCallback, ComponentButton},
checkbox::ComponentCheckbox,
},
drawing::Color,
event::EventListenerCollection,
globals::WguiGlobals,
i18n::Translation,
layout::{Layout, Widget},
parser::{ParseDocumentParams, ParserState},
widget::label::WidgetLabel,
parser::{ParseDocumentExtra, ParseDocumentParams, ParserState},
widget::{label::WidgetLabel, rectangle::WidgetRectangle},
};
pub struct TestbedGeneric {
@@ -58,12 +59,27 @@ impl TestbedGeneric {
let globals = WguiGlobals::new(Box::new(assets::Asset {}))?;
let extra = ParseDocumentExtra {
on_custom_attrib: Some(Box::new(move |par| {
if par.attrib == "my_custom" {
let mut rect = par.get_widget_as::<WidgetRectangle>().unwrap();
rect.params.color = match par.value {
"red" => Color::new(1.0, 0.0, 0.0, 1.0),
"green" => Color::new(0.0, 1.0, 0.0, 1.0),
"blue" => Color::new(0.0, 0.0, 1.0, 1.0),
_ => Color::new(1.0, 1.0, 1.0, 1.0),
}
}
})),
dev_mode: false,
};
let (layout, state) = wgui::parser::new_layout_from_assets(
listeners,
&ParseDocumentParams {
globals,
path: XML_PATH,
extra: Default::default(),
extra,
},
)?;