Skip to content

Commit

Permalink
wip: provide WidgetRef to Widget::get_child_at_pos
Browse files Browse the repository at this point in the history
  • Loading branch information
tomcur committed Sep 3, 2024
1 parent 50768e1 commit 48c8325
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions masonry/src/widget/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<WidgetRef<'w, dyn Widget>> {
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?
Expand Down Expand Up @@ -367,10 +370,10 @@ impl Widget for Box<dyn Widget> {

fn get_child_at_pos<'w>(
&self,
children: &[WidgetRef<'w, dyn Widget>],
widget_ref: WidgetRef<'w, dyn Widget>,
pos: Point,
) -> Option<WidgetRef<'w, dyn Widget>> {
self.deref().get_child_at_pos(children, pos)
self.deref().get_child_at_pos(widget_ref, pos)
}

fn as_any(&self) -> &dyn Any {
Expand Down
2 changes: 1 addition & 1 deletion masonry/src/widget/widget_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 48c8325

Please sign in to comment.