initial text impl

This commit is contained in:
2025-08-23 21:15:39 -04:00
parent abcbc267b5
commit 5ce6fca275
33 changed files with 530 additions and 117 deletions

View File

@@ -2,7 +2,7 @@ use std::sync::Arc;
use app::App;
use render::Renderer;
use ui::*;
use ui::prelude::*;
use winit::{event::WindowEvent, event_loop::ActiveEventLoop, window::Window};
use crate::testing::input::Input;
@@ -80,10 +80,11 @@ impl Client {
color: UiColor,
main: &WidgetId<Regioned>,
to: &WidgetId<To>,
) -> impl WidgetLike<Client, IdTag> {
label: impl Into<String>,
) -> impl WidgetLike<Client, FnTag> {
let main = main.clone();
let to = to.clone().erase_type();
Rect::new(color)
let rect = Rect::new(color)
.id_on(Sense::PressStart, move |id, ctx| {
ctx.ui[&main].inner = to.clone();
ctx.ui[id].color = color.add_rgb(-0.2);
@@ -96,14 +97,15 @@ impl Client {
})
.edit_on(Sense::HoverEnd, move |r, _| {
r.color = color;
})
});
(rect, text(label)).stack()
}
let tabs = ui.add(
(
switch_button(UiColor::RED, &main, &pad_test),
switch_button(UiColor::GREEN, &main, &span_test),
switch_button(UiColor::BLUE, &main, &span_add_test),
switch_button(UiColor::RED, &main, &pad_test, "pad test"),
switch_button(UiColor::GREEN, &main, &span_test, "span test"),
switch_button(UiColor::BLUE, &main, &span_add_test, "span add test"),
)
.span(Dir::RIGHT, [1, 1, 1]),
);
@@ -113,8 +115,8 @@ impl Client {
println!("{}", ctx.ui.num_widgets());
})
.region(
UiRegion::corner(Corner::BotRight)
.size((150, 150))
UiPos::corner(Corner::BotRight)
.expand((150, 150))
.shifted((-75, -75)),
);
@@ -125,8 +127,8 @@ impl Client {
ctx.ui[&s].children.pop();
})
.region(
UiRegion::corner(Corner::BotLeft)
.size((150, 150))
UiPos::corner(Corner::BotLeft)
.expand((150, 150))
.shifted((75, -75)),
);
ui.set_base(
@@ -160,7 +162,10 @@ impl Client {
self.renderer.update(ui);
self.renderer.draw()
}
WindowEvent::Resized(size) => self.renderer.resize(&size),
WindowEvent::Resized(size) => {
ui.resize((size.width, size.height));
self.renderer.resize(&size)
}
WindowEvent::KeyboardInput { event, .. } => {
if event.state.is_pressed() {
let child = ui