anathema_widgets/nodes/
mod.rs1use anathema_templates::blueprints::Blueprint;
2use anathema_value_resolver::Scope;
3use eval::SlotEval;
4
5pub use self::element::Element;
6use self::eval::{ComponentEval, ControlFlowEval, Evaluator, ForLoopEval, SingleEval};
7pub use self::update::update_widget;
8use crate::error::Result;
9use crate::layout::EvalCtx;
10use crate::nodes::eval::WithEval;
11use crate::widget::WidgetTreeView;
12
13pub(crate) mod component;
14pub(crate) mod controlflow;
15pub(crate) mod element;
16pub(crate) mod eval;
17pub(crate) mod loops;
18mod update;
19pub(crate) mod with;
20
21pub enum WidgetGenerator<'bp> {
25 Children(&'bp [Blueprint]),
26 Single,
27 Slot(&'bp [Blueprint]),
28 Loop(&'bp [Blueprint]),
29 ControlFlow,
30 Noop,
31}
32
33#[derive(Debug)]
34pub enum WidgetKind<'bp> {
35 Element(Element<'bp>),
36 For(loops::For<'bp>),
37 With(with::With<'bp>),
38 Iteration(loops::Iteration<'bp>),
39 ControlFlow(controlflow::ControlFlow<'bp>),
40 ControlFlowContainer(u16),
41 Component(component::Component<'bp>),
42 Slot,
43}
44
45#[derive(Debug)]
46pub struct WidgetContainer<'bp> {
47 pub kind: WidgetKind<'bp>,
48 pub(crate) children: &'bp [Blueprint],
49}
50
51impl<'bp> WidgetContainer<'bp> {
52 pub fn new(kind: WidgetKind<'bp>, blueprints: &'bp [Blueprint]) -> Self {
53 Self {
54 kind,
55 children: blueprints,
56 }
57 }
58}
59
60pub fn eval_blueprint<'bp>(
61 blueprint: &'bp Blueprint,
62 ctx: &mut EvalCtx<'_, 'bp>,
63 scope: &Scope<'_, 'bp>,
64 parent: &[u16],
65 tree: &mut WidgetTreeView<'_, 'bp>,
66) -> Result<()> {
67 match blueprint {
68 Blueprint::Single(single) => SingleEval.eval(single, ctx, scope, parent, tree),
69 Blueprint::For(for_loop) => ForLoopEval.eval(for_loop, ctx, scope, parent, tree),
70 Blueprint::With(with) => WithEval.eval(with, ctx, scope, parent, tree),
71 Blueprint::ControlFlow(flow) => ControlFlowEval.eval(flow, ctx, scope, parent, tree),
72 Blueprint::Component(component) => ComponentEval.eval(component, ctx, scope, parent, tree),
73 Blueprint::Slot(blueprints) => SlotEval.eval(blueprints, ctx, scope, parent, tree),
74 }
75}