summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml3
-rw-r--r--material_theme/Cargo.toml3
-rw-r--r--material_theme/src/lib.rs74
-rw-r--r--src/main.rs17
-rw-r--r--src/panes/element_list.rs11
6 files changed, 61 insertions, 49 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 2dc8556..b2ab721 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2678,6 +2678,8 @@ name = "material_theme"
version = "0.14.0-dev"
dependencies = [
"dark-light",
+ "iced_anim",
+ "iced_dialog",
"iced_widget",
"serde",
"toml",
diff --git a/Cargo.toml b/Cargo.toml
index 33d3b8e..63e5f89 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -19,7 +19,7 @@ iced.workspace = true
iced_anim.workspace = true
iced_custom_highlighter = { git = "https://github.com/pml68/iced_custom_highlighter", branch = "master" }
iced_drop = { path = "iced_drop" }
-iced_dialog = { git = "https://github.com/pml68/iced_dialog", branch = "iced/personal" }
+iced_dialog.workspace = true
material_theme = { path = "material_theme" }
serde.workspace = true
serde_json = "1.0.140"
@@ -36,6 +36,7 @@ dirs-next = "2.0.0"
[workspace.dependencies]
iced_anim = { version = "0.2.1", features = ["derive"] }
+iced_dialog = { git = "https://github.com/pml68/iced_dialog", branch = "iced/personal" }
serde = { version = "1.0.219", features = ["derive"] }
toml = "0.8.20"
diff --git a/material_theme/Cargo.toml b/material_theme/Cargo.toml
index 5a48dc0..e88ce92 100644
--- a/material_theme/Cargo.toml
+++ b/material_theme/Cargo.toml
@@ -14,12 +14,15 @@ rust-version = "1.85"
[features]
default = []
animate = ["dep:iced_anim"]
+dialog = ["dep:iced_dialog"]
[dependencies]
iced_widget = "0.14.0-dev"
serde.workspace = true
toml.workspace = true
dark-light = "2.0.0"
+iced_dialog.workspace = true
+iced_dialog.optional = true
[dependencies.iced_anim]
workspace = true
diff --git a/material_theme/src/lib.rs b/material_theme/src/lib.rs
index 930e511..87cf353 100644
--- a/material_theme/src/lib.rs
+++ b/material_theme/src/lib.rs
@@ -28,31 +28,6 @@ impl Theme {
}
}
-#[cfg(feature = "animate")]
-impl iced_anim::Animate for Theme {
- fn components() -> usize {
- ColorScheme::components()
- }
-
- fn update(&mut self, components: &mut impl Iterator<Item = f32>) {
- let mut colors = self.colorscheme;
- colors.update(components);
-
- *self = Theme::new("Animating Theme", colors);
- }
-
- fn distance_to(&self, end: &Self) -> Vec<f32> {
- self.colorscheme.distance_to(&end.colorscheme)
- }
-
- fn lerp(&mut self, start: &Self, end: &Self, progress: f32) {
- let mut colors = self.colorscheme;
- colors.lerp(&start.colorscheme, &end.colorscheme, progress);
-
- *self = Theme::new("Animating Theme", colors);
- }
-}
-
impl Clone for Theme {
fn clone(&self) -> Self {
Self {
@@ -92,6 +67,47 @@ impl Base for Theme {
}
}
+#[cfg(feature = "animate")]
+impl iced_anim::Animate for Theme {
+ fn components() -> usize {
+ ColorScheme::components()
+ }
+
+ fn update(&mut self, components: &mut impl Iterator<Item = f32>) {
+ let mut colors = self.colorscheme;
+ colors.update(components);
+
+ *self = Theme::new("Animating Theme", colors);
+ }
+
+ fn distance_to(&self, end: &Self) -> Vec<f32> {
+ self.colorscheme.distance_to(&end.colorscheme)
+ }
+
+ fn lerp(&mut self, start: &Self, end: &Self, progress: f32) {
+ let mut colors = self.colorscheme;
+ colors.lerp(&start.colorscheme, &end.colorscheme, progress);
+
+ *self = Theme::new("Animating Theme", colors);
+ }
+}
+
+#[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")
+});
+
+pub static LIGHT: LazyLock<Theme> = LazyLock::new(|| {
+ toml::from_str(LIGHT_THEME_CONTENT).expect("parse light theme")
+});
+
#[derive(Debug, Clone, Copy, PartialEq, Deserialize)]
#[cfg_attr(feature = "animate", derive(iced_anim::Animate))]
pub struct ColorScheme {
@@ -106,14 +122,6 @@ pub struct ColorScheme {
pub shadow: Color,
}
-pub static DARK: LazyLock<Theme> = LazyLock::new(|| {
- toml::from_str(DARK_THEME_CONTENT).expect("parse dark theme")
-});
-
-pub static LIGHT: LazyLock<Theme> = LazyLock::new(|| {
- toml::from_str(LIGHT_THEME_CONTENT).expect("parse light theme")
-});
-
#[derive(Debug, Clone, Copy, PartialEq, Deserialize)]
#[cfg_attr(feature = "animate", derive(iced_anim::Animate))]
pub struct Primary {
diff --git a/src/main.rs b/src/main.rs
index 6ab4da9..3895dbc 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -31,8 +31,7 @@ use iced_dialog::dialog::Dialog;
use panes::{code_view, designer_view, element_list};
use tokio::runtime;
use types::{
- Action, DesignerPane, DialogAction, DialogButtons, ElementName, Message,
- Project,
+ Action, DesignerPane, DialogAction, DialogButtons, Message, Project,
};
fn main() -> Result<(), Box<dyn std::error::Error>> {
@@ -79,7 +78,6 @@ struct App {
dialog_content: String,
dialog_buttons: DialogButtons,
dialog_action: DialogAction,
- element_list: &'static [ElementName],
editor_content: text_editor::Content,
}
@@ -132,7 +130,6 @@ impl App {
dialog_content: String::new(),
dialog_buttons: DialogButtons::None,
dialog_action: DialogAction::None,
- element_list: ElementName::ALL,
editor_content: text_editor::Content::new(),
},
task,
@@ -408,9 +405,7 @@ impl App {
code_view::view(&self.editor_content, is_focused)
}
},
- Panes::ElementList => {
- element_list::view(self.element_list, is_focused)
- }
+ Panes::ElementList => element_list::view(is_focused),
}
},
)
@@ -438,7 +433,13 @@ impl App {
DialogButtons::OkCancel => vec![ok_button(), cancel_button()],
},
)
- .title(self.dialog_title);
+ .title(self.dialog_title)
+ .container_style(|theme| container::Style {
+ background: Some(
+ theme.extended_palette().background.strong.color.into(),
+ ),
+ ..Default::default()
+ });
Animation::new(&self.theme, content)
.on_update(Message::SwitchTheme)
diff --git a/src/panes/element_list.rs b/src/panes/element_list.rs
index 10eea66..594c203 100644
--- a/src/panes/element_list.rs
+++ b/src/panes/element_list.rs
@@ -5,13 +5,13 @@ use iced_drop::droppable;
use super::style;
use crate::types::{ElementName, Message};
-fn items_list_view(items: &[ElementName]) -> Element<'_, Message> {
+fn items_list_view<'a>() -> Element<'a, Message> {
let mut column = Column::new()
.spacing(20)
.align_x(Alignment::Center)
.width(Length::Fill);
- for item in items {
+ for item in ElementName::ALL {
column = column.push(
droppable(text(item.clone().to_string())).on_drop(|point, rect| {
Message::DropNewElement(item.clone(), point, rect)
@@ -25,11 +25,8 @@ fn items_list_view(items: &[ElementName]) -> Element<'_, Message> {
.into()
}
-pub fn view(
- element_list: &[ElementName],
- is_focused: bool,
-) -> pane_grid::Content<'_, Message> {
- let items_list = items_list_view(element_list);
+pub fn view<'a>(is_focused: bool) -> pane_grid::Content<'a, Message> {
+ let items_list = items_list_view();
let content = column![items_list]
.align_x(Alignment::Center)
.height(Length::Fill)