Implement `Widget::overlay` for `PaneGrid`

This commit is contained in:
Héctor Ramón Jiménez 2020-07-10 01:35:58 +02:00
parent 1070b61f34
commit f24e03eae8
2 changed files with 32 additions and 2 deletions

View File

@ -29,8 +29,8 @@ pub use state::{Focus, State};
pub use title_bar::TitleBar;
use crate::{
container, keyboard, layout, mouse, row, text, Clipboard, Element, Event,
Hasher, Layout, Length, Point, Rectangle, Size, Vector, Widget,
container, keyboard, layout, mouse, overlay, row, text, Clipboard, Element,
Event, Hasher, Layout, Length, Point, Rectangle, Size, Vector, Widget,
};
/// A collection of panes distributed using either vertical or horizontal splits
@ -636,6 +636,17 @@ where
element.hash_layout(state);
}
}
fn overlay(
&mut self,
layout: Layout<'_>,
) -> Option<overlay::Element<'_, Message, Renderer>> {
self.elements
.iter_mut()
.zip(layout.children())
.filter_map(|((_, pane), layout)| pane.overlay(layout))
.next()
}
}
/// The renderer of a [`PaneGrid`].

View File

@ -1,5 +1,6 @@
use crate::container;
use crate::layout;
use crate::overlay;
use crate::pane_grid::{self, TitleBar};
use crate::{Clipboard, Element, Event, Hasher, Layout, Point, Size};
@ -184,6 +185,24 @@ where
pub(crate) fn hash_layout(&self, state: &mut Hasher) {
self.body.hash_layout(state);
}
pub(crate) fn overlay(
&mut self,
layout: Layout<'_>,
) -> Option<overlay::Element<'_, Message, Renderer>> {
let body_layout = if self.title_bar.is_some() {
let mut children = layout.children();
// Overlays only allowed in the pane body, for now at least.
let _title_bar_layout = children.next();
children.next()?
} else {
layout
};
self.body.overlay(body_layout)
}
}
impl<'a, T, Message, Renderer> From<T> for Content<'a, Message, Renderer>