From 48c8325ac111725817062e416013be7fbb78a5d3 Mon Sep 17 00:00:00 2001 From: Thomas Churchman Date: Fri, 30 Aug 2024 17:33:53 +0200 Subject: [PATCH] wip: provide `WidgetRef` to `Widget::get_child_at_pos` --- masonry/src/widget/widget.rs | 15 +++++++++------ masonry/src/widget/widget_ref.rs | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) 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 {