summaryrefslogtreecommitdiff
path: root/material_theme/src
diff options
context:
space:
mode:
authorpml68 <contact@pml68.dev>2025-04-08 19:40:45 +0200
committerpml68 <contact@pml68.dev>2025-04-15 23:49:01 +0200
commit53dc5464c2f595d1a32174598e280428d3265f15 (patch)
treeeacb4abf0bbad81abd78e9b2617255c147ea345c /material_theme/src
parentfeat(material_theme): impl `scrollable::Catalog` (diff)
downloadiced-builder-53dc5464c2f595d1a32174598e280428d3265f15.tar.gz
feat(material_theme): impl `menu::Catalog`, change `dialog::Catalog` impl
Diffstat (limited to 'material_theme/src')
-rw-r--r--material_theme/src/dialog.rs25
-rw-r--r--material_theme/src/lib.rs11
-rw-r--r--material_theme/src/menu.rs29
3 files changed, 57 insertions, 8 deletions
diff --git a/material_theme/src/dialog.rs b/material_theme/src/dialog.rs
new file mode 100644
index 0000000..68c61b5
--- /dev/null
+++ b/material_theme/src/dialog.rs
@@ -0,0 +1,25 @@
+use iced_widget::container::Style;
+use iced_widget::core::{Background, border};
+
+use super::{Theme, text};
+
+impl iced_dialog::dialog::Catalog for Theme {
+ fn default_container<'a>()
+ -> <Self as iced_widget::container::Catalog>::Class<'a> {
+ Box::new(default_container)
+ }
+
+ fn default_title<'a>() -> <Self as iced_widget::text::Catalog>::Class<'a> {
+ Box::new(text::surface)
+ }
+}
+
+pub fn default_container(theme: &Theme) -> Style {
+ let colors = theme.colorscheme.surface;
+ Style {
+ background: Some(Background::Color(colors.surface_container.high)),
+ text_color: Some(colors.on_surface_variant),
+ border: border::rounded(28),
+ ..Style::default()
+ }
+}
diff --git a/material_theme/src/lib.rs b/material_theme/src/lib.rs
index 273ef9a..a4eea24 100644
--- a/material_theme/src/lib.rs
+++ b/material_theme/src/lib.rs
@@ -6,6 +6,9 @@ use serde::Deserialize;
pub mod button;
pub mod container;
+#[cfg(feature = "dialog")]
+pub mod dialog;
+pub mod menu;
pub mod scrollable;
pub mod text;
pub mod utils;
@@ -93,14 +96,6 @@ impl iced_anim::Animate for Theme {
}
}
-#[cfg(feature = "dialog")]
-impl iced_dialog::dialog::Catalog for Theme {
- fn default_container<'a>()
- -> <Self as iced_widget::container::Catalog>::Class<'a> {
- Box::new(container::surface)
- }
-}
-
pub static DARK: LazyLock<Theme> = LazyLock::new(|| {
toml::from_str(DARK_THEME_CONTENT).expect("parse dark theme")
});
diff --git a/material_theme/src/menu.rs b/material_theme/src/menu.rs
new file mode 100644
index 0000000..d1bebec
--- /dev/null
+++ b/material_theme/src/menu.rs
@@ -0,0 +1,29 @@
+use iced_widget::core::{Background, border};
+use iced_widget::overlay::menu::{Catalog, Style, StyleFn};
+
+use super::Theme;
+
+impl Catalog for Theme {
+ type Class<'a> = StyleFn<'a, Self>;
+
+ fn default<'a>() -> <Self as Catalog>::Class<'a> {
+ Box::new(default)
+ }
+
+ fn style(&self, class: &<Self as Catalog>::Class<'_>) -> Style {
+ class(self)
+ }
+}
+
+pub fn default(theme: &Theme) -> Style {
+ let surface = theme.colorscheme.surface;
+ let secondary = theme.colorscheme.secondary;
+
+ Style {
+ border: border::rounded(4),
+ background: Background::Color(surface.surface_container.base),
+ text_color: surface.on_surface,
+ selected_background: Background::Color(secondary.secondary_container),
+ selected_text_color: secondary.on_secondary_container,
+ }
+}