~tm85/lintuini

ref: 281900fe61d7df4c18826576a3ed56064e914e45 lintuini/src/elements/container.rs -rw-r--r-- 997 bytes
281900feTerraMaster85 fmt: all 26 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use ratatui_core::layout;
use ratatui_core::terminal::Frame;

use crate::elements::macros::*;
use crate::elements::{Element, ElementWithChildren};
use crate::error;

#[derive(Default)]
pub struct Container<'a> {
    children: Vec<Box<dyn Element>>,
    constraint: layout::Constraint,
    layout: layout::Layout,
    widgets: ContainerWidgets<'a>,
}

#[derive(Clone, Default)]
struct ContainerWidgets<'a> {
    block0: ratatui_widgets::block::Block<'a>,
}

basic_config_methods!(Container<'_>);
element_with_children!(Container<'_>);

impl Element for Container<'_> {
    #[inline(always)]
    fn constraint(&self) -> layout::Constraint {
        self.constraint
    }

    fn render(
        &self,
        frm: &mut Frame,
        rect: layout::Rect,
    ) -> Result<(), error::LintuiniError> {
        frm.render_widget(&self.widgets.block0, rect);

        for (el, r) in self.children.iter().zip(&*self.layout.split(rect)) {
            el.render(frm, *r)?;
        }

        Ok(())
    }
}