mirror of
https://github.com/griffi-gh/hUI.git
synced 2024-11-22 07:08:42 -06:00
eh... its better i guess. still needs a refactor
This commit is contained in:
parent
371f3cb61e
commit
30579928b0
|
@ -8,7 +8,7 @@ use winit::{
|
||||||
use hui::{
|
use hui::{
|
||||||
UiInstance,
|
UiInstance,
|
||||||
element::{
|
element::{
|
||||||
ElementList, UiElementListExt,
|
ElementList, UiElementExt,
|
||||||
container::Container,
|
container::Container,
|
||||||
text::Text,
|
text::Text,
|
||||||
},
|
},
|
||||||
|
@ -40,7 +40,6 @@ fn main() {
|
||||||
|
|
||||||
hui.begin();
|
hui.begin();
|
||||||
|
|
||||||
hui.add({
|
|
||||||
Container::default()
|
Container::default()
|
||||||
.with_size((UiSize::Fraction(1.), UiSize::Fraction(1.)))
|
.with_size((UiSize::Fraction(1.), UiSize::Fraction(1.)))
|
||||||
.with_padding(Sides::all(5.))
|
.with_padding(Sides::all(5.))
|
||||||
|
@ -50,9 +49,9 @@ fn main() {
|
||||||
.with_text("Hello, world")
|
.with_text("Hello, world")
|
||||||
.with_text_size(120)
|
.with_text_size(120)
|
||||||
.with_color(vec4(0., 0., 0., 1.))
|
.with_color(vec4(0., 0., 0., 1.))
|
||||||
.add_to(ui);
|
.add_child(ui);
|
||||||
})
|
})
|
||||||
}, resolution);
|
.add_root(&mut hui, resolution);
|
||||||
|
|
||||||
hui.end();
|
hui.end();
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use crate::{
|
use crate::{
|
||||||
draw::UiDrawCommandList,
|
draw::UiDrawCommandList, layout::LayoutInfo, measure::Response, state::StateRepo, text::TextMeasure, UiInstance
|
||||||
measure::Response,
|
|
||||||
state::StateRepo,
|
|
||||||
text::TextMeasure,
|
|
||||||
layout::LayoutInfo
|
|
||||||
};
|
};
|
||||||
|
|
||||||
mod builtin;
|
mod builtin;
|
||||||
|
@ -64,7 +60,7 @@ pub trait UiElement {
|
||||||
pub struct ElementList(pub Vec<Box<dyn UiElement>>);
|
pub struct ElementList(pub Vec<Box<dyn UiElement>>);
|
||||||
|
|
||||||
impl ElementList {
|
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))
|
self.0.push(Box::new(element))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,12 +79,16 @@ impl From<Vec<Box<dyn UiElement>>> for ElementList {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait UiElementListExt {
|
pub trait UiElementExt: UiElement {
|
||||||
fn add_to(self, ui: &mut ElementList);
|
fn add_child(self, ui: &mut ElementList);
|
||||||
|
fn add_root(self, ui: &mut UiInstance, resolution: glam::Vec2);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: UiElement + 'static> UiElementListExt for T {
|
impl<T: UiElement + 'static> UiElementExt for T {
|
||||||
fn add_to(self, ui: &mut ElementList) {
|
fn add_child(self, ui: &mut ElementList) {
|
||||||
ui.add(self)
|
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