2024-02-26 09:33:55 -06:00
|
|
|
use glam::UVec2;
|
2024-02-17 21:04:02 -06:00
|
|
|
use glium::{backend::glutin::SimpleWindowBuilder, Surface};
|
|
|
|
use winit::{
|
|
|
|
event::{Event, WindowEvent},
|
|
|
|
event_loop::{EventLoopBuilder, ControlFlow}
|
|
|
|
};
|
|
|
|
use hui::{
|
2024-02-26 09:33:55 -06:00
|
|
|
UiInstance, color, size,
|
|
|
|
layout::Alignment,
|
2024-02-17 21:04:02 -06:00
|
|
|
element::{
|
2024-02-26 09:33:55 -06:00
|
|
|
container::Container, text::Text, UiElementExt
|
2024-02-25 18:15:55 -06:00
|
|
|
},
|
2024-02-17 21:04:02 -06:00
|
|
|
};
|
|
|
|
use hui_glium::GliumUiRenderer;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
kubi_logging::init();
|
|
|
|
|
|
|
|
let event_loop = EventLoopBuilder::new().build().unwrap();
|
|
|
|
let (_window, display) = SimpleWindowBuilder::new().build(&event_loop);
|
|
|
|
|
|
|
|
let mut hui = UiInstance::new();
|
|
|
|
let mut backend = GliumUiRenderer::new(&display);
|
2024-02-25 18:15:55 -06:00
|
|
|
|
2024-02-17 21:04:02 -06:00
|
|
|
event_loop.run(|event, window_target| {
|
|
|
|
window_target.set_control_flow(ControlFlow::Poll);
|
|
|
|
match event {
|
|
|
|
Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => {
|
|
|
|
window_target.exit();
|
|
|
|
},
|
|
|
|
Event::AboutToWait => {
|
|
|
|
let mut frame = display.draw();
|
|
|
|
frame.clear_color_srgb(0.5, 0.5, 0.5, 0.);
|
|
|
|
|
|
|
|
let resolution = UVec2::from(display.get_framebuffer_dimensions()).as_vec2();
|
|
|
|
|
|
|
|
hui.begin();
|
|
|
|
|
2024-02-26 08:13:03 -06:00
|
|
|
Container::default()
|
2024-02-26 09:33:55 -06:00
|
|
|
.with_size(size!(100%, 50%))
|
|
|
|
.with_align(Alignment::Center)
|
|
|
|
.with_padding(5.)
|
2024-02-28 09:47:46 -06:00
|
|
|
.with_gap(10.)
|
2024-02-26 09:33:55 -06:00
|
|
|
.with_corner_radius(10.)
|
2024-02-28 09:47:46 -06:00
|
|
|
.with_background(color::WHITE)
|
2024-02-26 09:33:55 -06:00
|
|
|
.with_children(|ui| {
|
2024-02-26 08:13:03 -06:00
|
|
|
Text::default()
|
|
|
|
.with_text("Hello, world")
|
2024-02-26 09:33:55 -06:00
|
|
|
.with_text_size(100)
|
2024-02-28 09:47:46 -06:00
|
|
|
.with_color(color::BLACK)
|
2024-02-26 09:33:55 -06:00
|
|
|
.add_child(ui);
|
|
|
|
Container::default()
|
|
|
|
.with_padding((10., 20.))
|
2024-02-28 09:47:46 -06:00
|
|
|
.with_corner_radius((2.5, 30., 2.5, 2.5))
|
2024-02-26 09:33:55 -06:00
|
|
|
.with_background(color::DARK_RED)
|
|
|
|
.with_children(|ui| {
|
|
|
|
Text::default()
|
|
|
|
.with_text("Lorem ipsum dolor sit amet, consectetur adipiscing elit.")
|
|
|
|
.with_text_size(24)
|
|
|
|
.add_child(ui);
|
|
|
|
})
|
2024-02-26 08:13:03 -06:00
|
|
|
.add_child(ui);
|
|
|
|
})
|
|
|
|
.add_root(&mut hui, resolution);
|
2024-02-17 21:04:02 -06:00
|
|
|
|
|
|
|
hui.end();
|
|
|
|
|
|
|
|
backend.update(&hui);
|
|
|
|
backend.draw(&mut frame, resolution);
|
|
|
|
|
|
|
|
frame.finish().unwrap();
|
|
|
|
}
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}).unwrap();
|
|
|
|
}
|