wgui: attrib pairs
This commit is contained in:
@@ -24,11 +24,19 @@
|
||||
<CheckBox text="i'm checked by default" checked="1" />
|
||||
</div>
|
||||
|
||||
<label text="custom attrib test, you should see three rectangles below, each of them in R, G and B" />
|
||||
<label text="custom attrib test, you should see size rectangles below, each of them in R, G and B (if TESTBED is generic)" />
|
||||
<div flex_direction="row" gap="8">
|
||||
<rectangle _my_custom="red" width="16" height="16" />
|
||||
<rectangle _my_custom="green" width="16" height="16" />
|
||||
<rectangle _my_custom="blue" width="16" height="16" />
|
||||
<label text="lighter:" />
|
||||
|
||||
<rectangle _my_custom="red" _mult="1.0" width="16" height="16" />
|
||||
<rectangle _my_custom="green" _mult="1.0" width="16" height="16" />
|
||||
<rectangle _my_custom="blue" _mult="1.0" width="16" height="16" />
|
||||
|
||||
<label text="darker:" />
|
||||
|
||||
<rectangle _my_custom="red" _mult="0.5" width="16" height="16" />
|
||||
<rectangle _my_custom="green" _mult="0.5" width="16" height="16" />
|
||||
<rectangle _my_custom="blue" _mult="0.5" width="16" height="16" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -62,16 +62,28 @@ impl TestbedGeneric {
|
||||
let globals = WguiGlobals::new(Box::new(assets::Asset {}), Default::default())?;
|
||||
|
||||
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),
|
||||
}
|
||||
}
|
||||
on_custom_attribs: Some(Box::new(move |par| {
|
||||
let Some(my_custom_value) = par.get_value("my_custom") else {
|
||||
return;
|
||||
};
|
||||
|
||||
let Some(mult_value) = par.get_value("mult") else {
|
||||
return;
|
||||
};
|
||||
|
||||
let mult_f32 = mult_value.parse::<f32>().unwrap();
|
||||
|
||||
let mut color = match my_custom_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),
|
||||
};
|
||||
|
||||
color = color.mult_rgb(mult_f32);
|
||||
|
||||
let mut rect = par.get_widget_as::<WidgetRectangle>().unwrap();
|
||||
rect.params.color = color;
|
||||
})),
|
||||
dev_mode: false,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user