diff options
| author | 2023-01-24 02:14:50 +0100 | |
|---|---|---|
| committer | 2023-01-24 02:14:50 +0100 | |
| commit | 2dea5fe058f825db1a03cfce1fa84efbcb46a906 (patch) | |
| tree | 1991b0c69784d37671686776a0296f047ac16731 /native/src/overlay.rs | |
| parent | eb4fcba05fb54741289a28ec9b921c90c9acc7fd (diff) | |
| parent | 01c484245be54c1aeb6605659fb0f222856c28da (diff) | |
| download | iced-2dea5fe058f825db1a03cfce1fa84efbcb46a906.tar.gz iced-2dea5fe058f825db1a03cfce1fa84efbcb46a906.tar.bz2 iced-2dea5fe058f825db1a03cfce1fa84efbcb46a906.zip | |
Merge pull request #1655 from tarkah/feat/group-overlay
Group Overlay
Diffstat (limited to 'native/src/overlay.rs')
| -rw-r--r-- | native/src/overlay.rs | 18 | 
1 files changed, 15 insertions, 3 deletions
| diff --git a/native/src/overlay.rs b/native/src/overlay.rs index 22f8b6ec..6cada416 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}; @@ -87,9 +89,17 @@ where      ) -> mouse::Interaction {          mouse::Interaction::Idle      } + +    /// 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) +    }  } -/// 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. @@ -102,12 +112,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::<Vec<_>>(); + +    (!children.is_empty()).then(|| Group::with_children(children).overlay())  } | 
