This commit is contained in:
2025-08-13 01:35:09 -04:00
parent 23a5ccd05e
commit c7e3225c5f
11 changed files with 247 additions and 142 deletions

View File

@@ -1,7 +1,7 @@
use std::sync::Arc;
use app::App;
use gui::{Dir, Rect, UI, UIColor, WidgetArrUtil, WidgetUtil, fixed, ratio, rel};
use gui::*;
use render::Renderer;
use winit::{event::WindowEvent, event_loop::ActiveEventLoop, window::Window};
@@ -14,44 +14,46 @@ pub fn main() {
pub struct Client {
renderer: Renderer,
ui: Ui,
test: WidgetId<Span>,
}
impl Client {
pub fn new(window: Arc<Window>) -> Self {
let mut renderer = Renderer::new(window);
let renderer = Renderer::new(window);
let rect = Rect {
color: UIColor::WHITE,
color: UiColor::WHITE,
radius: 20.0,
thickness: 0.0,
inner_radius: 0.0,
};
let mut ui = UI::build();
let blue = ui.add(rect.color(UIColor::BLUE));
let handle = blue.handle();
let mut ui = ui.finish(
let mut ui = Ui::new();
let test = ui.id();
ui.set_base(
(
(
blue,
rect.color(UiColor::BLUE),
(
rect.color(UIColor::RED).center((100.0, 100.0)),
rect.color(UiColor::RED).center((100.0, 100.0)),
(
rect.color(UIColor::ORANGE),
rect.color(UIColor::LIME).pad(10.0),
rect.color(UiColor::ORANGE),
rect.color(UiColor::LIME).pad(10.0),
)
.span(Dir::RIGHT, [1, 1]),
rect.color(UIColor::YELLOW),
rect.color(UiColor::YELLOW),
)
.span(Dir::RIGHT, [2, 2, 1])
.pad(10),
)
.span(Dir::RIGHT, [1, 3]),
Span::empty(Dir::RIGHT).id(&test),
(
rect.color(UIColor::GREEN),
rect.color(UIColor::ORANGE),
rect.color(UIColor::CYAN),
rect.color(UIColor::BLUE),
rect.color(UIColor::MAGENTA),
rect.color(UIColor::RED),
rect.color(UiColor::GREEN),
rect.color(UiColor::ORANGE),
rect.color(UiColor::CYAN),
rect.color(UiColor::BLUE),
rect.color(UiColor::MAGENTA),
rect.color(UiColor::RED),
)
.span(
Dir::LEFT,
@@ -65,19 +67,27 @@ impl Client {
],
),
)
.span(Dir::DOWN, [3, 1])
.span(Dir::DOWN, [3, 1, 1])
.pad(10),
);
ui.widgets.get_mut(&handle).unwrap().color = UIColor::MAGENTA;
renderer.update(&ui);
Self { renderer }
Self { renderer, ui, test }
}
pub fn event(&mut self, event: WindowEvent, event_loop: &ActiveEventLoop) {
match event {
WindowEvent::CloseRequested => event_loop.exit(),
WindowEvent::RedrawRequested => self.renderer.draw(),
WindowEvent::RedrawRequested => {
self.renderer.update(&mut self.ui);
self.renderer.draw()
}
WindowEvent::Resized(size) => self.renderer.resize(&size),
WindowEvent::KeyboardInput { event, .. } => {
if event.state.is_pressed() {
let child = self.ui.add(Rect::new(Color::YELLOW)).erase_type();
self.ui[&self.test].children.push((child, fixed(20.0)));
self.renderer.window().request_redraw();
}
}
_ => (),
}
}