diff --git a/masonry/src/widget/widget.rs b/masonry/src/widget/widget.rs index bb2afec15..1ba3b9079 100644 --- a/masonry/src/widget/widget.rs +++ b/masonry/src/widget/widget.rs @@ -172,17 +172,20 @@ pub trait Widget: AsAny { /// The child returned is a direct child, not eg a grand-child. The position is in /// relative coordinates. (Eg `(0,0)` is the top-left corner of `self`). /// + /// [`widget_ref`] is a rich reference to the current widget, giving access to this widget's + /// state. + /// /// Has a default implementation, that can be overridden to search children more /// efficiently. /// - /// The child widget references in `children` are in the same order as returned by - /// [`Self::children_ids`]. + /// [`widget_ref`]: WidgetRef fn get_child_at_pos<'w>( &self, - children: &[WidgetRef<'w, dyn Widget>], + widget_ref: WidgetRef<'w, dyn Widget>, pos: Point, ) -> Option> { - children + widget_ref + .children() .iter() // TODO: currently assumes `Self::children_ids` is in increasing "z-order". Picks the // last child in case of overlapping children. Is this the desired behavior? @@ -367,10 +370,10 @@ impl Widget for Box { fn get_child_at_pos<'w>( &self, - children: &[WidgetRef<'w, dyn Widget>], + widget_ref: WidgetRef<'w, dyn Widget>, pos: Point, ) -> Option> { - self.deref().get_child_at_pos(children, pos) + self.deref().get_child_at_pos(widget_ref, pos) } fn as_any(&self) -> &dyn Any { diff --git a/masonry/src/widget/widget_ref.rs b/masonry/src/widget/widget_ref.rs index 90e2260af..9ff265102 100644 --- a/masonry/src/widget/widget_ref.rs +++ b/masonry/src/widget/widget_ref.rs @@ -191,7 +191,7 @@ impl<'w> WidgetRef<'w, dyn Widget> { if let Some(child) = innermost_widget .widget - .get_child_at_pos(&innermost_widget.children(), pos) + .get_child_at_pos(innermost_widget, pos) { innermost_widget = child; } else {