raui_material/component/containers/
modal_paper.rs1use 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 if let Ok(props) = shared_props.read::<ThemeProps>() {
61 if let Some(c) = props.modal_shadow_variants.get(&shadow_variant) {
62 color = *c;
63 }
64 }
65 }
66
67 let shadow_image_props = ImageBoxProps {
68 material: ImageBoxMaterial::Color(ImageBoxColor {
69 color,
70 ..Default::default()
71 }),
72 ..Default::default()
73 };
74
75 make_widget!(portal_box)
76 .key(key)
77 .named_slot(
78 "content",
79 make_widget!(content_box)
80 .key("container")
81 .listed_slot(
82 make_widget!(navigation_barrier)
83 .key("shadow-barrier")
84 .named_slot(
85 "content",
86 make_widget!(image_box)
87 .key("shadow-image")
88 .with_props(shadow_image_props),
89 ),
90 )
91 .listed_slot(content),
92 )
93 .into()
94}