blob: f40742e3e5223ada80945f4658241b7a97d511cd (
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
32
33
34
35
36
37
|
use tui::layout::Rect;
use super::LayoutNode;
pub struct DrawContext<'a> {
current_node: &'a LayoutNode,
current_offset: (u16, u16),
}
impl<'a> DrawContext<'_> {
/// Creates a new [`DrawContext`], with the offset set to `(0, 0)`.
pub(crate) fn root(root: &'a LayoutNode) -> DrawContext<'a> {
DrawContext {
current_node: root,
current_offset: (0, 0),
}
}
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,
})
}
}
|