summaryrefslogtreecommitdiffstats
path: root/src/tuice/context.rs
blob: 43540e44e50fe93ab8a22482e288b278a51c9a91 (plain)
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
use tui::layout::Rect;

use super::LayoutNode;

pub struct DrawContext<'a> {
    current_node: &'a LayoutNode,
    current_offset: (u16, u16),
}

impl<'a> DrawContext<'_> {
    pub(crate) fn new() {}

    pub(crate) fn rect(&self) -> Rect {
        self.current_node.rect
    }

    pub(crate) fn children(&self) -> impl Iterator<Item = DrawContext<'_>> {
        let new_offset = (
            self.current_offset.0 + self.current_node.rect.x,
            self.current_offset.1 + self.current_node.rect.y,
        );

        self.current_node
            .children
            .iter()
            .map(move |layout_node| DrawContext {
                current_node: layout_node,
                current_offset: new_offset,
            })
    }
}