This commit is contained in:
griffi-gh 2023-12-02 19:46:08 +01:00
parent 6b33e9cdc9
commit adbab2b2a6
3 changed files with 42 additions and 9 deletions

View file

@ -15,7 +15,7 @@ use kubi_ui::{
},
interaction::IntoInteractable,
UiSize,
UiDirection, IfModified,
UiDirection, IfModified, elements,
};
use kubi_ui_glium::GliumUiRenderer;
@ -24,12 +24,15 @@ fn main() {
let event_loop = EventLoopBuilder::new().build().unwrap();
let (window, display) = SimpleWindowBuilder::new().build(&event_loop);
window.set_title("Mom downloader 2000");
let mut kui = KubiUi::new();
let mut backend = GliumUiRenderer::new(&display);
let font_handle = kui.add_font_from_bytes(include_bytes!("../../assets/fonts/roboto/Roboto-Regular.ttf"));
let instant = Instant::now();
event_loop.run(|event, window_target| {
window_target.set_control_flow(ControlFlow::Poll);
match event {
@ -49,13 +52,27 @@ fn main() {
padding: Sides::all(5.),
align: (Alignment::Begin, Alignment::Begin),
size: (UiSize::Percentage(1.), UiSize::Percentage(1.)),
elements: vec![
Box::new(Text {
text: "Hello_world".into(),
background: Some(vec4(0.2, 0.2, 0.5, 1.)),
elements: elements(|el| {
if instant.elapsed().as_secs_f32() < 5. {
el.add(Text {
text: "Downloading your mom...".into(),
font: font_handle,
..Default::default()
});
el.add(ProgressBar {
value: (instant.elapsed().as_secs_f32() / 60.).powf(0.5),
..Default::default()
});
} else {
el.add(Text {
text: "Error 413 (Request Entity Too Large)".into(),
font: font_handle,
color: vec4(1., 0., 0., 1.),
..Default::default()
});
}
}),
],
..Default::default()
}, resolution);

View file

@ -160,12 +160,15 @@ impl UiDrawPlan {
let mut layout = Layout::new(CoordinateSystem::PositiveYDown);
layout.append(
&[tr.internal_font(*font)],
&TextStyle::new(&text, *size as f32, 0)
&TextStyle::new(text, *size as f32, 0)
);
let glyphs = layout.glyphs();
//let mut rpos_x = 0.;
for layout_glyph in glyphs {
if !layout_glyph.char_data.rasterize() {
continue
}
let vidx = swapper.current().vertices.len() as u32;
let glyph = tr.glyph(*font, layout_glyph.parent, layout_glyph.key.px as u8);
//rpos_x += glyph.metrics.advance_width;//glyph.metrics.advance_width;

View file

@ -114,3 +114,16 @@ pub struct LayoutInfo {
pub max_size: Vec2,
pub direction: UiDirection,
}
pub struct ElementList(Vec<Box<dyn UiElement>>);
impl ElementList {
pub fn add(&mut self, element: impl UiElement + 'static) {
self.0.push(Box::new(element));
}
}
pub fn elements(f: impl FnOnce(&mut ElementList)) -> Vec<Box<dyn UiElement>> {
let mut elements = ElementList(Vec::new());
f(&mut elements);
elements.0
}