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
use crate::widget::{ node::{WidgetNode, WidgetNodePrefab}, unit::{WidgetUnit, WidgetUnitData}, WidgetId, }; use serde::{Deserialize, Serialize}; use std::convert::TryFrom; #[derive(Debug, Default, Clone, Serialize, Deserialize)] pub struct AreaBox { #[serde(default)] pub id: WidgetId, #[serde(default)] pub slot: Box<WidgetUnit>, } impl WidgetUnitData for AreaBox { fn id(&self) -> &WidgetId { &self.id } fn get_children(&self) -> Vec<&WidgetUnit> { vec![&self.slot] } } impl TryFrom<AreaBoxNode> for AreaBox { type Error = (); fn try_from(node: AreaBoxNode) -> Result<Self, Self::Error> { let AreaBoxNode { id, slot, .. } = node; Ok(Self { id, slot: Box::new(WidgetUnit::try_from(*slot)?), }) } } #[derive(Debug, Default, Clone)] pub struct AreaBoxNode { pub id: WidgetId, pub slot: Box<WidgetNode>, } impl Into<WidgetNode> for AreaBoxNode { fn into(self) -> WidgetNode { WidgetNode::Unit(self.into()) } } #[derive(Debug, Default, Clone, Serialize, Deserialize)] pub(crate) struct AreaBoxNodePrefab { #[serde(default)] pub id: WidgetId, #[serde(default)] pub slot: Box<WidgetNodePrefab>, }