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
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
use crate::{
    component::containers::paper::PaperProps,
    theme::{ThemeColor, ThemeProps, ThemeVariant, ThemedImageMaterial, ThemedWidgetProps},
};
use raui_core::prelude::*;

widget_component! {
    button_paper_content(id, key, props, shared_props, named_slots) {
        unpack_named_slots!(named_slots => content);

        let button_props = props.read_cloned_or_default::<ButtonProps>();
        let paper_props = props.read_cloned_or_default::<PaperProps>();
        let themed_props = props.read_cloned_or_default::<ThemedWidgetProps>();

        let items = match themed_props.variant {
            ThemeVariant::ContentOnly => vec![content],
            ThemeVariant::Filled => {
                let button_background = shared_props
                    .map_or_default::<ThemeProps, _, _>(|props| {
                        if button_props.trigger || button_props.context {
                            props
                                .button_backgrounds
                                .get(&paper_props.variant)
                                .cloned()
                                .unwrap_or_default()
                                .trigger
                        } else if button_props.selected {
                            props
                                .button_backgrounds
                                .get(&paper_props.variant)
                                .cloned()
                                .unwrap_or_default()
                                .selected
                        } else {
                            props
                                .button_backgrounds
                                .get(&paper_props.variant)
                                .cloned()
                                .unwrap_or_default()
                                .default
                        }
                    });
                let button_colors = shared_props.map_or_default::<ThemeProps, _, _>(|props| {
                    props.active_colors.clone()
                });
                let image = match button_background {
                    ThemedImageMaterial::Color => {
                        let color = match themed_props.color {
                            ThemeColor::Default => button_colors.main.default.main,
                            ThemeColor::Primary => button_colors.main.primary.main,
                            ThemeColor::Secondary => button_colors.main.secondary.main,
                        };
                        ImageBoxProps {
                            material: ImageBoxMaterial::Color(ImageBoxColor {
                                color,
                                ..Default::default()
                            }),
                            ..Default::default()
                        }
                    }
                    ThemedImageMaterial::Image(material) => {
                        ImageBoxProps {
                            material: ImageBoxMaterial::Image(material),
                            ..Default::default()
                        }
                    }
                    ThemedImageMaterial::Procedural(material) => {
                        ImageBoxProps {
                            material: ImageBoxMaterial::Procedural(material),
                            ..Default::default()
                        }
                    }
                };
                let props = Props::new(ContentBoxItemLayout {
                    depth: Scalar::NEG_INFINITY,
                    ..Default::default()
                }).with(image);
                let background = widget! {
                    (#{"background"} image_box: {props})
                };
                if let Some(frame) = paper_props.frame {
                    let color = match themed_props.color {
                        ThemeColor::Default => button_colors.main.default.dark,
                        ThemeColor::Primary => button_colors.main.primary.dark,
                        ThemeColor::Secondary => button_colors.main.secondary.dark,
                    };
                    let props = Props::new(ContentBoxItemLayout {
                        depth: Scalar::NEG_INFINITY,
                        ..Default::default()
                    }).with(ImageBoxProps {
                        material: ImageBoxMaterial::Color(ImageBoxColor {
                            color,
                            scaling: ImageBoxImageScaling::Frame(frame),
                        }),
                        ..Default::default()
                    });
                    let frame = widget! {
                        (#{"frame"} image_box: {props})
                    };
                    vec![background, frame, content]
                } else {
                    vec![background, content]
                }
            },
            ThemeVariant::Outline => {
                if let Some(frame) = paper_props.frame {
                    let button_colors = shared_props.map_or_default::<ThemeProps, _, _>(|props| {
                        props.active_colors.clone()
                    });
                    let color = match themed_props.color {
                        ThemeColor::Default => button_colors.main.default.dark,
                        ThemeColor::Primary => button_colors.main.primary.dark,
                        ThemeColor::Secondary => button_colors.main.secondary.dark,
                    };
                    let props = Props::new(ContentBoxItemLayout {
                        depth: Scalar::NEG_INFINITY,
                        ..Default::default()
                    }).with(ImageBoxProps {
                        material: ImageBoxMaterial::Color(ImageBoxColor {
                            color,
                            scaling: ImageBoxImageScaling::Frame(frame),
                        }),
                        ..Default::default()
                    });
                    let frame = widget! {
                        (#{"frame"} image_box: {props})
                    };
                    vec![frame, content]
                } else {
                    vec![content]
                }
            },
        };

        widget! {
            (#{key} content_box: {props.clone()} |[ items ]|)
        }
    }
}

widget_component! {
    pub button_paper(key, props, named_slots) {
        unpack_named_slots!(named_slots => content);

        widget! {
            (#{key} button: {props.clone()} {
                content = (#{"content"} button_paper_content: {props.clone()} {
                    content = {content}
                })
            })
        }
    }
}