fix view leak and add view count

This commit is contained in:
2025-08-24 22:13:02 -04:00
parent 74d01d14d4
commit 44a8b1cbeb
7 changed files with 41 additions and 18 deletions

View File

@@ -23,7 +23,7 @@ pub struct Client {
pub struct ClientUi {
info: WidgetId<Text>,
old_num: usize,
old_info: String,
}
impl Client {
@@ -153,11 +153,19 @@ impl Client {
del_button.label("del button"),
info_sect.label("info sect"),
)
.stack().label("main stack"),
.stack()
.label("main stack"),
)
.span(Dir::DOWN, [fixed(40), ratio(1)]).label("root"),
.span(Dir::DOWN, [fixed(40), ratio(1)])
.label("root"),
);
(ui, ClientUi { info, old_num: 0 })
(
ui,
ClientUi {
info,
old_info: String::new(),
},
)
}
pub fn new(window: Arc<Window>, ui: ClientUi) -> Self {
@@ -187,10 +195,14 @@ impl Client {
}
_ => (),
}
let num = ui.num_widgets();
if num != self.ui.old_num {
ui[&self.ui.info].content = format!("widgets: {}", num);
self.ui.old_num = num;
let new = format!(
"widgets: {}\nviews: {}",
ui.num_widgets(),
self.renderer.ui.view_count()
);
if new != self.ui.old_info {
ui[&self.ui.info].content = new.clone();
self.ui.old_info = new;
}
if ui.needs_redraw() {
self.renderer.window().request_redraw();