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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use std::{
cell::RefCell,
ops::{Deref, DerefMut},
rc::{Rc, Weak},
};
use crate::{NativeWidget, VContainerWidget, VNode, VWidget};
pub type StrongNodeType = Rc<RefCell<VNodeType>>;
pub type WeakNodeType = Weak<RefCell<VNodeType>>;
pub enum VNodeType {
Widget(Box<dyn VWidget>),
ContainerWidget(Box<dyn VContainerWidget>),
TopLevelContainerWidget(Box<dyn VContainerWidget>),
}
impl Deref for VNodeType {
type Target = dyn VNode;
fn deref(&self) -> &Self::Target {
match self {
VNodeType::Widget(node) => node.deref().as_ref(),
VNodeType::TopLevelContainerWidget(node) => node.deref().as_ref(),
VNodeType::ContainerWidget(node) => node.deref().as_ref(),
}
}
}
impl DerefMut for VNodeType {
fn deref_mut(&mut self) -> &mut Self::Target {
match self {
VNodeType::Widget(node) => node.deref_mut().as_mut(),
VNodeType::ContainerWidget(node) => node.deref_mut().as_mut(),
VNodeType::TopLevelContainerWidget(node) => node.deref_mut().as_mut(),
}
}
}
impl VNodeType {
pub fn get_native_widget(&self) -> &NativeWidget {
match self {
VNodeType::Widget(w) => w.deref(),
VNodeType::ContainerWidget(w) => w.deref(),
VNodeType::TopLevelContainerWidget(w) => w.deref(),
}
}
}