raui_core/widget/component/containers/
variant_box.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
use crate::{
    widget::{context::WidgetContext, node::WidgetNode},
    PropsData,
};
use serde::{Deserialize, Serialize};

#[derive(PropsData, Debug, Default, Clone, Serialize, Deserialize)]
#[props_data(crate::props::PropsData)]
#[prefab(crate::Prefab)]
pub struct VariantBoxProps {
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub variant_name: Option<String>,
}

pub fn variant_box(context: WidgetContext) -> WidgetNode {
    let WidgetContext {
        props,
        mut named_slots,
        ..
    } = context;

    let VariantBoxProps { variant_name } = props.read_cloned_or_default();

    if let Some(variant_name) = variant_name {
        named_slots.remove(&variant_name).unwrap_or_default()
    } else {
        Default::default()
    }
}