fix on_id widget refcount leak (-> memory leak)

This commit is contained in:
2025-12-04 02:59:05 -05:00
parent 84c460a91f
commit e5d0a7e592
6 changed files with 74 additions and 130 deletions

View File

@@ -1,6 +1,6 @@
use crate::{
core::WidgetPtr,
layout::{Len, Painter, SizeCtx, StaticWidgetId, Ui, WidgetId, WidgetIdFn},
layout::{Len, Painter, SizeCtx, Ui, WidgetId, WidgetIdFn},
};
use std::{any::Any, marker::PhantomData};
@@ -26,7 +26,9 @@ pub struct FnTag;
pub trait WidgetLike<Tag> {
type Widget: 'static;
fn add(self, ui: &mut Ui) -> WidgetId<Self::Widget>;
fn with_id<W2>(
self,
f: impl FnOnce(&mut Ui, WidgetId<Self::Widget>) -> WidgetId<W2>,
@@ -39,18 +41,14 @@ pub trait WidgetLike<Tag> {
f(ui, id)
}
}
fn add_static(self, ui: &mut Ui) -> StaticWidgetId<Self::Widget>
where
Self: Sized,
{
self.add(ui).into_static()
}
fn set_root(self, ui: &mut Ui)
where
Self: Sized,
{
ui.set_root(self);
}
fn set_ptr(self, ptr: &WidgetId<WidgetPtr>, ui: &mut Ui)
where
Self: Sized,