raui_core/widget/unit/
area.rs

1use crate::widget::{
2    node::{WidgetNode, WidgetNodePrefab},
3    unit::{WidgetUnit, WidgetUnitData},
4    WidgetId,
5};
6use serde::{Deserialize, Serialize};
7use std::convert::TryFrom;
8
9#[derive(Debug, Default, Clone, Serialize, Deserialize)]
10pub struct AreaBox {
11    #[serde(default)]
12    pub id: WidgetId,
13    #[serde(default)]
14    pub slot: Box<WidgetUnit>,
15}
16
17impl WidgetUnitData for AreaBox {
18    fn id(&self) -> &WidgetId {
19        &self.id
20    }
21
22    fn get_children(&self) -> Vec<&WidgetUnit> {
23        vec![&self.slot]
24    }
25}
26
27impl TryFrom<AreaBoxNode> for AreaBox {
28    type Error = ();
29
30    fn try_from(node: AreaBoxNode) -> Result<Self, Self::Error> {
31        let AreaBoxNode { id, slot } = node;
32        Ok(Self {
33            id,
34            slot: Box::new(WidgetUnit::try_from(*slot)?),
35        })
36    }
37}
38
39#[derive(Debug, Default, Clone)]
40pub struct AreaBoxNode {
41    pub id: WidgetId,
42    pub slot: Box<WidgetNode>,
43}
44
45impl From<AreaBoxNode> for WidgetNode {
46    fn from(data: AreaBoxNode) -> Self {
47        Self::Unit(data.into())
48    }
49}
50
51#[derive(Debug, Default, Clone, Serialize, Deserialize)]
52pub(crate) struct AreaBoxNodePrefab {
53    #[serde(default)]
54    pub id: WidgetId,
55    #[serde(default)]
56    pub slot: Box<WidgetNodePrefab>,
57}