summaryrefslogtreecommitdiffstats
path: root/native/src/widget/pane_grid.rs
diff options
context:
space:
mode:
authorLibravatar Nick Senger <dev@nsenger.com>2023-02-09 21:16:12 -0800
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-02-16 16:15:45 +0100
commit84a6038961a5ebd1366ae8c6ba9e44be07d37f16 (patch)
tree37b117701d58380112f187f377dc06477c4b0c70 /native/src/widget/pane_grid.rs
parent6a683b603d555c9d7f589f99738d4151192b91ef (diff)
downloadiced-84a6038961a5ebd1366ae8c6ba9e44be07d37f16.tar.gz
iced-84a6038961a5ebd1366ae8c6ba9e44be07d37f16.tar.bz2
iced-84a6038961a5ebd1366ae8c6ba9e44be07d37f16.zip
provide ID to operation.container in applicable widgets
Diffstat (limited to 'native/src/widget/pane_grid.rs')
-rw-r--r--native/src/widget/pane_grid.rs53
1 files changed, 44 insertions, 9 deletions
diff --git a/native/src/widget/pane_grid.rs b/native/src/widget/pane_grid.rs
index eb04c0ba..6a65754e 100644
--- a/native/src/widget/pane_grid.rs
+++ b/native/src/widget/pane_grid.rs
@@ -101,6 +101,7 @@ where
Renderer: crate::Renderer,
Renderer::Theme: StyleSheet + container::StyleSheet,
{
+ id: Option<Id>,
contents: Contents<'a, Content<'a, Message, Renderer>>,
width: Length,
height: Length,
@@ -147,6 +148,7 @@ where
};
Self {
+ id: None,
contents,
width: Length::Fill,
height: Length::Fill,
@@ -158,6 +160,12 @@ where
}
}
+ /// Sets the [`Id`] of the [`PaneGrid`].
+ pub fn id(mut self, id: Id) -> Self {
+ self.id = Some(id);
+ self
+ }
+
/// Sets the width of the [`PaneGrid`].
pub fn width(mut self, width: Length) -> Self {
self.width = width;
@@ -297,15 +305,18 @@ where
renderer: &Renderer,
operation: &mut dyn widget::Operation<Message>,
) {
- operation.container(None, &mut |operation| {
- self.contents
- .iter()
- .zip(&mut tree.children)
- .zip(layout.children())
- .for_each(|(((_pane, content), state), layout)| {
- content.operate(state, layout, renderer, operation);
- })
- });
+ operation.container(
+ self.id.as_ref().map(|id| &id.0),
+ &mut |operation| {
+ self.contents
+ .iter()
+ .zip(&mut tree.children)
+ .zip(layout.children())
+ .for_each(|(((_pane, content), state), layout)| {
+ content.operate(state, layout, renderer, operation);
+ })
+ },
+ );
}
fn on_event(
@@ -996,3 +1007,27 @@ impl<'a, T> Contents<'a, T> {
matches!(self, Self::Maximized(..))
}
}
+
+/// The identifier of a [`PaneGrid`].
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub struct Id(widget::Id);
+
+impl Id {
+ /// Creates a custom [`Id`].
+ pub fn new(id: impl Into<std::borrow::Cow<'static, str>>) -> Self {
+ Self(widget::Id::new(id))
+ }
+
+ /// Creates a unique [`Id`].
+ ///
+ /// This function produces a different [`Id`] every time it is called.
+ pub fn unique() -> Self {
+ Self(widget::Id::unique())
+ }
+}
+
+impl From<Id> for widget::Id {
+ fn from(id: Id) -> Self {
+ id.0
+ }
+}