material_ui_rs/design/style/
menu.rs1use iced_widget::core::{Background, border};
2use iced_widget::overlay::menu::{Catalog, Style, StyleFn};
3
4use crate::Theme;
5use crate::tokens;
6use crate::utils::shadow_from_level;
7
8impl Catalog for Theme {
9 type Class<'a> = StyleFn<'a, Self>;
10
11 fn default<'a>() -> <Self as Catalog>::Class<'a> {
12 Box::new(default)
13 }
14
15 fn style(&self, class: &<Self as Catalog>::Class<'_>) -> Style {
16 class(self)
17 }
18}
19
20pub fn default(theme: &Theme) -> Style {
21 let colors = theme.colors();
22 let surface = colors.surface;
23
24 Style {
25 border: border::rounded(tokens::component::menu::CONTAINER_SHAPE),
26 background: Background::Color(surface.container.base),
27 text_color: surface.text,
28 selected_background: Background::Color(colors.secondary.container),
29 selected_text_color: colors.secondary.container_text,
30 shadow: shadow_from_level(
31 tokens::component::menu::CONTAINER_ELEVATION_LEVEL,
32 colors.shadow,
33 ),
34 }
35}
36
37pub fn outlined_select(theme: &Theme) -> Style {
38 let colors = theme.colors();
39 let surface = colors.surface;
40
41 Style {
42 border: border::rounded(tokens::component::select::MENU_CONTAINER_SHAPE),
43 background: Background::Color(surface.container.base),
44 text_color: surface.text,
45 selected_background: Background::Color(surface.container.highest),
46 selected_text_color: surface.text,
47 shadow: shadow_from_level(
48 tokens::component::select::MENU_CONTAINER_ELEVATION_LEVEL,
49 colors.shadow,
50 ),
51 }
52}
53
54#[cfg(test)]
55#[path = "../../../tests/design/style/menu.rs"]
56mod tests;