refcount ids and delete unused
This commit is contained in:
@@ -22,13 +22,13 @@ pub struct Client {
|
||||
}
|
||||
|
||||
pub struct UiIds {
|
||||
test: WidgetId<Span>,
|
||||
span_add: WidgetId<Span>,
|
||||
}
|
||||
|
||||
impl Client {
|
||||
pub fn create_ui() -> (Ui<Self>, UiIds) {
|
||||
let mut ui = Ui::new();
|
||||
let test = ui.id();
|
||||
let span_add = ui.id();
|
||||
let rect = Rect {
|
||||
color: UiColor::WHITE,
|
||||
radius: 20.0,
|
||||
@@ -73,7 +73,7 @@ impl Client {
|
||||
],
|
||||
),
|
||||
);
|
||||
let span_add_test = ui.add(Span::empty(Dir::RIGHT).id(&test));
|
||||
let span_add_test = ui.add(Span::empty(Dir::RIGHT).id(&span_add));
|
||||
let main: WidgetId<Regioned> = ui.id();
|
||||
|
||||
fn switch_button<To>(
|
||||
@@ -100,7 +100,7 @@ impl Client {
|
||||
})
|
||||
}
|
||||
|
||||
let buttons = ui.add(
|
||||
let tabs = ui.add(
|
||||
(
|
||||
switch_button(UiColor::RED, &main, &pad_test),
|
||||
switch_button(UiColor::GREEN, &main, &span_test),
|
||||
@@ -108,22 +108,36 @@ impl Client {
|
||||
)
|
||||
.span(Dir::RIGHT, [1, 1, 1]),
|
||||
);
|
||||
let test_button = Rect::new(Color::PURPLE)
|
||||
.radius(30)
|
||||
.on(Sense::PressStart, move |ui, _| {
|
||||
println!("{}", ui.num_widgets());
|
||||
})
|
||||
.region(
|
||||
UiRegion::corner(Corner::BotRight)
|
||||
.size((150, 150))
|
||||
.shifted((-75, -75)),
|
||||
);
|
||||
|
||||
let s = span_add.clone();
|
||||
let del_button = Rect::new(Color::RED)
|
||||
.radius(30)
|
||||
.on(Sense::PressStart, move |ui, _| {
|
||||
ui[&s].children.pop();
|
||||
})
|
||||
.region(
|
||||
UiRegion::corner(Corner::BotLeft)
|
||||
.size((150, 150))
|
||||
.shifted((75, -75)),
|
||||
);
|
||||
ui.set_base(
|
||||
(
|
||||
buttons,
|
||||
(
|
||||
pad_test.pad(10).id(&main),
|
||||
Rect::new(Color::PURPLE).radius(30).region(
|
||||
UiRegion::bottom_right()
|
||||
.size((150, 150))
|
||||
.shifted((-75, -75)),
|
||||
),
|
||||
)
|
||||
.stack(),
|
||||
tabs,
|
||||
(pad_test.pad(10).id(&main), test_button, del_button).stack(),
|
||||
)
|
||||
.span(Dir::DOWN, [fixed(40), ratio(1)]),
|
||||
);
|
||||
(ui, UiIds { test })
|
||||
(ui, UiIds { span_add })
|
||||
}
|
||||
|
||||
pub fn new(window: Arc<Window>, ui: UiIds) -> Self {
|
||||
@@ -151,7 +165,7 @@ impl Client {
|
||||
WindowEvent::KeyboardInput { event, .. } => {
|
||||
if event.state.is_pressed() {
|
||||
let child = ui.add(Rect::new(Color::YELLOW)).erase_type();
|
||||
ui[&self.ui.test].children.push((child, fixed(20.0)));
|
||||
ui[&self.ui.span_add].children.push((child, fixed(20.0)));
|
||||
self.renderer.window().request_redraw();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user