initial global widget store

This commit is contained in:
2025-12-10 01:42:39 -05:00
parent 7f4846a2d3
commit 6156c66a20
31 changed files with 536 additions and 352 deletions

View File

@@ -51,7 +51,7 @@ impl DefaultAppState for Client {
.add(ui);
let span_add = Span::empty(Dir::RIGHT).add(ui);
let span_add_ = span_add.clone();
let span_add_ = span_add.weak();
let add_button = rect(Color::LIME)
.radius(30)
@@ -64,7 +64,6 @@ impl DefaultAppState for Client {
.sized((150, 150))
.align(Align::BOT_RIGHT);
let span_add_ = span_add.clone();
let del_button = rect(Color::RED)
.radius(30)
.on(CursorSense::click(), move |_| {
@@ -99,7 +98,8 @@ impl DefaultAppState for Client {
.add(ui);
let texts = Span::empty(Dir::DOWN).gap(10).add(ui);
let msg_area = texts.clone().scroll().masked().background(rect(Color::SKY));
let texts_ = texts.weak();
let msg_area = texts.scroll().masked().background(rect(Color::SKY));
let add_text = wtext("add")
.editable(false)
.text_align(Align::LEFT)
@@ -114,18 +114,19 @@ impl DefaultAppState for Client {
.wrap(true)
.attr::<Selectable>(());
let msg_box = text.background(rect(Color::WHITE.darker(0.5))).add(ctx.ui);
texts.get_mut().children.push(msg_box);
texts_.get_mut().children.push(msg_box);
})
.add(ui);
let add_text_ = add_text.weak();
let text_edit_scroll = (
msg_area.height(rest(1)),
(
Rect::new(Color::WHITE.darker(0.9)),
(
add_text.clone().width(rest(1)),
add_text.width(rest(1)),
Rect::new(Color::GREEN)
.on(CursorSense::click(), move |ctx| {
ctx.ui.run_event(ctx.state, &add_text, Submit, ());
ctx.ui.run_event(ctx.state, add_text_, Submit, ());
})
.sized((40, 40)),
)
@@ -140,13 +141,24 @@ impl DefaultAppState for Client {
.span(Dir::DOWN)
.add(ui);
let main = pad_test.clone().pad(10).add(ui);
let main = pad_test.pad(10).add(ui);
let main_ = main.weak();
let switch_button = |color, to: WidgetRef, label| {
let main_ = main.clone();
let tab_handles = Handle::from((0, Vec::new()));
let switch_button = |color, to: Option<WidgetHandle>, label| {
let tab_handles = tab_handles.clone();
let i = tab_handles.get().1.len();
tab_handles.get_mut().1.push(to);
let rect = rect(color)
.on(CursorSense::click(), move |ctx| {
main_.get_mut().inner = to.clone();
let (prev, all) = &mut *tab_handles.get_mut();
if let Some(to) = &mut all[i] {
let mut main = main_.get_mut();
std::mem::swap(&mut main.inner, to);
all.swap(*prev, i);
*prev = i;
}
ctx.widget.get_mut().color = color.darker(0.3);
})
.on(
@@ -162,20 +174,21 @@ impl DefaultAppState for Client {
};
let tabs = (
switch_button(Color::RED, pad_test, "pad"),
switch_button(Color::GREEN, span_test, "span"),
switch_button(Color::BLUE, span_add_test, "image span"),
switch_button(Color::MAGENTA, text_test, "text layout"),
switch_button(Color::RED, None, "pad"),
switch_button(Color::GREEN, Some(span_test), "span"),
switch_button(Color::BLUE, Some(span_add_test), "image span"),
switch_button(Color::MAGENTA, Some(text_test), "text layout"),
switch_button(
Color::YELLOW.mul_rgb(0.5),
text_edit_scroll,
Some(text_edit_scroll),
"text edit scroll",
),
)
.span(Dir::RIGHT);
let info = wtext("").add(ui);
let info_sect = info.clone().pad(10).align(Align::RIGHT);
let info_ = wtext("").add(ui);
let info = info_.weak();
let info_sect = info_.pad(10).align(Align::RIGHT);
((tabs.height(40), main).span(Dir::DOWN), info_sect)
.stack()
@@ -187,7 +200,7 @@ impl DefaultAppState for Client {
fn window_event(&mut self, _: WindowEvent, ui: &mut Ui, state: &UiState) {
let new = format!(
"widgets: {}\nactive:{}\nviews: {}",
ui.num_widgets(),
total_widgets(),
ui.active_widgets(),
state.renderer.ui.view_count()
);