async_ui_core/vnode/
node_pass.rs

1use std::rc::Rc;
2
3use crate::{backend::BackendTrait, context::ContextMap, position::PositionIndex, vnode::VNode};
4
5use super::VNodeTrait;
6
7pub struct PassVNode<B: BackendTrait> {
8    parent: Rc<VNode<B>>,
9    index: usize,
10    context: ContextMap,
11}
12
13impl<B: BackendTrait> PassVNode<B> {
14    pub fn new(parent: Rc<VNode<B>>, index: usize) -> Self {
15        let context = parent.get_context_map().to_owned();
16        Self {
17            parent,
18            index,
19            context,
20        }
21    }
22}
23
24impl<B: BackendTrait> VNodeTrait<B> for PassVNode<B> {
25    fn add_child_node(&self, node: B::Node, mut position: PositionIndex) {
26        position.wrap(self.index);
27        self.parent.add_child_node(node, position)
28    }
29
30    fn del_child_node(&self, mut position: PositionIndex) -> B::Node {
31        position.wrap(self.index);
32        self.parent.del_child_node(position)
33    }
34
35    fn get_context_map<'s>(&'s self) -> &'s ContextMap {
36        &self.context
37    }
38}