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
use core::{
    ecs::{Component, FlaggedStorage, VecStorage},
    prefab::{Prefab, PrefabComponent},
    Ignite,
};
use raui_core::PrefabValue;
use serde::{Deserialize, Serialize};

#[derive(Ignite, Debug, Clone, Serialize, Deserialize)]
pub struct UserInterfaceView {
    #[serde(default)]
    app_id: String,
    #[serde(default)]
    root: PrefabValue,
    #[serde(default)]
    pub input_order: usize,
    #[serde(default)]
    pub capture_input: bool,
    #[serde(default)]
    pub deselect_when_no_button_found: bool,
    #[serde(skip)]
    #[serde(default = "UserInterfaceView::default_dirty")]
    #[ignite(ignore)]
    pub(crate) dirty: bool,
}

impl Default for UserInterfaceView {
    fn default() -> Self {
        Self::new(Default::default())
    }
}

impl UserInterfaceView {
    fn default_dirty() -> bool {
        true
    }

    pub fn new(app_id: String) -> Self {
        Self {
            app_id,
            root: Default::default(),
            input_order: 0,
            capture_input: false,
            deselect_when_no_button_found: false,
            dirty: true,
        }
    }

    pub fn app_id(&self) -> &str {
        &self.app_id
    }

    pub fn root(&self) -> &PrefabValue {
        &self.root
    }

    pub fn set_root(&mut self, root: PrefabValue) {
        self.root = root;
        self.dirty = true;
    }
}

impl Component for UserInterfaceView {
    type Storage = FlaggedStorage<Self, VecStorage<Self>>;
}

impl Prefab for UserInterfaceView {}
impl PrefabComponent for UserInterfaceView {}