From d35f474f60cba0676d909b38f777099cac2b7d64 Mon Sep 17 00:00:00 2001 From: Thomas Churchman Date: Fri, 30 Aug 2024 14:37:54 +0200 Subject: [PATCH] masonry: when querying widgets by pos, in case of overlap take last This takes the last child as returned by Widget::children_ids, i.e., the last in "z-order". --- masonry/src/widget/widget_ref.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/masonry/src/widget/widget_ref.rs b/masonry/src/widget/widget_ref.rs index 2f85ea5ba..56d4d1e71 100644 --- a/masonry/src/widget/widget_ref.rs +++ b/masonry/src/widget/widget_ref.rs @@ -170,6 +170,9 @@ impl<'w> WidgetRef<'w, dyn Widget> { /// Recursively find innermost widget at given position. /// + /// If multiple overlapping children of a widget contain the given position in their layout + /// boxes, the last child as determined by [`Widget::children_ids`] is chosen. + /// /// **pos** - the position in local coordinates (zero being the top-left of the /// inner widget). pub fn find_widget_at_pos(&self, pos: Point) -> Option> { @@ -190,7 +193,7 @@ impl<'w> WidgetRef<'w, dyn Widget> { } } // TODO - Use Widget::get_child_at_pos method - if let Some(child) = innermost_widget.children().into_iter().find(|child| { + if let Some(child) = innermost_widget.children().into_iter().rev().find(|child| { !child.widget.skip_pointer() && child.state().window_layout_rect().contains(pos) }) { innermost_widget = child;