diff --git a/core/src/orientation/pos.rs b/core/src/orientation/pos.rs index 70a867a..423de52 100644 --- a/core/src/orientation/pos.rs +++ b/core/src/orientation/pos.rs @@ -279,10 +279,10 @@ impl UiSpan { } pub fn outside(&self, parent: &Self) -> Option { - match (self.start.outside(parent), self.end.outside(parent)) { - (Some(start), Some(end)) => Some(Self { start, end }), - _ => None, - } + Some(Self { + start: self.start.outside(parent)?, + end: self.end.outside(parent)?, + }) } pub const fn len(&self) -> UiScalar { diff --git a/core/src/ui/painter.rs b/core/src/ui/painter.rs index 6ed9cfe..8d229c8 100644 --- a/core/src/ui/painter.rs +++ b/core/src/ui/painter.rs @@ -71,34 +71,33 @@ impl<'a> Painter<'a> { } /// Draws a widget within this widget's region. - pub fn widget(&mut self, id: &StrongWidget) -> DrawResult<'_, 'a> { + pub fn widget<'s, W: ?Sized>(&'s mut self, id: &'s StrongWidget) -> DrawResult<'s, 'a, W> { self.widget_at(id, self.region) } /// Draws a widget somewhere within this one. Drawing one a second time /// gives it a new box, keeping the drawing it already has where it can. - pub fn widget_within( - &mut self, - id: &StrongWidget, + pub fn widget_within<'s, W: ?Sized>( + &'s mut self, + id: &'s StrongWidget, region: UiRegion, - ) -> DrawResult<'_, 'a> { + ) -> DrawResult<'s, 'a, W> { let region = region.within(&self.region); self.widget_at(id, region) } - fn widget_at( - &mut self, - id: &StrongWidget, + fn widget_at<'s, W: ?Sized>( + &'s mut self, + id: &'s StrongWidget, region: UiRegion, - ) -> DrawResult<'_, 'a> { - let child = id.id(); + ) -> DrawResult<'s, 'a, W> { // A child listed twice would be moved twice. - if !self.children.contains(&child) { - self.children.push(child); + if !self.children.contains(&id.id()) { + self.children.push(id.id()); } let size = self.state.draw_inner( self.layer, - child, + id.id(), region, Some(self.id), self.mask, @@ -106,7 +105,7 @@ impl<'a> Painter<'a> { self.rsc, ); DrawResult { - child, + child: id, painter: self, size, } @@ -116,13 +115,13 @@ impl<'a> Painter<'a> { /// Asking counts as reading its size. pub fn size_hint(&mut self, id: &StrongWidget, axis: Axis) -> Option { let hint = self.rsc.widgets().get_dyn(id.id())?.size_hint(axis)?; - self.depend_on_size(id.id()); + self.depend_on_size(id); Some(hint) } - fn depend_on_size(&mut self, child: WidgetId) { - if !self.size_deps.contains(&child) { - self.size_deps.push(child); + fn depend_on_size(&mut self, child: &StrongWidget) { + if !self.size_deps.contains(&child.id()) { + self.size_deps.push(child.id()); } } @@ -202,13 +201,13 @@ impl<'a> Painter<'a> { /// A child that has just been drawn. Reading its size records that this /// widget's own size depends on it; dropping it without reading draws the /// child and leaves the parent independent of what it came to. -pub struct DrawResult<'p, 'a> { +pub struct DrawResult<'p, 'a, W: ?Sized> { painter: &'p mut Painter<'a>, - child: WidgetId, + child: &'p StrongWidget, size: Size, } -impl DrawResult<'_, '_> { +impl DrawResult<'_, '_, W> { pub fn size(self) -> Size { self.painter.depend_on_size(self.child); self.size