sizing actually working correctly now

This commit is contained in:
2025-09-16 17:31:54 -04:00
parent b48acccb8d
commit f9097807a2
17 changed files with 333 additions and 194 deletions

View File

@@ -21,7 +21,7 @@ pub struct Client {
input: Input,
ui: Ui<Client>,
info: WidgetId<Text>,
selected: Option<WidgetId<TextEdit>>,
focus: Option<WidgetId<TextEdit>>,
}
impl Client {
@@ -38,7 +38,7 @@ impl Client {
rrect.color(Color::ORANGE),
rrect.color(Color::LIME).pad(10.0),
)
.span(Dir::RIGHT, [1, 1]),
.span(Dir::RIGHT, ratio(1)),
rrect.color(Color::YELLOW),
)
.span(Dir::RIGHT, [2, 2, 1])
@@ -110,6 +110,7 @@ impl Client {
btext(":gamer mode").family(Family::Monospace),
rect(Color::CYAN).size(10).center(),
rect(Color::RED).size(100).center(),
rect(Color::PURPLE).size(50).align(Align::Top),
)
.span(Dir::RIGHT, sized())
.center(),
@@ -119,14 +120,34 @@ impl Client {
.add_static(&mut ui);
let texts = Span::empty(Dir::DOWN).add(&mut ui);
let add_text = text_edit("add")
.text_align(Align::Left)
.font_size(30)
.id_on(Sense::click(), |id, client: &mut Client, ctx| {
client.ui.text(id).select(ctx.cursor, ctx.size);
client.focus = Some(id.clone());
})
.add(&mut ui);
let text_edit_scroll = (
texts,
text_edit("add")
.font_size(30)
.id_on(Sense::click(), |id, client: &mut Client, ctx| {
client.ui.text(id).select(ctx.cursor, ctx.size);
client.selected = Some(id.clone());
})
(Rect::new(Color::SKY), texts.clone()).stack(),
(
add_text.clone(),
Rect::new(Color::GREEN)
.on(Sense::click(), move |client: &mut Client, _| {
let content = client.ui.text(&add_text).take();
let text = text_edit(content)
.font_size(30)
.id_on(Sense::click(), |id, client: &mut Client, ctx| {
client.ui.text(id).select(ctx.cursor, ctx.size);
client.focus = Some(id.clone());
})
.pad(10)
.add(&mut client.ui);
client.ui[&texts].children.push((text.any(), sized()));
})
.size(40),
)
.span(Dir::RIGHT, [ratio(1), sized()])
.pad(30),
)
.span(Dir::DOWN, [ratio(1), sized()])
@@ -161,24 +182,15 @@ impl Client {
.span(Dir::RIGHT, ratio(1));
let info = text("").add(&mut ui);
let info_sect = info.clone().pad(10).align(Align::BotLeft);
ui.set_root(
(
tabs.label("tabs"),
(main, info_sect.label("info sect"))
.stack()
.label("main stack"),
)
.span(Dir::DOWN, [fixed(40), ratio(1)])
.label("root"),
);
// let info_sect = info.clone().pad(10).align(Align::BotLeft);
ui.set_root((tabs, main).span(Dir::DOWN, [fixed(40), ratio(1)]));
Self {
renderer,
input: Input::default(),
ui,
info,
selected: None,
focus: None,
}
}
@@ -186,6 +198,12 @@ impl Client {
self.input.event(&event);
let cursor_state = self.cursor_state().clone();
let window_size = self.window_size();
if let Some(focus) = &self.focus
&& cursor_state.buttons.left.is_start()
{
self.ui.text(focus).deselect();
self.focus = None;
}
run_sensors(self, &cursor_state, window_size);
match event {
WindowEvent::CloseRequested => event_loop.exit(),
@@ -199,24 +217,24 @@ impl Client {
self.renderer.resize(&size)
}
WindowEvent::KeyboardInput { event, .. } => {
if let Some(sel) = &self.selected
if let Some(sel) = &self.focus
&& event.state.is_pressed()
&& self.ui.text(sel).apply_event(&event).unfocus()
{
self.selected = None;
self.focus = None;
}
}
_ => (),
}
let new = format!(
"widgets: {}\nactive:{}\nviews: {}",
self.ui.num_widgets(),
self.ui.active_widgets(),
self.renderer.ui.view_count()
);
if new != self.ui[&self.info].content {
self.ui[&self.info].content = new;
}
// let new = format!(
// "widgets: {}\nactive:{}\nviews: {}",
// self.ui.num_widgets(),
// self.ui.active_widgets(),
// self.renderer.ui.view_count()
// );
// if new != self.ui[&self.info].content {
// self.ui[&self.info].content = new;
// }
if self.ui.needs_redraw() {
self.renderer.window().request_redraw();
}