diff --git a/hui-examples/examples/modern_testbed.rs b/hui-examples/examples/modern_testbed.rs index 07e836f..5adbec0 100644 --- a/hui-examples/examples/modern_testbed.rs +++ b/hui-examples/examples/modern_testbed.rs @@ -8,7 +8,7 @@ use winit::{ use hui::{ UiInstance, element::{ - ElementList, UiElementListExt, + ElementList, UiElementExt, container::Container, text::Text, }, @@ -40,19 +40,18 @@ fn main() { hui.begin(); - hui.add({ - Container::default() - .with_size((UiSize::Fraction(1.), UiSize::Fraction(1.))) - .with_padding(Sides::all(5.)) - .with_background(vec3(1., 0., 0.)) - .with_children(|ui: &mut ElementList| { - Text::default() - .with_text("Hello, world") - .with_text_size(120) - .with_color(vec4(0., 0., 0., 1.)) - .add_to(ui); - }) - }, resolution); + Container::default() + .with_size((UiSize::Fraction(1.), UiSize::Fraction(1.))) + .with_padding(Sides::all(5.)) + .with_background(vec3(1., 0., 0.)) + .with_children(|ui: &mut ElementList| { + Text::default() + .with_text("Hello, world") + .with_text_size(120) + .with_color(vec4(0., 0., 0., 1.)) + .add_child(ui); + }) + .add_root(&mut hui, resolution); hui.end(); diff --git a/hui/src/element.rs b/hui/src/element.rs index 310b4de..46f0082 100644 --- a/hui/src/element.rs +++ b/hui/src/element.rs @@ -1,10 +1,6 @@ use std::any::Any; use crate::{ - draw::UiDrawCommandList, - measure::Response, - state::StateRepo, - text::TextMeasure, - layout::LayoutInfo + draw::UiDrawCommandList, layout::LayoutInfo, measure::Response, state::StateRepo, text::TextMeasure, UiInstance }; mod builtin; @@ -64,7 +60,7 @@ pub trait UiElement { pub struct ElementList(pub Vec>); impl ElementList { - pub fn add<'a>(&mut self, element: impl UiElement + 'static) { + pub fn add(&mut self, element: impl UiElement + 'static) { self.0.push(Box::new(element)) } } @@ -83,12 +79,16 @@ impl From>> for ElementList { } } -pub trait UiElementListExt { - fn add_to(self, ui: &mut ElementList); +pub trait UiElementExt: UiElement { + fn add_child(self, ui: &mut ElementList); + fn add_root(self, ui: &mut UiInstance, resolution: glam::Vec2); } -impl UiElementListExt for T { - fn add_to(self, ui: &mut ElementList) { +impl UiElementExt for T { + fn add_child(self, ui: &mut ElementList) { ui.add(self) } + fn add_root(self, ui: &mut UiInstance, max_size: glam::Vec2) { + ui.add(self, max_size); + } }