strong & weak widgets

This commit is contained in:
2025-12-11 07:16:06 -05:00
parent a85e129026
commit 36668c82f4
19 changed files with 293 additions and 294 deletions

View File

@@ -387,17 +387,17 @@ impl<'a, 'c> Painter<'a, 'c> {
}
/// Draws a widget within this widget's region.
pub fn widget<W>(&mut self, id: &WidgetHandle<W>) {
pub fn widget<W: ?Sized>(&mut self, id: &WidgetHandle<W>) {
self.widget_at(id, self.region);
}
/// Draws a widget somewhere within this one.
/// Useful for drawing child widgets in select areas.
pub fn widget_within<W>(&mut self, id: &WidgetHandle<W>, region: UiRegion) {
pub fn widget_within<W: ?Sized>(&mut self, id: &WidgetHandle<W>, region: UiRegion) {
self.widget_at(id, region.within(&self.region));
}
fn widget_at<W>(&mut self, id: &WidgetHandle<W>, region: UiRegion) {
fn widget_at<W: ?Sized>(&mut self, id: &WidgetHandle<W>, region: UiRegion) {
self.children.push(id.id());
self.ctx
.draw_inner(self.layer, id.id(), region, Some(self.id), self.mask, None);
@@ -427,11 +427,11 @@ impl<'a, 'c> Painter<'a, 'c> {
self.region
}
pub fn size<W>(&mut self, id: &WidgetHandle<W>) -> Size {
pub fn size<W: ?Sized>(&mut self, id: &WidgetHandle<W>) -> Size {
self.size_ctx().size(id)
}
pub fn len_axis<W>(&mut self, id: &WidgetHandle<W>, axis: Axis) -> Len {
pub fn len_axis<W: ?Sized>(&mut self, id: &WidgetHandle<W>, axis: Axis) -> Len {
match axis {
Axis::X => self.size_ctx().width(id),
Axis::Y => self.size_ctx().height(id),
@@ -550,22 +550,22 @@ impl SizeCtx<'_> {
len
}
pub fn width<W>(&mut self, id: &WidgetHandle<W>) -> Len {
pub fn width<W: ?Sized>(&mut self, id: &WidgetHandle<W>) -> Len {
self.width_inner(id.id())
}
pub fn height<W>(&mut self, id: &WidgetHandle<W>) -> Len {
pub fn height<W: ?Sized>(&mut self, id: &WidgetHandle<W>) -> Len {
self.height_inner(id.id())
}
pub fn len_axis<W>(&mut self, id: &WidgetHandle<W>, axis: Axis) -> Len {
pub fn len_axis<W: ?Sized>(&mut self, id: &WidgetHandle<W>, axis: Axis) -> Len {
match axis {
Axis::X => self.width(id),
Axis::Y => self.height(id),
}
}
pub fn size<W>(&mut self, id: &WidgetHandle<W>) -> Size {
pub fn size<W: ?Sized>(&mut self, id: &WidgetHandle<W>) -> Size {
Size {
x: self.width(id),
y: self.height(id),