raui_material/component/containers/
modal_paper.rs

1use crate::theme::ThemeProps;
2use raui_core::{
3    PropsData, make_widget, unpack_named_slots,
4    widget::{
5        component::{
6            containers::{content_box::content_box, portal_box::portal_box},
7            image_box::{ImageBoxProps, image_box},
8            interactive::navigation::navigation_barrier,
9        },
10        context::WidgetContext,
11        node::WidgetNode,
12        unit::image::{ImageBoxColor, ImageBoxMaterial},
13        utils::Color,
14    },
15};
16use serde::{Deserialize, Serialize};
17
18#[derive(PropsData, Debug, Clone, Serialize, Deserialize)]
19#[props_data(raui_core::props::PropsData)]
20#[prefab(raui_core::Prefab)]
21pub struct ModalPaperProps {
22    #[serde(default = "ModalPaperProps::default_shadow_shown")]
23    pub shadow_shown: bool,
24    #[serde(default)]
25    pub shadow_variant: String,
26}
27
28impl ModalPaperProps {
29    fn default_shadow_shown() -> bool {
30        true
31    }
32}
33
34impl Default for ModalPaperProps {
35    fn default() -> Self {
36        Self {
37            shadow_shown: Self::default_shadow_shown(),
38            shadow_variant: Default::default(),
39        }
40    }
41}
42
43pub fn modal_paper(context: WidgetContext) -> WidgetNode {
44    let WidgetContext {
45        key,
46        props,
47        shared_props,
48        named_slots,
49        ..
50    } = context;
51    unpack_named_slots!(named_slots => content);
52
53    let ModalPaperProps {
54        shadow_shown,
55        shadow_variant,
56    } = props.read_cloned_or_default();
57
58    let mut color = Color::transparent();
59    if shadow_shown
60        && let Ok(props) = shared_props.read::<ThemeProps>()
61        && let Some(c) = props.modal_shadow_variants.get(&shadow_variant)
62    {
63        color = *c;
64    }
65
66    let shadow_image_props = ImageBoxProps {
67        material: ImageBoxMaterial::Color(ImageBoxColor {
68            color,
69            ..Default::default()
70        }),
71        ..Default::default()
72    };
73
74    make_widget!(portal_box)
75        .key(key)
76        .named_slot(
77            "content",
78            make_widget!(content_box)
79                .key("container")
80                .listed_slot(
81                    make_widget!(navigation_barrier)
82                        .key("shadow-barrier")
83                        .named_slot(
84                            "content",
85                            make_widget!(image_box)
86                                .key("shadow-image")
87                                .with_props(shadow_image_props),
88                        ),
89                )
90                .listed_slot(content),
91        )
92        .into()
93}