mirror of
https://github.com/griffi-gh/hUI.git
synced 2024-11-21 22:58:42 -06:00
eh... its better i guess. still needs a refactor
This commit is contained in:
parent
6bc912e936
commit
0f98da2753
|
@ -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();
|
||||
|
||||
|
|
|
@ -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<Box<dyn UiElement>>);
|
||||
|
||||
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<Vec<Box<dyn UiElement>>> 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<T: UiElement + 'static> UiElementListExt for T {
|
||||
fn add_to(self, ui: &mut ElementList) {
|
||||
impl<T: UiElement + 'static> 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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue