1use std::cell::RefCell;
2
3use crate::storage::Storage;
4use zintl_ui_render::{Metrics, Position, RenderContent, RenderObject};
5
6pub type Generator = Box<dyn Fn(&mut Storage) -> RenderObject>;
7
8#[derive(Default)]
10pub struct Context {
11 children: RefCell<Vec<Generator>>,
12}
13
14impl std::fmt::Debug for Context {
15 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
16 write!(f, "Context {{ ... }}")
17 }
18}
19
20impl Context {
21 pub fn new() -> Self {
22 Context {
23 children: Vec::new().into(),
24 }
25 }
26 pub fn set_style_property(&self) {}
27 pub fn render(&self, storage: &mut Storage) -> RenderObject {
28 let children = self.children.borrow();
29 let mut objs = Vec::new();
30 for child in &*children {
31 objs.push(child(storage));
32 }
33 let robj = RenderObject::new(RenderContent::Empty, Position::new(0.0, 0.0), Metrics::Auto);
35 robj.set_children(objs);
36 robj
37 }
38 pub fn set_children(&self, children: Vec<Generator>) {
39 self.children.replace(children);
40 }
41}