From 3c866c15aa1db944a2056f01449a2fbdda2f5abb Mon Sep 17 00:00:00 2001 From: Cory Forsstrom Date: Tue, 17 Jan 2023 10:01:17 -0800 Subject: Add group overlay element --- native/src/overlay.rs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'native/src/overlay.rs') diff --git a/native/src/overlay.rs b/native/src/overlay.rs index 22f8b6ec..0b1e8daf 100644 --- a/native/src/overlay.rs +++ b/native/src/overlay.rs @@ -1,9 +1,11 @@ //! Display interactive elements on top of other widgets. mod element; +mod group; pub mod menu; pub use element::Element; +pub use group::Group; pub use menu::Menu; use crate::event::{self, Event}; -- cgit From b2a3a85acb2a0722e90c46b70d574f1d676da9d1 Mon Sep 17 00:00:00 2001 From: Cory Forsstrom Date: Tue, 17 Jan 2023 10:12:51 -0800 Subject: Use group overlay for containers w/ children --- native/src/overlay.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'native/src/overlay.rs') diff --git a/native/src/overlay.rs b/native/src/overlay.rs index 0b1e8daf..e7394494 100644 --- a/native/src/overlay.rs +++ b/native/src/overlay.rs @@ -91,7 +91,7 @@ where } } -/// Obtains the first overlay [`Element`] found in the given children. +/// Returns a [`Group`] of overlay [`Element`] children. /// /// This method will generally only be used by advanced users that are /// implementing the [`Widget`](crate::Widget) trait. @@ -104,12 +104,14 @@ pub fn from_children<'a, Message, Renderer>( where Renderer: crate::Renderer, { - children + let children = children .iter_mut() .zip(&mut tree.children) .zip(layout.children()) .filter_map(|((child, state), layout)| { child.as_widget_mut().overlay(state, layout, renderer) }) - .next() + .collect::>(); + + (!children.is_empty()).then(|| Group::with_children(children).overlay()) } -- cgit From 3ab679725526bd095cc1a160705312b16c408b92 Mon Sep 17 00:00:00 2001 From: Cory Forsstrom Date: Tue, 17 Jan 2023 11:12:10 -0800 Subject: New method to determine if overlay contains cursor This is needed for "container" overlay's such as `Group` which should only consider it's childrens layouts and not it's own when determining if the cursor is captured by the overlay. --- native/src/overlay.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'native/src/overlay.rs') diff --git a/native/src/overlay.rs b/native/src/overlay.rs index e7394494..16d8bb31 100644 --- a/native/src/overlay.rs +++ b/native/src/overlay.rs @@ -89,6 +89,15 @@ where ) -> mouse::Interaction { mouse::Interaction::Idle } + + /// Whether the [`Overlay`] contains the cursor + fn contains_cursor( + &self, + layout: Layout<'_>, + cursor_position: Point, + ) -> bool { + layout.bounds().contains(cursor_position) + } } /// Returns a [`Group`] of overlay [`Element`] children. -- cgit From be860508a9deed1f4583e045790eb9ddd74d07d5 Mon Sep 17 00:00:00 2001 From: Cory Forsstrom Date: Tue, 17 Jan 2023 17:20:53 -0800 Subject: Rename method to is_over --- native/src/overlay.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'native/src/overlay.rs') diff --git a/native/src/overlay.rs b/native/src/overlay.rs index 16d8bb31..1c3d0fb9 100644 --- a/native/src/overlay.rs +++ b/native/src/overlay.rs @@ -90,12 +90,8 @@ where mouse::Interaction::Idle } - /// Whether the [`Overlay`] contains the cursor - fn contains_cursor( - &self, - layout: Layout<'_>, - cursor_position: Point, - ) -> bool { + /// Returns true if the cursor is over the [`Overlay`] + fn is_over(&self, layout: Layout<'_>, cursor_position: Point) -> bool { layout.bounds().contains(cursor_position) } } -- cgit From 01c484245be54c1aeb6605659fb0f222856c28da Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 24 Jan 2023 01:59:34 +0100 Subject: Fix some minor documentation inconsistencies --- native/src/overlay.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'native/src/overlay.rs') diff --git a/native/src/overlay.rs b/native/src/overlay.rs index 1c3d0fb9..6cada416 100644 --- a/native/src/overlay.rs +++ b/native/src/overlay.rs @@ -90,7 +90,10 @@ where mouse::Interaction::Idle } - /// Returns true if the cursor is over the [`Overlay`] + /// Returns true if the cursor is over the [`Overlay`]. + /// + /// By default, it returns true if the bounds of the `layout` contain + /// the `cursor_position`. fn is_over(&self, layout: Layout<'_>, cursor_position: Point) -> bool { layout.bounds().contains(cursor_position) } -- cgit