raui_core/widget/component/containers/
hidden_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
31
32
33
use crate::{
    unpack_named_slots,
    widget::{context::WidgetContext, node::WidgetNode, unit::area::AreaBoxNode},
    PropsData,
};
use serde::{Deserialize, Serialize};

#[derive(PropsData, Debug, Default, Copy, Clone, Serialize, Deserialize)]
#[props_data(crate::props::PropsData)]
#[prefab(crate::Prefab)]
pub struct HiddenBoxProps(#[serde(default)] pub bool);

pub fn hidden_box(context: WidgetContext) -> WidgetNode {
    let WidgetContext {
        id,
        props,
        named_slots,
        ..
    } = context;
    unpack_named_slots!(named_slots => content);

    let HiddenBoxProps(hidden) = props.read_cloned_or_default();

    if hidden {
        Default::default()
    } else {
        AreaBoxNode {
            id: id.to_owned(),
            slot: Box::new(content),
        }
        .into()
    }
}