freya_core/
node_state_snapshot.rs

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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use freya_native_core::real_dom::NodeImmutable;

use crate::{
    dom::DioxusNode,
    states::{
        AccessibilityState,
        CursorState,
        FontStyleState,
        LayoutState,
        StyleState,
        SvgState,
        TransformState,
    },
};

pub trait NodeStateSnapshot {
    fn state_snapshot(&self) -> NodeState;
}

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, PartialEq, Debug)]
pub struct NodeState {
    pub cursor: CursorState,
    pub font_style: FontStyleState,
    pub layout: LayoutState,
    pub style: StyleState,
    pub transform: TransformState,
    pub accessibility: AccessibilityState,
    pub svg: SvgState,
}

impl NodeStateSnapshot for DioxusNode<'_> {
    fn state_snapshot(&self) -> NodeState {
        let cursor = self
            .get::<CursorState>()
            .as_deref()
            .cloned()
            .unwrap_or_default();
        let font_style = self
            .get::<FontStyleState>()
            .as_deref()
            .cloned()
            .unwrap_or_default();
        let size = self
            .get::<LayoutState>()
            .as_deref()
            .cloned()
            .unwrap_or_default();
        let style = self
            .get::<StyleState>()
            .as_deref()
            .cloned()
            .unwrap_or_default();
        let transform = self
            .get::<TransformState>()
            .as_deref()
            .cloned()
            .unwrap_or_default();
        let accessibility = self
            .get::<AccessibilityState>()
            .as_deref()
            .cloned()
            .unwrap_or_default();
        let svg = self
            .get::<SvgState>()
            .as_deref()
            .cloned()
            .unwrap_or_default();

        NodeState {
            cursor,
            font_style,
            layout: size,
            style,
            transform,
            accessibility,
            svg,
        }
    }
}