summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--material_theme/src/dialog.rs25
-rw-r--r--material_theme/src/lib.rs11
-rw-r--r--material_theme/src/menu.rs29
-rwxr-xr-xsrc/types/rendered_element.rs105
4 files changed, 126 insertions, 44 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,
+ }
+}
diff --git a/src/types/rendered_element.rs b/src/types/rendered_element.rs
index 0a78dcd..77b76e4 100755
--- a/src/types/rendered_element.rs
+++ b/src/types/rendered_element.rs
@@ -317,53 +317,86 @@ impl<'a> From<RenderedElement> for Element<'a, Message> {
let child_elements = copy.child_elements.unwrap_or_default();
let content: Element<'a, Message> = match copy.name {
- ElementName::Text(s) => {
- if s.is_empty() {
- widget::text("New Text").apply_options(copy.options).into()
- } else {
- widget::text(s).apply_options(copy.options).into()
- }
- }
- ElementName::Button(s) => {
- if s.is_empty() {
- widget::button(widget::text("New Button"))
- .apply_options(copy.options)
- .into()
- } else {
- widget::button(widget::text(s))
- .apply_options(copy.options)
- .into()
- }
+ ElementName::Text(s) => if s.is_empty() {
+ widget::text("New Text")
+ } else {
+ widget::text(s)
}
+ .apply_options(copy.options)
+ .into(),
+ ElementName::Button(s) => widget::button(if s.is_empty() {
+ widget::text("New Button")
+ } else {
+ widget::text(s)
+ })
+ .apply_options(copy.options)
+ .into(),
ElementName::Svg(p) => {
widget::svg(p).apply_options(copy.options).into()
}
ElementName::Image(p) => {
widget::image(p).apply_options(copy.options).into()
}
- ElementName::Container => {
- widget::container(if child_elements.len() == 1 {
- child_elements[0].clone().into()
- } else {
- Element::from("")
- })
- .apply_options(copy.options)
- .padding(20)
- .into()
+ ElementName::Container => if child_elements.len() == 1 {
+ widget::container(child_elements[0].clone())
+ } else {
+ widget::container("New Container")
+ .padding(20)
+ .style(|theme| widget::container::Style {
+ border: iced::border::rounded(4).color(
+ theme.extended_palette().background.strongest.text,
+ ),
+ ..Default::default()
+ })
}
- ElementName::Row => widget::Row::from_vec(
- child_elements.into_iter().map(Into::into).collect(),
- )
- .padding(20)
- .apply_options(copy.options)
- .into(),
- ElementName::Column => widget::Column::from_vec(
- child_elements.into_iter().map(Into::into).collect(),
- )
- .padding(20)
.apply_options(copy.options)
.into(),
+ ElementName::Row => {
+ if !child_elements.is_empty() {
+ widget::Row::with_children(
+ child_elements.into_iter().map(Into::into),
+ )
+ .apply_options(copy.options)
+ .into()
+ } else {
+ widget::container(
+ widget::row!["New Row"]
+ .padding(20)
+ .apply_options(copy.options),
+ )
+ .style(|theme| widget::container::Style {
+ border: iced::border::rounded(4).color(
+ theme.extended_palette().background.strongest.text,
+ ),
+ ..Default::default()
+ })
+ .into()
+ }
+ }
+ ElementName::Column => {
+ if !child_elements.is_empty() {
+ widget::Column::with_children(
+ child_elements.into_iter().map(Into::into),
+ )
+ .apply_options(copy.options)
+ .into()
+ } else {
+ widget::container(
+ widget::column!["New Column"]
+ .padding(20)
+ .apply_options(copy.options),
+ )
+ .style(|theme| widget::container::Style {
+ border: iced::border::rounded(4).color(
+ theme.extended_palette().background.strongest.text,
+ ),
+ ..Default::default()
+ })
+ .into()
+ }
+ }
};
+
iced_drop::droppable(content)
.id(value.id().clone())
.drag_hide(true)