Skip to main content

iced_widget/pane_grid/
controls.rs

1use crate::container;
2use crate::core::{self, Element, Widget};
3
4/// The controls of a [`Pane`].
5///
6/// [`Pane`]: super::Pane
7pub struct Controls<'a, Message, Theme = crate::Theme, Renderer = crate::Renderer>
8where
9    Theme: container::Catalog,
10{
11    pub(super) full: Element<'a, Message, Theme, Renderer>,
12    pub(super) compact: Option<Element<'a, Message, Theme, Renderer>>,
13}
14
15impl<'a, Message, Theme, Renderer> Controls<'a, Message, Theme, Renderer>
16where
17    Theme: container::Catalog,
18{
19    /// Creates a new [`Controls`] with the given content.
20    pub fn new(content: impl Widget<Message, Theme, Renderer> + 'a) -> Self {
21        Self {
22            full: content._boxed(),
23            compact: None,
24        }
25    }
26
27    /// Creates a new [`Controls`] with a full and compact variant.
28    /// If there is not enough room to show the full variant without overlap,
29    /// then the compact variant will be shown instead.
30    pub fn dynamic(
31        full: impl Widget<Message, Theme, Renderer> + 'a,
32        compact: impl Widget<Message, Theme, Renderer> + 'a,
33    ) -> Self {
34        Self {
35            full: full._boxed(),
36            compact: Some(compact._boxed()),
37        }
38    }
39}
40
41impl<'a, Message, Theme, Renderer> From<Element<'a, Message, Theme, Renderer>>
42    for Controls<'a, Message, Theme, Renderer>
43where
44    Message: 'a,
45    Theme: container::Catalog + 'a,
46    Renderer: core::Renderer,
47{
48    fn from(value: Element<'a, Message, Theme, Renderer>) -> Self {
49        Self::new(value)
50    }
51}