Use group overlay for containers w/ children

This commit is contained in:
Cory Forsstrom 2023-01-17 10:12:51 -08:00
parent 3c866c15aa
commit b2a3a85acb
No known key found for this signature in database
GPG key ID: 1DFE170A4415C9F5
2 changed files with 13 additions and 8 deletions

View file

@ -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::<Vec<_>>();
(!children.is_empty()).then(|| Group::with_children(children).overlay())
}

View file

@ -35,7 +35,7 @@ pub use iced_style::pane_grid::{Line, StyleSheet};
use crate::event::{self, Event};
use crate::layout;
use crate::mouse;
use crate::overlay;
use crate::overlay::{self, Group};
use crate::renderer;
use crate::touch;
use crate::widget;
@ -450,14 +450,17 @@ where
layout: Layout<'_>,
renderer: &Renderer,
) -> Option<overlay::Element<'_, Message, Renderer>> {
self.contents
let children = self
.contents
.iter_mut()
.zip(&mut tree.children)
.zip(layout.children())
.filter_map(|(((_, pane), tree), layout)| {
pane.overlay(tree, layout, renderer)
.filter_map(|(((_, content), state), layout)| {
content.overlay(state, layout, renderer)
})
.next()
.collect::<Vec<_>>();
(!children.is_empty()).then(|| Group::with_children(children).overlay())
}
}