Skip to main content

ansiq_widgets/
pane.rs

1use ansiq_core::{Element, ElementKind, Layout, Length, PaneProps};
2
3pub struct Pane<Message = ()> {
4    element: Element<Message>,
5}
6
7impl<Message> Pane<Message> {
8    pub fn new() -> Self {
9        Self {
10            element: Element::new(ElementKind::Pane(PaneProps { title: None })).with_layout(
11                Layout {
12                    width: Length::Fill,
13                    height: Length::Fill,
14                },
15            ),
16        }
17    }
18
19    pub fn title(mut self, title: impl Into<String>) -> Self {
20        if let ElementKind::Pane(props) = &mut self.element.kind {
21            props.title = Some(title.into());
22        }
23        self
24    }
25
26    pub fn child(mut self, child: Element<Message>) -> Self {
27        self.element.children.push(child);
28        self
29    }
30
31    pub fn children<I>(mut self, children: I) -> Self
32    where
33        I: IntoIterator<Item = Element<Message>>,
34    {
35        self.element.children.extend(children);
36        self
37    }
38
39    pub fn layout(mut self, layout: Layout) -> Self {
40        self.element.layout = layout;
41        self
42    }
43
44    pub fn build(self) -> Element<Message> {
45        self.element
46    }
47}