mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-22 06:48:43 -06:00
it works
This commit is contained in:
parent
6b33e9cdc9
commit
adbab2b2a6
|
@ -15,7 +15,7 @@ use kubi_ui::{
|
||||||
},
|
},
|
||||||
interaction::IntoInteractable,
|
interaction::IntoInteractable,
|
||||||
UiSize,
|
UiSize,
|
||||||
UiDirection, IfModified,
|
UiDirection, IfModified, elements,
|
||||||
};
|
};
|
||||||
use kubi_ui_glium::GliumUiRenderer;
|
use kubi_ui_glium::GliumUiRenderer;
|
||||||
|
|
||||||
|
@ -24,12 +24,15 @@ fn main() {
|
||||||
|
|
||||||
let event_loop = EventLoopBuilder::new().build().unwrap();
|
let event_loop = EventLoopBuilder::new().build().unwrap();
|
||||||
let (window, display) = SimpleWindowBuilder::new().build(&event_loop);
|
let (window, display) = SimpleWindowBuilder::new().build(&event_loop);
|
||||||
|
window.set_title("Mom downloader 2000");
|
||||||
|
|
||||||
let mut kui = KubiUi::new();
|
let mut kui = KubiUi::new();
|
||||||
let mut backend = GliumUiRenderer::new(&display);
|
let mut backend = GliumUiRenderer::new(&display);
|
||||||
|
|
||||||
let font_handle = kui.add_font_from_bytes(include_bytes!("../../assets/fonts/roboto/Roboto-Regular.ttf"));
|
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| {
|
event_loop.run(|event, window_target| {
|
||||||
window_target.set_control_flow(ControlFlow::Poll);
|
window_target.set_control_flow(ControlFlow::Poll);
|
||||||
match event {
|
match event {
|
||||||
|
@ -49,13 +52,27 @@ fn main() {
|
||||||
padding: Sides::all(5.),
|
padding: Sides::all(5.),
|
||||||
align: (Alignment::Begin, Alignment::Begin),
|
align: (Alignment::Begin, Alignment::Begin),
|
||||||
size: (UiSize::Percentage(1.), UiSize::Percentage(1.)),
|
size: (UiSize::Percentage(1.), UiSize::Percentage(1.)),
|
||||||
elements: vec![
|
background: Some(vec4(0.2, 0.2, 0.5, 1.)),
|
||||||
Box::new(Text {
|
elements: elements(|el| {
|
||||||
text: "Hello_world".into(),
|
if instant.elapsed().as_secs_f32() < 5. {
|
||||||
|
el.add(Text {
|
||||||
|
text: "Downloading your mom...".into(),
|
||||||
font: font_handle,
|
font: font_handle,
|
||||||
..Default::default()
|
..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()
|
..Default::default()
|
||||||
}, resolution);
|
}, resolution);
|
||||||
|
|
|
@ -160,12 +160,15 @@ impl UiDrawPlan {
|
||||||
let mut layout = Layout::new(CoordinateSystem::PositiveYDown);
|
let mut layout = Layout::new(CoordinateSystem::PositiveYDown);
|
||||||
layout.append(
|
layout.append(
|
||||||
&[tr.internal_font(*font)],
|
&[tr.internal_font(*font)],
|
||||||
&TextStyle::new(&text, *size as f32, 0)
|
&TextStyle::new(text, *size as f32, 0)
|
||||||
);
|
);
|
||||||
let glyphs = layout.glyphs();
|
let glyphs = layout.glyphs();
|
||||||
|
|
||||||
//let mut rpos_x = 0.;
|
//let mut rpos_x = 0.;
|
||||||
for layout_glyph in glyphs {
|
for layout_glyph in glyphs {
|
||||||
|
if !layout_glyph.char_data.rasterize() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
let vidx = swapper.current().vertices.len() as u32;
|
let vidx = swapper.current().vertices.len() as u32;
|
||||||
let glyph = tr.glyph(*font, layout_glyph.parent, layout_glyph.key.px as u8);
|
let glyph = tr.glyph(*font, layout_glyph.parent, layout_glyph.key.px as u8);
|
||||||
//rpos_x += glyph.metrics.advance_width;//glyph.metrics.advance_width;
|
//rpos_x += glyph.metrics.advance_width;//glyph.metrics.advance_width;
|
||||||
|
|
|
@ -114,3 +114,16 @@ pub struct LayoutInfo {
|
||||||
pub max_size: Vec2,
|
pub max_size: Vec2,
|
||||||
pub direction: UiDirection,
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue