From 3f811ebef76e0b9ad937be34f70515fe626c21a3 Mon Sep 17 00:00:00 2001 From: pml68 Date: Mon, 24 Mar 2025 11:12:00 +0100 Subject: feat: add custom theme struct with dark and light variants --- Cargo.lock | 1 + 1 file changed, 1 insertion(+) (limited to 'Cargo.lock') diff --git a/Cargo.lock b/Cargo.lock index 1aee68c..e92c3fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1971,6 +1971,7 @@ dependencies = [ name = "iced_builder" version = "0.1.0" dependencies = [ + "dark-light", "dirs-next", "embed-resource 3.0.2", "fxhash", -- cgit v1.2.3 From e9af14434454e8512e99612271b557789f28deeb Mon Sep 17 00:00:00 2001 From: pml68 Date: Mon, 7 Apr 2025 02:05:39 +0200 Subject: refactor: move custom theme into its separate crate --- Cargo.lock | 20 ++- Cargo.toml | 27 ++-- assets/themes/dark.toml | 48 ------- assets/themes/light.toml | 48 ------- material_theme/Cargo.toml | 40 ++++++ material_theme/assets/themes/dark.toml | 48 +++++++ material_theme/assets/themes/light.toml | 48 +++++++ material_theme/src/button.rs | 209 +++++++++++++++++++++++++++++ material_theme/src/container.rs | 173 ++++++++++++++++++++++++ material_theme/src/lib.rs | 229 ++++++++++++++++++++++++++++++++ material_theme/src/text.rs | 86 ++++++++++++ material_theme/src/utils.rs | 61 +++++++++ src/main.rs | 19 --- src/theme.rs | 162 +--------------------- src/theme/button.rs | 189 -------------------------- src/theme/text.rs | 50 ------- theme_test/Cargo.toml | 8 ++ theme_test/src/main.rs | 89 +++++++++++++ 18 files changed, 1029 insertions(+), 525 deletions(-) delete mode 100644 assets/themes/dark.toml delete mode 100644 assets/themes/light.toml create mode 100644 material_theme/Cargo.toml create mode 100644 material_theme/assets/themes/dark.toml create mode 100644 material_theme/assets/themes/light.toml create mode 100644 material_theme/src/button.rs create mode 100644 material_theme/src/container.rs create mode 100644 material_theme/src/lib.rs create mode 100644 material_theme/src/text.rs create mode 100644 material_theme/src/utils.rs delete mode 100644 src/theme/button.rs delete mode 100644 src/theme/text.rs create mode 100644 theme_test/Cargo.toml create mode 100644 theme_test/src/main.rs (limited to 'Cargo.lock') diff --git a/Cargo.lock b/Cargo.lock index e92c3fc..2dc8556 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1971,7 +1971,6 @@ dependencies = [ name = "iced_builder" version = "0.1.0" dependencies = [ - "dark-light", "dirs-next", "embed-resource 3.0.2", "fxhash", @@ -1981,6 +1980,7 @@ dependencies = [ "iced_dialog", "iced_drop", "iced_fontello", + "material_theme", "rfd", "rust-format", "serde", @@ -2673,6 +2673,16 @@ dependencies = [ "libc", ] +[[package]] +name = "material_theme" +version = "0.14.0-dev" +dependencies = [ + "dark-light", + "iced_widget", + "serde", + "toml", +] + [[package]] name = "maybe-rayon" version = "0.1.1" @@ -4634,6 +4644,14 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "theme_test" +version = "0.0.1" +dependencies = [ + "iced", + "material_theme", +] + [[package]] name = "thiserror" version = "1.0.69" diff --git a/Cargo.toml b/Cargo.toml index 39e69af..33d3b8e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,23 +16,28 @@ debug = ["iced/debug"] [dependencies] iced.workspace = true -iced_anim = { git = "https://github.com/pml68/iced_anim", features = ["derive"] } +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" } -serde = { version = "1.0.217", features = ["derive"] } -serde_json = "1.0.138" -toml = "0.8.20" -tokio = { version = "1.43", features = ["fs"] } +material_theme = { path = "material_theme" } +serde.workspace = true +serde_json = "1.0.140" +toml.workspace = true +tokio = { version = "1.42.1", features = ["fs"] } tokio-stream = { version = "0.1", features = ["fs"] } # TODO: enable tokio when it actually compiles # rfd = { version = "0.15.2", default-features = false, features = ["tokio", "xdg-portal"] } rfd = "0.15.3" rust-format = "0.3.4" fxhash = "0.2.1" -thiserror = "2.0.11" +thiserror = "2.0.12" dirs-next = "2.0.0" -dark-light = "2.0.0" + +[workspace.dependencies] +iced_anim = { version = "0.2.1", features = ["derive"] } +serde = { version = "1.0.219", features = ["derive"] } +toml = "0.8.20" [workspace.dependencies.iced] git = "https://github.com/pml68/iced" @@ -46,7 +51,7 @@ iced_fontello = "0.13.2" xdg = "2.5.2" [target.'cfg(windows)'.build-dependencies] -embed-resource = "3.0.1" +embed-resource = "3.0.2" windows_exe_info = "0.5" [profile.dev] @@ -68,7 +73,7 @@ name = "iced-builder" path = "src/main.rs" [workspace] -members = ["iced_drop"] +members = ["iced_drop", "material_theme", "theme_test"] [lints.rust] missing_debug_implementations = "deny" @@ -89,3 +94,7 @@ from_over_into = "deny" needless_borrow = "deny" new_without_default = "deny" useless_conversion = "deny" + +[patch.crates-io] +iced_anim = { git = "https://github.com/pml68/iced_anim" } +iced_widget = { git = "https://github.com/pml68/iced", branch = "feat/rehighlight-on-redraw" } diff --git a/assets/themes/dark.toml b/assets/themes/dark.toml deleted file mode 100644 index 3c02ce8..0000000 --- a/assets/themes/dark.toml +++ /dev/null @@ -1,48 +0,0 @@ -name = "Dark" - -shadow = "#000000" - -[primary] -color = "#6200ee" -on_primary = "#ffffff" -primary_container = "#3700b3" -on_primary_container = "#ffffff" - -[secondary] -color = "#03dac6" -on_secondary = "#ffffff" -secondary_container = "#018786" -on_secondary_container = "#ffffff" - -[tertiary] -color = "#bb86fc" -on_tertiary = "#000000" -tertiary_container = "#6200ee" -on_tertiary_container = "#000000" - -[error] -color = "#b00020" -on_error = "#ffffff" -error_container = "#cf6679" -on_error_container = "#000000" - -[surface] -color = "#121212" -on_surface = "#ffffff" -on_surface_variant = "#b0b0b0" - -[surface.surface_container] -lowest = "#1e1e2e" -low = "#333333" -base = "#444444" -high = "#555555" -highest = "#666666" - -[inverse] -inverse_surface = "#212121" -inverse_on_surface = "#ffffff" -inverse_primary = "#bb86fc" - -[outline] -color = "#737373" -variant = "#aaaaaa" diff --git a/assets/themes/light.toml b/assets/themes/light.toml deleted file mode 100644 index 2842c82..0000000 --- a/assets/themes/light.toml +++ /dev/null @@ -1,48 +0,0 @@ -name = "Dark" - -shadow = "#000000" - -[primary] -color = "#6200ee" -on_primary = "#ffffff" -primary_container = "#e1bee7" -on_primary_container = "#000000" - -[secondary] -color = "#03dac6" -on_secondary = "#ffffff" -secondary_container = "#018786" -on_secondary_container = "#ffffff" - -[tertiary] -color = "#bb86fc" -on_tertiary = "#000000" -tertiary_container = "#6200ee" -on_tertiary_container = "#000000" - -[error] -color = "#b00020" -on_error = "#ffffff" -error_container = "#cf6679" -on_error_container = "#000000" - -[surface] -color = "#ffffff" -on_surface = "#000000" -on_surface_variant = "#757575" - -[surface.surface_container] -lowest = "#fafafa" -low = "#eeeeee" -base = "#dddddd" -high = "#cccccc" -highest = "#bbbbbb" - -[inverse] -inverse_surface = "#121212" -inverse_on_surface = "#ffffff" -inverse_primary = "#bb86fc" - -[outline] -color = "#757575" -variant = "#b0b0b0" diff --git a/material_theme/Cargo.toml b/material_theme/Cargo.toml new file mode 100644 index 0000000..0597d78 --- /dev/null +++ b/material_theme/Cargo.toml @@ -0,0 +1,40 @@ +[package] +name = "material_theme" +description = "An M3 inspired theme for `iced`" +authors = ["pml68 "] +version = "0.14.0-dev" +edition = "2024" +license = "MIT" +# readme = "README.md" +repository = "https://github.com/pml68/iced_builder" +categories = ["gui"] +keywords = ["gui", "ui", "graphics", "interface", "widgets"] +rust-version = "1.85" + +[dependencies] +iced_widget = "0.14.0-dev" +serde.workspace = true +toml.workspace = true +dark-light = "2.0.0" + +[lints.rust] +unsafe_code = "deny" +unused_results = "deny" + +[lints.clippy] +type-complexity = "allow" +semicolon_if_nothing_returned = "deny" +trivially-copy-pass-by-ref = "deny" +default_trait_access = "deny" +match-wildcard-for-single-variants = "deny" +redundant-closure-for-method-calls = "deny" +filter_map_next = "deny" +manual_let_else = "deny" +unused_async = "deny" +from_over_into = "deny" +needless_borrow = "deny" +new_without_default = "deny" +useless_conversion = "deny" + +[lints.rustdoc] +broken_intra_doc_links = "forbid" diff --git a/material_theme/assets/themes/dark.toml b/material_theme/assets/themes/dark.toml new file mode 100644 index 0000000..4d23fc8 --- /dev/null +++ b/material_theme/assets/themes/dark.toml @@ -0,0 +1,48 @@ +name = "Dark" + +shadow = "#000000" + +[primary] +color = "#9bd4a1" +on_primary = "#003916" +primary_container = "#1b5129" +on_primary_container = "#b6f1bb" + +[secondary] +color = "#b8ccb6" +on_secondary = "#233425" +secondary_container = "#394b3a" +on_secondary_container = "#d3e8d1" + +[tertiary] +color = "#a1ced7" +on_tertiary = "#00363e" +tertiary_container = "#1f4d55" +on_tertiary_container = "#bdeaf4" + +[error] +color = "#ffb4ab" +on_error = "#690005" +error_container = "#93000a" +on_error_container = "#ffdad6" + +[surface] +color = "#101510" +on_surface = "#e0e4dc" +on_surface_variant = "#c1c9be" + +[surface.surface_container] +lowest = "#0b0f0b" +low = "#181d18" +base = "#1c211c" +high = "#262b26" +highest = "#313631" + +[inverse] +inverse_surface = "#e0e4dc" +inverse_on_surface = "#2d322c" +inverse_primary = "#34693f" + +[outline] +color = "#8b9389" +variant = "#414941" diff --git a/material_theme/assets/themes/light.toml b/material_theme/assets/themes/light.toml new file mode 100644 index 0000000..5288c84 --- /dev/null +++ b/material_theme/assets/themes/light.toml @@ -0,0 +1,48 @@ +name = "Light" + +shadow = "#000000" + +[primary] +color = "#34693f" +on_primary = "#ffffff" +primary_container = "#b6f1bb" +on_primary_container = "#1b5129" + +[secondary] +color = "#516351" +on_secondary = "#ffffff" +secondary_container = "#d3e8d1" +on_secondary_container = "#394b3a" + +[tertiary] +color = "#39656d" +on_tertiary = "#ffffff" +tertiary_container = "#bdeaf4" +on_tertiary_container = "#1f4d55" + +[error] +color = "#ba1a1a" +on_error = "#ffffff" +error_container = "#ffdad6" +on_error_container = "#93000a" + +[surface] +color = "#f7fbf2" +on_surface = "#181d18" +on_surface_variant = "#414941" + +[surface.surface_container] +lowest = "#ffffff" +low = "#f1f5ed" +base = "#ebefe7" +high = "#e5e9e1" +highest = "#e0e4dc" + +[inverse] +inverse_surface = "#2d322c" +inverse_on_surface = "#eef2ea" +inverse_primary = "#9bd4a1" + +[outline] +color = "#727970" +variant = "#c1c9be" diff --git a/material_theme/src/button.rs b/material_theme/src/button.rs new file mode 100644 index 0000000..051d6c9 --- /dev/null +++ b/material_theme/src/button.rs @@ -0,0 +1,209 @@ +#![allow(dead_code)] +use iced_widget::button::{Catalog, Status, Style, StyleFn}; +use iced_widget::core::{Background, Border, Color, Shadow, Vector}; + +use crate::Theme; +use crate::utils::{elevation, mix}; + +impl Catalog for Theme { + type Class<'a> = StyleFn<'a, Self>; + + fn default<'a>() -> Self::Class<'a> { + Box::new(filled) + } + + fn style(&self, class: &Self::Class<'_>, status: Status) -> Style { + class(self, status) + } +} + +fn button( + foreground: Color, + background: Color, + tone_overlay: Color, + disabled: Color, + shadow_color: Color, + shadow_elevation: u8, + status: Status, +) -> Style { + let border = Border { + radius: 400.into(), + ..Default::default() + }; + + let active = Style { + background: Some(Background::Color(background)), + text_color: foreground, + border, + shadow: Shadow { + color: shadow_color, + offset: Vector { + x: 0.0, + y: elevation(shadow_elevation), + }, + blur_radius: elevation(shadow_elevation) + * (1.0 + 0.4_f32.powf(elevation(shadow_elevation))), + }, + }; + + match status { + Status::Active => active, + Status::Pressed => Style { + background: Some(Background::Color(mix( + background, + tone_overlay, + 0.08, + ))), + ..active + }, + Status::Hovered => Style { + background: Some(Background::Color(mix( + background, + tone_overlay, + 0.1, + ))), + text_color: foreground, + border, + shadow: Shadow { + color: shadow_color, + offset: Vector { + x: 0.0, + y: elevation(shadow_elevation + 1), + }, + blur_radius: (elevation(shadow_elevation + 1)) + * (1.0 + 0.4_f32.powf(elevation(shadow_elevation + 1))), + }, + }, + Status::Disabled => Style { + background: Some(Background::Color(Color { + a: 0.12, + ..disabled + })), + text_color: Color { + a: 0.38, + ..disabled + }, + border, + ..Default::default() + }, + } +} + +pub fn elevated(theme: &Theme, status: Status) -> Style { + let surface_colors = theme.colorscheme.surface; + + let foreground = theme.colorscheme.primary.color; + let background = surface_colors.surface_container.low; + let disabled = surface_colors.on_surface; + + let shadow_color = theme.colorscheme.shadow; + + button( + foreground, + background, + foreground, + disabled, + shadow_color, + 1, + status, + ) +} + +pub fn filled(theme: &Theme, status: Status) -> Style { + let primary_colors = theme.colorscheme.primary; + + let foreground = primary_colors.on_primary; + let background = primary_colors.color; + let disabled = theme.colorscheme.surface.on_surface; + + let shadow_color = theme.colorscheme.shadow; + + button( + foreground, + background, + foreground, + disabled, + shadow_color, + 0, + status, + ) +} + +pub fn filled_tonal(theme: &Theme, status: Status) -> Style { + let secondary_colors = theme.colorscheme.secondary; + + let foreground = secondary_colors.on_secondary_container; + let background = secondary_colors.secondary_container; + let disabled = theme.colorscheme.surface.on_surface; + let shadow_color = theme.colorscheme.shadow; + + button( + foreground, + background, + foreground, + disabled, + shadow_color, + 0, + status, + ) +} + +pub fn outlined(theme: &Theme, status: Status) -> Style { + let foreground = theme.colorscheme.primary.color; + let background = Color::TRANSPARENT; + let disabled = theme.colorscheme.surface.on_surface; + + let outline = theme.colorscheme.outline.color; + + let border = match status { + Status::Active | Status::Pressed | Status::Hovered => Border { + color: outline, + width: 1.0, + radius: 400.0.into(), + }, + Status::Disabled => Border { + color: Color { + a: 0.12, + ..disabled + }, + width: 1.0, + radius: 400.0.into(), + }, + }; + + let style = button( + foreground, + background, + foreground, + disabled, + Color::TRANSPARENT, + 0, + status, + ); + + Style { border, ..style } +} + +pub fn text(theme: &Theme, status: Status) -> Style { + let foreground = theme.colorscheme.primary.color; + let background = Color::TRANSPARENT; + let disabled = theme.colorscheme.surface.on_surface; + + let style = button( + foreground, + background, + foreground, + disabled, + Color::TRANSPARENT, + 0, + status, + ); + + match status { + Status::Hovered | Status::Pressed => style, + _ => Style { + background: None, + ..style + }, + } +} diff --git a/material_theme/src/container.rs b/material_theme/src/container.rs new file mode 100644 index 0000000..a14cfd5 --- /dev/null +++ b/material_theme/src/container.rs @@ -0,0 +1,173 @@ +use iced_widget::container::{Catalog, Style, StyleFn}; +use iced_widget::core::{Background, border}; + +use super::Theme; + +impl Catalog for Theme { + type Class<'a> = StyleFn<'a, Self>; + + fn default<'a>() -> Self::Class<'a> { + Box::new(transparent) + } + + fn style(&self, class: &Self::Class<'_>) -> Style { + class(self) + } +} + +pub fn transparent(_theme: &Theme) -> Style { + Style { + border: border::rounded(4), + ..Style::default() + } +} + +pub fn primary(theme: &Theme) -> Style { + let colors = theme.colorscheme.primary; + Style { + background: Some(Background::Color(colors.color)), + text_color: Some(colors.on_primary), + border: border::rounded(4), + ..Style::default() + } +} + +pub fn primary_container(theme: &Theme) -> Style { + let colors = theme.colorscheme.primary; + Style { + background: Some(Background::Color(colors.primary_container)), + text_color: Some(colors.on_primary_container), + border: border::rounded(8), + ..Style::default() + } +} + +pub fn secondary(theme: &Theme) -> Style { + let colors = theme.colorscheme.secondary; + Style { + background: Some(Background::Color(colors.color)), + text_color: Some(colors.on_secondary), + border: border::rounded(4), + ..Style::default() + } +} + +pub fn secondary_container(theme: &Theme) -> Style { + let colors = theme.colorscheme.secondary; + Style { + background: Some(Background::Color(colors.secondary_container)), + text_color: Some(colors.on_secondary_container), + border: border::rounded(8), + ..Style::default() + } +} + +pub fn tertiary(theme: &Theme) -> Style { + let colors = theme.colorscheme.tertiary; + Style { + background: Some(Background::Color(colors.color)), + text_color: Some(colors.on_tertiary), + border: border::rounded(4), + ..Style::default() + } +} + +pub fn tertiary_container(theme: &Theme) -> Style { + let colors = theme.colorscheme.tertiary; + Style { + background: Some(Background::Color(colors.tertiary_container)), + text_color: Some(colors.on_tertiary_container), + border: border::rounded(8), + ..Style::default() + } +} + +pub fn error(theme: &Theme) -> Style { + let colors = theme.colorscheme.error; + Style { + background: Some(Background::Color(colors.color)), + text_color: Some(colors.on_error), + border: border::rounded(4), + ..Style::default() + } +} + +pub fn error_container(theme: &Theme) -> Style { + let colors = theme.colorscheme.error; + Style { + background: Some(Background::Color(colors.error_container)), + text_color: Some(colors.on_error_container), + border: border::rounded(8), + ..Style::default() + } +} + +pub fn surface(theme: &Theme) -> Style { + let colors = theme.colorscheme.surface; + Style { + background: Some(Background::Color(colors.color)), + text_color: Some(colors.on_surface), + border: border::rounded(4), + ..Style::default() + } +} + +pub fn surface_container_lowest(theme: &Theme) -> Style { + let colors = theme.colorscheme.surface; + Style { + background: Some(Background::Color(colors.surface_container.lowest)), + text_color: Some(colors.on_surface), + border: border::rounded(8), + ..Style::default() + } +} + +pub fn surface_container_low(theme: &Theme) -> Style { + let colors = theme.colorscheme.surface; + Style { + background: Some(Background::Color(colors.surface_container.low)), + text_color: Some(colors.on_surface), + border: border::rounded(8), + ..Style::default() + } +} + +pub fn surface_container(theme: &Theme) -> Style { + let colors = theme.colorscheme.surface; + Style { + background: Some(Background::Color(colors.surface_container.base)), + text_color: Some(colors.on_surface), + border: border::rounded(8), + ..Style::default() + } +} + +pub fn surface_container_high(theme: &Theme) -> Style { + let colors = theme.colorscheme.surface; + Style { + background: Some(Background::Color(colors.surface_container.high)), + text_color: Some(colors.on_surface), + border: border::rounded(8), + ..Style::default() + } +} + +pub fn surface_container_highest(theme: &Theme) -> Style { + let colors = theme.colorscheme.surface; + Style { + background: Some(Background::Color(colors.surface_container.highest)), + text_color: Some(colors.on_surface), + border: border::rounded(8), + ..Style::default() + } +} + +pub fn inverse_surface(theme: &Theme) -> Style { + let colors = theme.colorscheme.inverse; + Style { + background: Some(Background::Color(colors.inverse_surface)), + text_color: Some(colors.inverse_on_surface), + border: border::rounded(4), + ..Style::default() + } +} diff --git a/material_theme/src/lib.rs b/material_theme/src/lib.rs new file mode 100644 index 0000000..6641b74 --- /dev/null +++ b/material_theme/src/lib.rs @@ -0,0 +1,229 @@ +use std::sync::LazyLock; + +use iced_widget::core::Color; +use iced_widget::core::theme::{Base, Style}; +use serde::Deserialize; + +pub mod button; +pub mod container; +pub mod text; +pub mod utils; + +const DARK_THEME_CONTENT: &str = include_str!("../assets/themes/dark.toml"); +const LIGHT_THEME_CONTENT: &str = include_str!("../assets/themes/light.toml"); + +#[derive(Debug, PartialEq, Deserialize)] +pub struct Theme { + pub name: String, + #[serde(flatten)] + pub colorscheme: ColorScheme, +} + +impl Theme { + pub fn new(name: impl Into, colorscheme: ColorScheme) -> Self { + Self { + name: name.into(), + colorscheme, + } + } +} + +impl Clone for Theme { + fn clone(&self) -> Self { + Self { + name: self.name.clone(), + colorscheme: self.colorscheme, + } + } + + fn clone_from(&mut self, source: &Self) { + self.name = source.name.clone(); + self.colorscheme = source.colorscheme; + } +} + +impl Default for Theme { + fn default() -> Self { + match dark_light::detect().unwrap_or(dark_light::Mode::Unspecified) { + dark_light::Mode::Dark | dark_light::Mode::Unspecified => { + DARK.clone() + } + dark_light::Mode::Light => LIGHT.clone(), + } + } +} + +impl Base for Theme { + fn base(&self) -> Style { + Style { + background_color: self.colorscheme.surface.color, + text_color: self.colorscheme.surface.on_surface, + } + } +} + +#[derive(Debug, Clone, Copy, PartialEq, Deserialize)] +pub struct ColorScheme { + pub primary: Primary, + pub secondary: Secondary, + pub tertiary: Tertiary, + pub error: Error, + pub surface: Surface, + pub inverse: Inverse, + pub outline: Outline, + #[serde(with = "color_serde")] + pub shadow: Color, +} + +pub static DARK: LazyLock = LazyLock::new(|| { + toml::from_str(DARK_THEME_CONTENT).expect("parse dark theme") +}); + +pub static LIGHT: LazyLock = LazyLock::new(|| { + toml::from_str(LIGHT_THEME_CONTENT).expect("parse light theme") +}); + +#[derive(Debug, Clone, Copy, PartialEq, Deserialize)] +pub struct Primary { + #[serde(with = "color_serde")] + pub color: Color, + #[serde(with = "color_serde")] + pub on_primary: Color, + #[serde(with = "color_serde")] + pub primary_container: Color, + #[serde(with = "color_serde")] + pub on_primary_container: Color, +} + +#[derive(Debug, Clone, Copy, PartialEq, Deserialize)] +pub struct Secondary { + #[serde(with = "color_serde")] + pub color: Color, + #[serde(with = "color_serde")] + pub on_secondary: Color, + #[serde(with = "color_serde")] + pub secondary_container: Color, + #[serde(with = "color_serde")] + pub on_secondary_container: Color, +} + +#[derive(Debug, Clone, Copy, PartialEq, Deserialize)] +pub struct Tertiary { + #[serde(with = "color_serde")] + pub color: Color, + #[serde(with = "color_serde")] + pub on_tertiary: Color, + #[serde(with = "color_serde")] + pub tertiary_container: Color, + #[serde(with = "color_serde")] + pub on_tertiary_container: Color, +} + +#[derive(Debug, Clone, Copy, PartialEq, Deserialize)] +pub struct Error { + #[serde(with = "color_serde")] + pub color: Color, + #[serde(with = "color_serde")] + pub on_error: Color, + #[serde(with = "color_serde")] + pub error_container: Color, + #[serde(with = "color_serde")] + pub on_error_container: Color, +} + +#[derive(Debug, Clone, Copy, PartialEq, Deserialize)] +pub struct Surface { + #[serde(with = "color_serde")] + pub color: Color, + #[serde(with = "color_serde")] + pub on_surface: Color, + #[serde(with = "color_serde")] + pub on_surface_variant: Color, + pub surface_container: SurfaceContainer, +} + +#[derive(Debug, Clone, Copy, PartialEq, Deserialize)] +pub struct SurfaceContainer { + #[serde(with = "color_serde")] + pub lowest: Color, + #[serde(with = "color_serde")] + pub low: Color, + #[serde(with = "color_serde")] + pub base: Color, + #[serde(with = "color_serde")] + pub high: Color, + #[serde(with = "color_serde")] + pub highest: Color, +} + +#[derive(Debug, Clone, Copy, PartialEq, Deserialize)] +pub struct Inverse { + #[serde(with = "color_serde")] + pub inverse_surface: Color, + #[serde(with = "color_serde")] + pub inverse_on_surface: Color, + #[serde(with = "color_serde")] + pub inverse_primary: Color, +} + +#[derive(Debug, Clone, Copy, PartialEq, Deserialize)] +pub struct Outline { + #[serde(with = "color_serde")] + pub color: Color, + #[serde(with = "color_serde")] + pub variant: Color, +} + +pub fn parse_argb(s: &str) -> Option { + let hex = s.strip_prefix('#').unwrap_or(s); + + let parse_channel = |from: usize, to: usize| { + let num = + usize::from_str_radix(&hex[from..=to], 16).ok()? as f32 / 255.0; + + // If we only got half a byte (one letter), expand it into a full byte (two letters) + Some(if from == to { num + num * 16.0 } else { num }) + }; + + Some(match hex.len() { + 3 => Color::from_rgb( + parse_channel(0, 0)?, + parse_channel(1, 1)?, + parse_channel(2, 2)?, + ), + 4 => Color::from_rgba( + parse_channel(1, 1)?, + parse_channel(2, 2)?, + parse_channel(3, 3)?, + parse_channel(0, 0)?, + ), + 6 => Color::from_rgb( + parse_channel(0, 1)?, + parse_channel(2, 3)?, + parse_channel(4, 5)?, + ), + 8 => Color::from_rgba( + parse_channel(2, 3)?, + parse_channel(4, 5)?, + parse_channel(6, 7)?, + parse_channel(0, 1)?, + ), + _ => None?, + }) +} + +mod color_serde { + use iced_widget::core::Color; + use serde::{Deserialize, Deserializer}; + + use super::parse_argb; + + pub fn deserialize<'de, D>(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + Ok(String::deserialize(deserializer) + .map(|hex| parse_argb(&hex))? + .unwrap_or(Color::TRANSPARENT)) + } +} diff --git a/material_theme/src/text.rs b/material_theme/src/text.rs new file mode 100644 index 0000000..10b2e65 --- /dev/null +++ b/material_theme/src/text.rs @@ -0,0 +1,86 @@ +#![allow(dead_code)] +use iced_widget::text::{Catalog, Style, StyleFn}; + +use crate::Theme; + +impl Catalog for Theme { + type Class<'a> = StyleFn<'a, Self>; + + fn default<'a>() -> Self::Class<'a> { + Box::new(none) + } + + fn style(&self, class: &Self::Class<'_>) -> Style { + class(self) + } +} + +pub fn none(_: &Theme) -> Style { + Style { color: None } +} + +pub fn primary(theme: &Theme) -> Style { + Style { + color: Some(theme.colorscheme.primary.on_primary), + } +} + +pub fn primary_container(theme: &Theme) -> Style { + Style { + color: Some(theme.colorscheme.primary.on_primary_container), + } +} + +pub fn secondary(theme: &Theme) -> Style { + Style { + color: Some(theme.colorscheme.secondary.on_secondary), + } +} + +pub fn secondary_container(theme: &Theme) -> Style { + Style { + color: Some(theme.colorscheme.secondary.on_secondary_container), + } +} + +pub fn tertiary(theme: &Theme) -> Style { + Style { + color: Some(theme.colorscheme.tertiary.on_tertiary), + } +} + +pub fn tertiary_container(theme: &Theme) -> Style { + Style { + color: Some(theme.colorscheme.tertiary.on_tertiary_container), + } +} + +pub fn error(theme: &Theme) -> Style { + Style { + color: Some(theme.colorscheme.error.on_error), + } +} + +pub fn error_container(theme: &Theme) -> Style { + Style { + color: Some(theme.colorscheme.error.on_error_container), + } +} + +pub fn surface(theme: &Theme) -> Style { + Style { + color: Some(theme.colorscheme.surface.on_surface), + } +} + +pub fn surface_variant(theme: &Theme) -> Style { + Style { + color: Some(theme.colorscheme.surface.on_surface_variant), + } +} + +pub fn inverse_surface(theme: &Theme) -> Style { + Style { + color: Some(theme.colorscheme.inverse.inverse_on_surface), + } +} diff --git a/material_theme/src/utils.rs b/material_theme/src/utils.rs new file mode 100644 index 0000000..c9eb78e --- /dev/null +++ b/material_theme/src/utils.rs @@ -0,0 +1,61 @@ +use iced_widget::core::Color; + +pub fn elevation(elevation_level: u8) -> f32 { + (match elevation_level { + 0 => 0.0, + 1 => 1.0, + 2 => 3.0, + 3 => 6.0, + 4 => 8.0, + _ => 12.0, + } as f32) +} + +pub fn mix(color1: Color, color2: Color, p2: f32) -> Color { + if p2 <= 0.0 { + return color1; + } else if p2 >= 1.0 { + return color2; + } + + let p1 = 1.0 - p2; + + if color1.a != 1.0 || color2.a != 1.0 { + let a = color1.a * p1 + color2.a * p2; + if a > 0.0 { + let c1 = color1.into_linear().map(|c| c * color1.a * p1); + let c2 = color2.into_linear().map(|c| c * color2.a * p2); + + let [r, g, b] = + [c1[0] + c2[0], c1[1] + c2[1], c1[2] + c2[2]].map(|u| u / a); + + return Color::from_linear_rgba(r, g, b, a); + } + } + + let c1 = color1.into_linear().map(|c| c * p1); + let c2 = color2.into_linear().map(|c| c * p2); + + Color::from_linear_rgba( + c1[0] + c2[0], + c1[1] + c2[1], + c1[2] + c2[2], + c1[3] + c2[3], + ) +} + +#[cfg(test)] +mod tests { + use super::{Color, mix}; + + #[test] + fn mixing_works() { + let base = Color::from_rgba(1.0, 0.0, 0.0, 0.7); + let overlay = Color::from_rgba(0.0, 1.0, 0.0, 0.2); + + assert_eq!( + mix(base, overlay, 0.75).into_rgba8(), + Color::from_linear_rgba(0.53846, 0.46154, 0.0, 0.325).into_rgba8() + ); + } +} diff --git a/src/main.rs b/src/main.rs index 63e9deb..6ab4da9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,8 +35,6 @@ use types::{ Project, }; -//pub type Element<'a, Message> = iced::Element<'a, Message, OtherTheme>; - fn main() -> Result<(), Box> { let version = std::env::args() .nth(1) @@ -60,7 +58,6 @@ fn main() -> Result<(), Box> { iced::application(App::title, App::update, App::view) .font(icon::FONT) .theme(|state| state.theme.value().clone()) - //.theme(|_| theme::LIGHT.clone()) .subscription(App::subscription) .antialiasing(true) .run_with(move || App::new(config_load))?; @@ -446,21 +443,5 @@ impl App { Animation::new(&self.theme, content) .on_update(Message::SwitchTheme) .into() - //row![ - // button("filled") - // .style(theme::button::filled) - // .on_press(Message::RefreshEditorContent), - // button("elevated") - // .style(theme::button::elevated) - // .on_press(Message::RefreshEditorContent), - // button("filled tonal") - // .style(theme::button::filled_tonal) - // .on_press(Message::RefreshEditorContent), - // button("outlined") - // .style(theme::button::outlined) - // .on_press(Message::RefreshEditorContent), - //] - //.spacing(10) - //.into() } } diff --git a/src/theme.rs b/src/theme.rs index 6fe844c..232f309 100644 --- a/src/theme.rs +++ b/src/theme.rs @@ -1,18 +1,11 @@ -pub mod button; -pub mod text; - -use std::sync::{Arc, LazyLock}; +use std::sync::Arc; use iced::Color; -use iced::theme::Base; use iced::theme::palette::Extended; use serde::Deserialize; use crate::config::Config; -const DARK_THEME_CONTENT: &str = include_str!("../assets/themes/dark.toml"); -const LIGHT_THEME_CONTENT: &str = include_str!("../assets/themes/light.toml"); - pub fn theme_index(theme_name: &str, slice: &[iced::Theme]) -> Option { slice .iter() @@ -83,159 +76,6 @@ impl Default for Appearance { } } -#[derive(Debug, PartialEq, Deserialize)] -pub struct OtherTheme { - name: String, - #[serde(flatten)] - colorscheme: ColorScheme, -} - -impl Clone for OtherTheme { - fn clone(&self) -> Self { - Self { - name: self.name.clone(), - colorscheme: self.colorscheme, - } - } - - fn clone_from(&mut self, source: &Self) { - self.name = source.name.clone(); - self.colorscheme = source.colorscheme; - } -} - -impl Default for OtherTheme { - fn default() -> Self { - match dark_light::detect().unwrap_or(dark_light::Mode::Unspecified) { - dark_light::Mode::Dark | dark_light::Mode::Unspecified => { - DARK.clone() - } - dark_light::Mode::Light => LIGHT.clone(), - } - } -} - -impl Base for OtherTheme { - fn base(&self) -> iced::theme::Style { - iced::theme::Style { - background_color: self.colorscheme.surface.color, - text_color: self.colorscheme.surface.on_surface, - } - } -} - -#[derive(Debug, Clone, Copy, PartialEq, Deserialize)] -pub struct ColorScheme { - pub primary: Primary, - pub secondary: Secondary, - pub tertiary: Tertiary, - pub error: Error, - pub surface: Surface, - pub inverse: Inverse, - pub outline: Outline, - #[serde(with = "color_serde")] - pub shadow: Color, -} - -pub static DARK: LazyLock = LazyLock::new(|| { - toml::from_str(DARK_THEME_CONTENT).expect("parse dark theme") -}); - -pub static LIGHT: LazyLock = LazyLock::new(|| { - toml::from_str(LIGHT_THEME_CONTENT).expect("parse light theme") -}); - -#[derive(Debug, Clone, Copy, PartialEq, Deserialize)] -pub struct Primary { - #[serde(with = "color_serde")] - pub color: Color, - #[serde(with = "color_serde")] - pub on_primary: Color, - #[serde(with = "color_serde")] - pub primary_container: Color, - #[serde(with = "color_serde")] - pub on_primary_container: Color, -} - -#[derive(Debug, Clone, Copy, PartialEq, Deserialize)] -pub struct Secondary { - #[serde(with = "color_serde")] - pub color: Color, - #[serde(with = "color_serde")] - pub on_secondary: Color, - #[serde(with = "color_serde")] - pub secondary_container: Color, - #[serde(with = "color_serde")] - pub on_secondary_container: Color, -} - -#[derive(Debug, Clone, Copy, PartialEq, Deserialize)] -pub struct Tertiary { - #[serde(with = "color_serde")] - pub color: Color, - #[serde(with = "color_serde")] - pub on_tertiary: Color, - #[serde(with = "color_serde")] - pub tertiary_container: Color, - #[serde(with = "color_serde")] - pub on_tertiary_container: Color, -} - -#[derive(Debug, Clone, Copy, PartialEq, Deserialize)] -pub struct Error { - #[serde(with = "color_serde")] - pub color: Color, - #[serde(with = "color_serde")] - pub on_error: Color, - #[serde(with = "color_serde")] - pub error_container: Color, - #[serde(with = "color_serde")] - pub on_error_container: Color, -} - -#[derive(Debug, Clone, Copy, PartialEq, Deserialize)] -pub struct Surface { - #[serde(with = "color_serde")] - pub color: Color, - #[serde(with = "color_serde")] - pub on_surface: Color, - #[serde(with = "color_serde")] - pub on_surface_variant: Color, - pub surface_container: SurfaceContainer, -} - -#[derive(Debug, Clone, Copy, PartialEq, Deserialize)] -pub struct SurfaceContainer { - #[serde(with = "color_serde")] - pub lowest: Color, - #[serde(with = "color_serde")] - pub low: Color, - #[serde(with = "color_serde")] - pub base: Color, - #[serde(with = "color_serde")] - pub high: Color, - #[serde(with = "color_serde")] - pub highest: Color, -} - -#[derive(Debug, Clone, Copy, PartialEq, Deserialize)] -pub struct Inverse { - #[serde(with = "color_serde")] - pub inverse_surface: Color, - #[serde(with = "color_serde")] - pub inverse_on_surface: Color, - #[serde(with = "color_serde")] - pub inverse_primary: Color, -} - -#[derive(Debug, Clone, Copy, PartialEq, Deserialize)] -pub struct Outline { - #[serde(with = "color_serde")] - pub color: Color, - #[serde(with = "color_serde")] - pub variant: Color, -} - #[derive(Debug, Deserialize)] pub struct Theme { name: String, diff --git a/src/theme/button.rs b/src/theme/button.rs deleted file mode 100644 index ddd2c71..0000000 --- a/src/theme/button.rs +++ /dev/null @@ -1,189 +0,0 @@ -#![allow(dead_code)] -use iced::widget::button::{Catalog, Status, Style, StyleFn}; -use iced::{Background, Border, Color, Shadow, Vector}; - -use super::OtherTheme; - -impl Catalog for OtherTheme { - type Class<'a> = StyleFn<'a, Self>; - - fn default<'a>() -> Self::Class<'a> { - Box::new(default) - } - - fn style(&self, class: &Self::Class<'_>, status: Status) -> Style { - class(self, status) - } -} - -fn default(theme: &OtherTheme, status: Status) -> Style { - filled(theme, status) -} - -fn button( - foreground: Color, - background: Color, - background_hover: Color, - disabled: Color, - shadow_color: Color, - shadow_elevation: u8, - status: Status, -) -> Style { - let border = Border { - radius: 400.0.into(), - ..Default::default() - }; - - let elevation_to_offset = |elevation: u8| { - (match elevation { - 0 => 0.0, - 1 => 1.0, - 2 => 3.0, - 3 => 6.0, - 4 => 8.0, - _ => 12.0, - } as f32) - }; - - match status { - Status::Active | Status::Pressed => Style { - background: Some(Background::Color(background)), - text_color: foreground, - border, - shadow: Shadow { - color: shadow_color, - offset: Vector { - x: 0.0, - y: elevation_to_offset(shadow_elevation), - }, - blur_radius: elevation_to_offset(shadow_elevation) - * (1.0 - + 0.4_f32.powf(elevation_to_offset(shadow_elevation))), - }, - }, - Status::Hovered => Style { - background: Some(Background::Color(background_hover)), - text_color: foreground, - border, - shadow: Shadow { - color: shadow_color, - offset: Vector { - x: 0.0, - y: elevation_to_offset(shadow_elevation + 1), - }, - blur_radius: (elevation_to_offset(shadow_elevation + 1)) - * (1.0 - + 0.4_f32 - .powf(elevation_to_offset(shadow_elevation + 1))), - }, - }, - Status::Disabled => Style { - background: Some(Background::Color(Color { - a: 0.12, - ..disabled - })), - text_color: Color { - a: 0.38, - ..disabled - }, - border, - ..Default::default() - }, - } -} - -pub fn elevated(theme: &OtherTheme, status: Status) -> Style { - let surface_colors = theme.colorscheme.surface; - - let foreground = theme.colorscheme.primary.color; - let background = surface_colors.surface_container.low; - let disabled = surface_colors.on_surface; - - let shadow_color = theme.colorscheme.shadow; - - button( - foreground, - background, - background, - disabled, - shadow_color, - 1, - status, - ) -} - -pub fn filled(theme: &OtherTheme, status: Status) -> Style { - let primary_colors = theme.colorscheme.primary; - - let foreground = primary_colors.on_primary; - let background = primary_colors.color; - let disabled = theme.colorscheme.surface.on_surface; - - let shadow_color = theme.colorscheme.shadow; - - button( - foreground, - background, - background, - disabled, - shadow_color, - 0, - status, - ) -} - -pub fn filled_tonal(theme: &OtherTheme, status: Status) -> Style { - let secondary_colors = theme.colorscheme.secondary; - - let foreground = secondary_colors.on_secondary_container; - let background = secondary_colors.secondary_container; - let disabled = theme.colorscheme.surface.on_surface; - - let shadow_color = theme.colorscheme.shadow; - - button( - foreground, - background, - background, - disabled, - shadow_color, - 0, - status, - ) -} - -pub fn outlined(theme: &OtherTheme, status: Status) -> Style { - let foreground = theme.colorscheme.primary.color; - let background = Color::TRANSPARENT; - let disabled = theme.colorscheme.surface.on_surface; - - let outline = theme.colorscheme.outline.color; - - let border = match status { - Status::Active | Status::Pressed | Status::Hovered => Border { - color: outline, - width: 1.0, - radius: 400.0.into(), - }, - Status::Disabled => Border { - color: Color { - a: 0.12, - ..disabled - }, - width: 1.0, - radius: 400.0.into(), - }, - }; - - let style = button( - foreground, - background, - background, - disabled, - Color::TRANSPARENT, - 0, - status, - ); - - Style { border, ..style } -} diff --git a/src/theme/text.rs b/src/theme/text.rs deleted file mode 100644 index 9cbd056..0000000 --- a/src/theme/text.rs +++ /dev/null @@ -1,50 +0,0 @@ -#![allow(dead_code)] -use iced::widget::text::{Catalog, Style, StyleFn}; - -use super::OtherTheme; - -impl Catalog for OtherTheme { - type Class<'a> = StyleFn<'a, Self>; - - fn default<'a>() -> Self::Class<'a> { - Box::new(none) - } - - fn style(&self, class: &Self::Class<'_>) -> Style { - class(self) - } -} - -pub fn none(_: &OtherTheme) -> Style { - Style { color: None } -} - -pub fn primary(theme: &OtherTheme) -> Style { - Style { - color: Some(theme.colorscheme.primary.on_primary), - } -} - -pub fn secondary(theme: &OtherTheme) -> Style { - Style { - color: Some(theme.colorscheme.secondary.on_secondary), - } -} - -pub fn tertiary(theme: &OtherTheme) -> Style { - Style { - color: Some(theme.colorscheme.tertiary.on_tertiary), - } -} - -pub fn error(theme: &OtherTheme) -> Style { - Style { - color: Some(theme.colorscheme.error.on_error), - } -} - -pub fn surface(theme: &OtherTheme) -> Style { - Style { - color: Some(theme.colorscheme.surface.on_surface), - } -} diff --git a/theme_test/Cargo.toml b/theme_test/Cargo.toml new file mode 100644 index 0000000..34008eb --- /dev/null +++ b/theme_test/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "theme_test" +version = "0.0.1" +edition = "2024" + +[dependencies] +iced.workspace = true +material_theme = { path = "../material_theme" } diff --git a/theme_test/src/main.rs b/theme_test/src/main.rs new file mode 100644 index 0000000..c4735be --- /dev/null +++ b/theme_test/src/main.rs @@ -0,0 +1,89 @@ +use iced::Element; +use iced::widget::{button, column, container, row, text}; +use material_theme::Theme; +use material_theme::button::{ + elevated, filled_tonal, outlined, text as text_style, +}; +use material_theme::container::{ + error, error_container, inverse_surface, primary, primary_container, + secondary, secondary_container, surface, surface_container, + surface_container_high, surface_container_highest, surface_container_low, + surface_container_lowest, tertiary, tertiary_container, +}; +use material_theme::text::surface_variant; + +fn main() { + iced::application("Theme Test", (), view) + .theme(|_| material_theme::DARK.clone()) + .run() + .unwrap(); +} + +#[derive(Debug, Clone)] +enum Message { + Noop, +} + +fn view(_: &()) -> Element<'_, Message, Theme> { + container( + row![ + column![ + button("Disabled"), + button("Filled").on_press(Message::Noop), + button("Filled Tonal") + .on_press(Message::Noop) + .style(filled_tonal), + button("Elevated").on_press(Message::Noop).style(elevated), + button("Outlined").on_press(Message::Noop).style(outlined), + button("Text").on_press(Message::Noop).style(text_style), + button("Text Disabled").style(text_style), + ] + .spacing(10), + column![ + text("None"), + container("Primary").padding(8).style(primary), + container("Primary Container") + .padding(8) + .style(primary_container), + container("Secondary").padding(8).style(secondary), + container("Secondary Container") + .padding(8) + .style(secondary_container), + container("Tertiary").padding(8).style(tertiary), + container("Tertiary Container") + .padding(8) + .style(tertiary_container), + container("Error").padding(8).style(error), + container("Error Container") + .padding(8) + .style(error_container), + container("Surface").padding(8).style(surface), + container(text("Surface Variant").style(surface_variant)) + .padding(8) + .style(surface), + container("Inverse Surface") + .padding(8) + .style(inverse_surface), + container("Surface Container Lowest") + .padding(8) + .style(surface_container_lowest), + container("Surface Container Low") + .padding(8) + .style(surface_container_low), + container("Surface Container") + .padding(8) + .style(surface_container), + container("Surface Container High") + .padding(8) + .style(surface_container_high), + container("Surface Container Highest") + .padding(8) + .style(surface_container_highest), + ] + .spacing(10) + ] + .spacing(20), + ) + .padding(12) + .into() +} -- cgit v1.2.3 From c6a76e63604b16b9a14d5de6bd0ea91eea7f9bf2 Mon Sep 17 00:00:00 2001 From: pml68 Date: Tue, 8 Apr 2025 01:13:38 +0200 Subject: feat(material_theme): implement Catalog for iced_dialog (`dialog` feature) --- Cargo.lock | 2 ++ Cargo.toml | 3 +- material_theme/Cargo.toml | 3 ++ material_theme/src/lib.rs | 74 ++++++++++++++++++++++++++--------------------- src/main.rs | 17 ++++++----- src/panes/element_list.rs | 11 +++---- 6 files changed, 61 insertions(+), 49 deletions(-) (limited to 'Cargo.lock') 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) { - let mut colors = self.colorscheme; - colors.update(components); - - *self = Theme::new("Animating Theme", colors); - } - - fn distance_to(&self, end: &Self) -> Vec { - 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) { + let mut colors = self.colorscheme; + colors.update(components); + + *self = Theme::new("Animating Theme", colors); + } + + fn distance_to(&self, end: &Self) -> Vec { + 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>() + -> ::Class<'a> { + Box::new(container::surface) + } +} + +pub static DARK: LazyLock = LazyLock::new(|| { + toml::from_str(DARK_THEME_CONTENT).expect("parse dark theme") +}); + +pub static LIGHT: LazyLock = 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 = LazyLock::new(|| { - toml::from_str(DARK_THEME_CONTENT).expect("parse dark theme") -}); - -pub static LIGHT: LazyLock = 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> { @@ -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) -- cgit v1.2.3 From 941eb51e043b6b847089130625c2df10b0674154 Mon Sep 17 00:00:00 2001 From: pml68 Date: Wed, 9 Apr 2025 00:29:34 +0200 Subject: feat: update `iced`, make designer view more usable --- Cargo.lock | 252 +++++++++++++++++++++++------------------- Cargo.toml | 4 +- src/main.rs | 18 ++- src/panes/designer_view.rs | 19 +++- src/types/rendered_element.rs | 42 ++++--- 5 files changed, 193 insertions(+), 142 deletions(-) (limited to 'Cargo.lock') diff --git a/Cargo.lock b/Cargo.lock index b2ab721..a324ccd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -57,6 +57,12 @@ dependencies = [ "zerocopy 0.7.35", ] +[[package]] +name = "aliasable" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "250f629c0161ad8107cf89319e990051fae62832fd343083bea452d93e2205fd" + [[package]] name = "aligned-vec" version = "0.5.0" @@ -105,15 +111,6 @@ version = "1.0.97" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcfed56ad506cb2c684a14971b8861fdc3baaaae314b9e5f9bb532cbe3ba7a4f" -[[package]] -name = "approx" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cab112f0a86d568ea0e627cc1d6be74a1e9cd55214684db5561995f6dad897c6" -dependencies = [ - "num-traits", -] - [[package]] name = "arbitrary" version = "1.4.1" @@ -569,12 +566,6 @@ version = "3.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf" -[[package]] -name = "by_address" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64fa3c856b712db6612c019f14756e64e4bcea13337a6b33b696333a9eaa2d06" - [[package]] name = "bytemuck" version = "1.22.0" @@ -1316,12 +1307,6 @@ dependencies = [ "zune-inflate", ] -[[package]] -name = "fast-srgb8" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd2e7510819d6fbf51a5545c8f922716ecfb14df168a3242f7d33e0239efe6a1" - [[package]] name = "fastrand" version = "2.3.0" @@ -1767,9 +1752,9 @@ dependencies = [ [[package]] name = "half" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7db2ff139bba50379da6aa0766b52fdcb62cb5b263009b09ed58ba604e14bbd1" +checksum = "459196ed295495a68f7d7fe1d84f6c4b7ff0e21fe3017b2f283c6fac3ad803c9" dependencies = [ "cfg-if", "crunchy", @@ -1784,6 +1769,12 @@ dependencies = [ "foldhash", ] +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + [[package]] name = "heck" version = "0.5.0" @@ -1938,11 +1929,14 @@ dependencies = [ [[package]] name = "iced" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#1a84a8019cbd95ae1b1c88f75aeb0a15f0f3caf2" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#add48e518b3423bed980983ddc373cfb8f5e8980" dependencies = [ "iced_core", + "iced_debug", + "iced_devtools", "iced_futures", "iced_renderer", + "iced_runtime", "iced_widget", "iced_winit", "image", @@ -1967,6 +1961,21 @@ dependencies = [ "syn", ] +[[package]] +name = "iced_beacon" +version = "0.14.0-dev" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#add48e518b3423bed980983ddc373cfb8f5e8980" +dependencies = [ + "bincode", + "futures", + "iced_core", + "log", + "semver", + "serde", + "thiserror 1.0.69", + "tokio", +] + [[package]] name = "iced_builder" version = "0.1.0" @@ -1996,7 +2005,7 @@ dependencies = [ [[package]] name = "iced_core" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#1a84a8019cbd95ae1b1c88f75aeb0a15f0f3caf2" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#add48e518b3423bed980983ddc373cfb8f5e8980" dependencies = [ "bitflags 2.9.0", "bytes", @@ -2005,8 +2014,8 @@ dependencies = [ "lilt", "log", "num-traits", - "palette", "rustc-hash 2.1.1", + "serde", "smol_str", "thiserror 1.0.69", "web-time", @@ -2022,6 +2031,26 @@ dependencies = [ "two-face", ] +[[package]] +name = "iced_debug" +version = "0.14.0-dev" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#add48e518b3423bed980983ddc373cfb8f5e8980" +dependencies = [ + "iced_beacon", + "iced_core", + "log", +] + +[[package]] +name = "iced_devtools" +version = "0.14.0-dev" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#add48e518b3423bed980983ddc373cfb8f5e8980" +dependencies = [ + "iced_debug", + "iced_program", + "iced_widget", +] + [[package]] name = "iced_dialog" version = "0.14.0-dev" @@ -2055,7 +2084,7 @@ dependencies = [ [[package]] name = "iced_futures" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#1a84a8019cbd95ae1b1c88f75aeb0a15f0f3caf2" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#add48e518b3423bed980983ddc373cfb8f5e8980" dependencies = [ "futures", "iced_core", @@ -2069,7 +2098,7 @@ dependencies = [ [[package]] name = "iced_graphics" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#1a84a8019cbd95ae1b1c88f75aeb0a15f0f3caf2" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#add48e518b3423bed980983ddc373cfb8f5e8980" dependencies = [ "bitflags 2.9.0", "bytemuck", @@ -2086,10 +2115,19 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "iced_program" +version = "0.14.0-dev" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#add48e518b3423bed980983ddc373cfb8f5e8980" +dependencies = [ + "iced_graphics", + "iced_runtime", +] + [[package]] name = "iced_renderer" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#1a84a8019cbd95ae1b1c88f75aeb0a15f0f3caf2" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#add48e518b3423bed980983ddc373cfb8f5e8980" dependencies = [ "iced_graphics", "iced_tiny_skia", @@ -2101,20 +2139,20 @@ dependencies = [ [[package]] name = "iced_runtime" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#1a84a8019cbd95ae1b1c88f75aeb0a15f0f3caf2" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#add48e518b3423bed980983ddc373cfb8f5e8980" dependencies = [ "bytes", "iced_core", + "iced_debug", "iced_futures", "raw-window-handle", - "sipper", "thiserror 1.0.69", ] [[package]] name = "iced_tiny_skia" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#1a84a8019cbd95ae1b1c88f75aeb0a15f0f3caf2" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#add48e518b3423bed980983ddc373cfb8f5e8980" dependencies = [ "bytemuck", "cosmic-text", @@ -2130,7 +2168,7 @@ dependencies = [ [[package]] name = "iced_wgpu" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#1a84a8019cbd95ae1b1c88f75aeb0a15f0f3caf2" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#add48e518b3423bed980983ddc373cfb8f5e8980" dependencies = [ "bitflags 2.9.0", "bytemuck", @@ -2149,12 +2187,13 @@ dependencies = [ [[package]] name = "iced_widget" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#1a84a8019cbd95ae1b1c88f75aeb0a15f0f3caf2" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#add48e518b3423bed980983ddc373cfb8f5e8980" dependencies = [ "iced_renderer", "iced_runtime", "log", "num-traits", + "ouroboros", "rustc-hash 2.1.1", "thiserror 1.0.69", "unicode-segmentation", @@ -2163,11 +2202,10 @@ dependencies = [ [[package]] name = "iced_winit" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#1a84a8019cbd95ae1b1c88f75aeb0a15f0f3caf2" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#add48e518b3423bed980983ddc373cfb8f5e8980" dependencies = [ - "iced_futures", - "iced_graphics", - "iced_runtime", + "iced_debug", + "iced_program", "log", "rustc-hash 2.1.1", "thiserror 1.0.69", @@ -2758,9 +2796,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.8.5" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e3e04debbb59698c15bacbb6d93584a8c0ca9cc3213cb423d31f760d8843ce5" +checksum = "3be647b768db090acb35d5ec5db2b0e1f1de11133ca123b9eacf5137868f892a" dependencies = [ "adler2", "simd-adler32", @@ -3347,36 +3385,36 @@ dependencies = [ ] [[package]] -name = "owned_ttf_parser" -version = "0.25.0" +name = "ouroboros" +version = "0.18.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22ec719bbf3b2a81c109a4e20b1f129b5566b7dce654bc3872f6a05abf82b2c4" +checksum = "1e0f050db9c44b97a94723127e6be766ac5c340c48f2c4bb3ffa11713744be59" dependencies = [ - "ttf-parser 0.25.1", + "aliasable", + "ouroboros_macro", + "static_assertions", ] [[package]] -name = "palette" -version = "0.7.6" +name = "ouroboros_macro" +version = "0.18.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cbf71184cc5ecc2e4e1baccdb21026c20e5fc3dcf63028a086131b3ab00b6e6" +checksum = "3c7028bdd3d43083f6d8d4d5187680d0d3560d54df4cc9d752005268b41e64d0" dependencies = [ - "approx", - "fast-srgb8", - "palette_derive", - "phf", + "heck 0.4.1", + "proc-macro2", + "proc-macro2-diagnostics", + "quote", + "syn", ] [[package]] -name = "palette_derive" -version = "0.7.6" +name = "owned_ttf_parser" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5030daf005bface118c096f510ffb781fc28f9ab6a32ab224d8631be6851d30" +checksum = "22ec719bbf3b2a81c109a4e20b1f129b5566b7dce654bc3872f6a05abf82b2c4" dependencies = [ - "by_address", - "proc-macro2", - "quote", - "syn", + "ttf-parser 0.25.1", ] [[package]] @@ -3430,48 +3468,6 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" -[[package]] -name = "phf" -version = "0.11.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd6780a80ae0c52cc120a26a1a42c1ae51b247a253e4e06113d23d2c2edd078" -dependencies = [ - "phf_macros", - "phf_shared", -] - -[[package]] -name = "phf_generator" -version = "0.11.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c80231409c20246a13fddb31776fb942c38553c51e871f8cbd687a4cfb5843d" -dependencies = [ - "phf_shared", - "rand 0.8.5", -] - -[[package]] -name = "phf_macros" -version = "0.11.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f84ac04429c13a7ff43785d75ad27569f2951ce0ffd30a3321230db2fc727216" -dependencies = [ - "phf_generator", - "phf_shared", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "phf_shared" -version = "0.11.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67eabc2ef2a60eb7faa00097bd1ffdb5bd28e62bf39990626a582201b7a754e5" -dependencies = [ - "siphasher", -] - [[package]] name = "pico-args" version = "0.5.0" @@ -3600,6 +3596,19 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "proc-macro2-diagnostics" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af066a9c399a26e020ada66a034357a868728e72cd426f3adcd35f80d88d88c8" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "version_check", + "yansi", +] + [[package]] name = "profiling" version = "1.0.16" @@ -4176,6 +4185,9 @@ name = "semver" version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56e6fa9c48d24d85fb3de5ad847117517440f6beceb7798af16b4a87d616b8d0" +dependencies = [ + "serde", +] [[package]] name = "serde" @@ -4308,16 +4320,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d" -[[package]] -name = "sipper" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bccb4192828b3d9a08e0b5a73f17795080dfb278b50190216e3ae2132cf4f95" -dependencies = [ - "futures", - "pin-project-lite", -] - [[package]] name = "skrifa" version = "0.26.6" @@ -4484,7 +4486,7 @@ version = "0.26.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" dependencies = [ - "heck", + "heck 0.5.0", "proc-macro2", "quote", "rustversion", @@ -4612,7 +4614,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3e535eb8dded36d55ec13eddacd30dec501792ff23a0b1682c38601b8cf2349" dependencies = [ "cfg-expr", - "heck", + "heck 0.5.0", "pkg-config", "toml", "version-compare", @@ -4790,9 +4792,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.44.1" +version = "1.44.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f382da615b842244d4b8738c82ed1275e6c5dd90c459a30941cd07080b06c91a" +checksum = "e6b88822cbe49de4185e3a4cbf8321dd487cf5fe0c5c65695fef6346371e9c48" dependencies = [ "backtrace", "bytes", @@ -4800,9 +4802,21 @@ dependencies = [ "mio", "pin-project-lite", "socket2", + "tokio-macros", "windows-sys 0.52.0", ] +[[package]] +name = "tokio-macros" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "tokio-native-tls" version = "0.3.1" @@ -6029,9 +6043,9 @@ dependencies = [ [[package]] name = "winnow" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e97b544156e9bebe1a0ffbc03484fc1ffe3100cbce3ffb17eac35f7cdd7ab36" +checksum = "63d3fcd9bba44b03821e7d699eeee959f3126dcc4aa8e4ae18ec617c2a5cea10" dependencies = [ "memchr", ] @@ -6161,6 +6175,12 @@ dependencies = [ "lzma-sys", ] +[[package]] +name = "yansi" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049" + [[package]] name = "yazi" version = "0.2.1" diff --git a/Cargo.toml b/Cargo.toml index 63e5f89..e48a39c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ material_theme = { path = "material_theme" } serde.workspace = true serde_json = "1.0.140" toml.workspace = true -tokio = { version = "1.42.1", features = ["fs"] } +tokio = { version = "1.44.2", features = ["fs"] } tokio-stream = { version = "0.1", features = ["fs"] } # TODO: enable tokio when it actually compiles # rfd = { version = "0.15.2", default-features = false, features = ["tokio", "xdg-portal"] } @@ -43,7 +43,7 @@ toml = "0.8.20" [workspace.dependencies.iced] git = "https://github.com/pml68/iced" branch = "feat/rehighlight-on-redraw" -features = ["image", "svg", "advanced", "tokio"] +features = ["image", "svg", "advanced", "tokio", "lazy"] [build-dependencies] iced_fontello = "0.13.2" diff --git a/src/main.rs b/src/main.rs index 3895dbc..d58329a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -54,12 +54,18 @@ fn main() -> Result<(), Box> { rt.block_on(Config::load()) }; - iced::application(App::title, App::update, App::view) - .font(icon::FONT) - .theme(|state| state.theme.value().clone()) - .subscription(App::subscription) - .antialiasing(true) - .run_with(move || App::new(config_load))?; + iced::application( + move || App::new(config_load.clone()), + App::update, + App::view, + ) + .title(App::title) + .font(icon::FONT) + .theme(|state| state.theme.value().clone()) + .subscription(App::subscription) + .antialiasing(true) + .run()?; + Ok(()) } diff --git a/src/panes/designer_view.rs b/src/panes/designer_view.rs index 6340f73..69ff750 100644 --- a/src/panes/designer_view.rs +++ b/src/panes/designer_view.rs @@ -1,16 +1,29 @@ -use iced::widget::{Space, button, container, pane_grid, row, text, themer}; +use iced::widget::{ + Space, button, center, container, pane_grid, responsive, row, text, themer, +}; use iced::{Alignment, Element, Length}; use super::style; use crate::types::{DesignerPane, Message, RenderedElement}; pub fn view<'a>( - element_tree: Option<&RenderedElement>, + element_tree: Option<&'a RenderedElement>, designer_theme: iced::Theme, is_focused: bool, ) -> pane_grid::Content<'a, Message> { let el_tree: Element<'a, Message> = match element_tree { - Some(tree) => tree.clone().into(), + Some(tree) => responsive(|size| { + center( + container(tree.clone()) + .style(|theme| { + container::background(theme.palette().background) + }) + .height(size.height * 0.5) + .width(size.height * 0.8), + ) + .into() + }) + .into(), None => text("Open a project or begin creating one").into(), }; let content = container(themer(designer_theme, el_tree)) diff --git a/src/types/rendered_element.rs b/src/types/rendered_element.rs index 77b76e4..bd8187e 100755 --- a/src/types/rendered_element.rs +++ b/src/types/rendered_element.rs @@ -340,15 +340,19 @@ impl<'a> From for Element<'a, Message> { 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, - ), + widget::container("New Container").style( + |theme: &iced::Theme| widget::container::Style { + border: iced::Border { + color: theme.palette().text, + + width: 2.0, + radius: 4.into(), + }, ..Default::default() - }) + }, + ) } + .padding(20) .apply_options(copy.options) .into(), ElementName::Row => { @@ -356,6 +360,7 @@ impl<'a> From for Element<'a, Message> { widget::Row::with_children( child_elements.into_iter().map(Into::into), ) + .padding(20) .apply_options(copy.options) .into() } else { @@ -364,10 +369,13 @@ impl<'a> From for Element<'a, Message> { .padding(20) .apply_options(copy.options), ) - .style(|theme| widget::container::Style { - border: iced::border::rounded(4).color( - theme.extended_palette().background.strongest.text, - ), + .style(|theme: &iced::Theme| widget::container::Style { + border: iced::Border { + color: theme.palette().text, + + width: 2.0, + radius: 4.into(), + }, ..Default::default() }) .into() @@ -378,6 +386,7 @@ impl<'a> From for Element<'a, Message> { widget::Column::with_children( child_elements.into_iter().map(Into::into), ) + .padding(20) .apply_options(copy.options) .into() } else { @@ -386,10 +395,13 @@ impl<'a> From for Element<'a, Message> { .padding(20) .apply_options(copy.options), ) - .style(|theme| widget::container::Style { - border: iced::border::rounded(4).color( - theme.extended_palette().background.strongest.text, - ), + .style(|theme: &iced::Theme| widget::container::Style { + border: iced::Border { + color: theme.palette().text, + + width: 2.0, + radius: 4.into(), + }, ..Default::default() }) .into() -- cgit v1.2.3 From 68f4ed46b1846e27c03f23d0b98e3ce89dc497b8 Mon Sep 17 00:00:00 2001 From: pml68 Date: Sun, 13 Apr 2025 03:31:36 +0200 Subject: feat(material_theme): implement `pick_list::Catalog` --- Cargo.lock | 68 ++++++------ material_theme/Cargo.toml | 1 + material_theme/README.md | 3 + material_theme/assets/themes/dark.toml | 1 + material_theme/assets/themes/light.toml | 1 + material_theme/src/lib.rs | 49 ++------- material_theme/src/menu.rs | 16 +-- material_theme/src/pick_list.rs | 40 +++++++ material_theme/src/utils.rs | 38 +++++++ theme_test/Cargo.toml | 4 +- theme_test/src/main.rs | 184 ++++++++++++++++++++------------ 11 files changed, 258 insertions(+), 147 deletions(-) create mode 100644 material_theme/README.md create mode 100644 material_theme/src/pick_list.rs (limited to 'Cargo.lock') diff --git a/Cargo.lock b/Cargo.lock index a324ccd..0143fbd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -649,17 +649,11 @@ dependencies = [ "wayland-client", ] -[[package]] -name = "camino" -version = "1.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b96ec4966b5813e2c0507c1f86115c8c5abaadc3980879c3424042a02fd1ad3" - [[package]] name = "cc" -version = "1.2.17" +version = "1.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fcb57c740ae1daf453ae85f16e37396f672b039e00d9d866e07ddb24e328e3a" +checksum = "8e3a13707ac958681c13b39b458c073d0d9bc8a22cb1b2f4c8e55eb72c13f362" dependencies = [ "jobserver", "libc", @@ -860,9 +854,9 @@ dependencies = [ [[package]] name = "cosmic-text" -version = "0.13.2" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e418dd4f5128c3e93eab12246391c54a20c496811131f85754dc8152ee207892" +checksum = "1db686e755000c93f73a3acc78be56a71e3efb83ed92886f45faea2b9485bad7" dependencies = [ "bitflags 2.9.0", "fontdb 0.16.2", @@ -948,7 +942,7 @@ checksum = "43da5946c66ffcc7745f48db692ffbb10a83bfe0afd96235c5c2a4fb23994929" [[package]] name = "cryoglyph" version = "0.1.0" -source = "git+https://github.com/iced-rs/cryoglyph.git?rev=be2defe4a13fd7c97c6f4c81e8e085463eb578dc#be2defe4a13fd7c97c6f4c81e8e085463eb578dc" +source = "git+https://github.com/iced-rs/cryoglyph.git?rev=a456d1c17bbcf33afcca41d9e5e299f9f1193819#a456d1c17bbcf33afcca41d9e5e299f9f1193819" dependencies = [ "cosmic-text", "etagere", @@ -1929,7 +1923,7 @@ dependencies = [ [[package]] name = "iced" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#add48e518b3423bed980983ddc373cfb8f5e8980" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#4f933c3b8919a115fa82d9aee94ec5b1c81c4dfe" dependencies = [ "iced_core", "iced_debug", @@ -1964,7 +1958,7 @@ dependencies = [ [[package]] name = "iced_beacon" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#add48e518b3423bed980983ddc373cfb8f5e8980" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#4f933c3b8919a115fa82d9aee94ec5b1c81c4dfe" dependencies = [ "bincode", "futures", @@ -2005,7 +1999,7 @@ dependencies = [ [[package]] name = "iced_core" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#add48e518b3423bed980983ddc373cfb8f5e8980" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#4f933c3b8919a115fa82d9aee94ec5b1c81c4dfe" dependencies = [ "bitflags 2.9.0", "bytes", @@ -2034,7 +2028,7 @@ dependencies = [ [[package]] name = "iced_debug" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#add48e518b3423bed980983ddc373cfb8f5e8980" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#4f933c3b8919a115fa82d9aee94ec5b1c81c4dfe" dependencies = [ "iced_beacon", "iced_core", @@ -2044,7 +2038,7 @@ dependencies = [ [[package]] name = "iced_devtools" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#add48e518b3423bed980983ddc373cfb8f5e8980" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#4f933c3b8919a115fa82d9aee94ec5b1c81c4dfe" dependencies = [ "iced_debug", "iced_program", @@ -2054,7 +2048,7 @@ dependencies = [ [[package]] name = "iced_dialog" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced_dialog?branch=iced%2Fpersonal#6bd6c48b55201116791c59e73779613d617615c7" +source = "git+https://github.com/pml68/iced_dialog?branch=iced%2Fpersonal#c0f931f38ac83e77cfb937d4166fa8d2a23988cf" dependencies = [ "iced_core", "iced_widget", @@ -2084,7 +2078,7 @@ dependencies = [ [[package]] name = "iced_futures" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#add48e518b3423bed980983ddc373cfb8f5e8980" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#4f933c3b8919a115fa82d9aee94ec5b1c81c4dfe" dependencies = [ "futures", "iced_core", @@ -2098,7 +2092,7 @@ dependencies = [ [[package]] name = "iced_graphics" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#add48e518b3423bed980983ddc373cfb8f5e8980" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#4f933c3b8919a115fa82d9aee94ec5b1c81c4dfe" dependencies = [ "bitflags 2.9.0", "bytemuck", @@ -2118,7 +2112,7 @@ dependencies = [ [[package]] name = "iced_program" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#add48e518b3423bed980983ddc373cfb8f5e8980" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#4f933c3b8919a115fa82d9aee94ec5b1c81c4dfe" dependencies = [ "iced_graphics", "iced_runtime", @@ -2127,7 +2121,7 @@ dependencies = [ [[package]] name = "iced_renderer" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#add48e518b3423bed980983ddc373cfb8f5e8980" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#4f933c3b8919a115fa82d9aee94ec5b1c81c4dfe" dependencies = [ "iced_graphics", "iced_tiny_skia", @@ -2139,7 +2133,7 @@ dependencies = [ [[package]] name = "iced_runtime" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#add48e518b3423bed980983ddc373cfb8f5e8980" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#4f933c3b8919a115fa82d9aee94ec5b1c81c4dfe" dependencies = [ "bytes", "iced_core", @@ -2152,10 +2146,11 @@ dependencies = [ [[package]] name = "iced_tiny_skia" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#add48e518b3423bed980983ddc373cfb8f5e8980" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#4f933c3b8919a115fa82d9aee94ec5b1c81c4dfe" dependencies = [ "bytemuck", "cosmic-text", + "iced_debug", "iced_graphics", "kurbo 0.10.4", "log", @@ -2168,7 +2163,7 @@ dependencies = [ [[package]] name = "iced_wgpu" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#add48e518b3423bed980983ddc373cfb8f5e8980" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#4f933c3b8919a115fa82d9aee94ec5b1c81c4dfe" dependencies = [ "bitflags 2.9.0", "bytemuck", @@ -2176,6 +2171,7 @@ dependencies = [ "futures", "glam", "guillotiere", + "iced_debug", "iced_graphics", "log", "resvg", @@ -2187,7 +2183,7 @@ dependencies = [ [[package]] name = "iced_widget" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#add48e518b3423bed980983ddc373cfb8f5e8980" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#4f933c3b8919a115fa82d9aee94ec5b1c81c4dfe" dependencies = [ "iced_renderer", "iced_runtime", @@ -2202,7 +2198,7 @@ dependencies = [ [[package]] name = "iced_winit" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#add48e518b3423bed980983ddc373cfb8f5e8980" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#4f933c3b8919a115fa82d9aee94ec5b1c81c4dfe" dependencies = [ "iced_debug", "iced_program", @@ -2625,9 +2621,9 @@ checksum = "2a385b1be4e5c3e362ad2ffa73c392e53f031eaa5b7d648e64cd87f27f6063d7" [[package]] name = "linux-raw-sys" -version = "0.9.3" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe7db12097d22ec582439daf8618b8fdd1a7bef6270e9af3b1ebcd30893cf413" +checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12" [[package]] name = "litemap" @@ -4036,15 +4032,15 @@ dependencies = [ "bitflags 2.9.0", "errno", "libc", - "linux-raw-sys 0.9.3", + "linux-raw-sys 0.9.4", "windows-sys 0.59.0", ] [[package]] name = "rustls" -version = "0.23.25" +version = "0.23.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "822ee9188ac4ec04a2f0531e55d035fb2de73f18b41a63c70c2712503b6fb13c" +checksum = "df51b5869f3a441595eac5e8ff14d486ff285f7b8c0df8770e49c3b56351f0f0" dependencies = [ "once_cell", "rustls-pki-types", @@ -4176,9 +4172,9 @@ dependencies = [ [[package]] name = "self_cell" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2fdfc24bc566f839a2da4c4295b82db7d25a24253867d5c64355abb5799bdbe" +checksum = "0f7d95a54511e0c7be3f51e8867aa8cf35148d7b9445d44de2f943e2b206e749" [[package]] name = "semver" @@ -4653,6 +4649,8 @@ name = "theme_test" version = "0.0.1" dependencies = [ "iced", + "iced_anim", + "iced_dialog", "material_theme", ] @@ -6156,9 +6154,9 @@ checksum = "b9cc00251562a284751c9973bace760d86c0276c471b4be569fe6b068ee97a56" [[package]] name = "xml-rs" -version = "0.8.25" +version = "0.8.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5b940ebc25896e71dd073bad2dbaa2abfe97b0a391415e22ad1326d9c54e3c4" +checksum = "a62ce76d9b56901b19a74f19431b0d8b3bc7ca4ad685a746dfd78ca8f4fc6bda" [[package]] name = "xmlwriter" diff --git a/material_theme/Cargo.toml b/material_theme/Cargo.toml index e88ce92..eef9605 100644 --- a/material_theme/Cargo.toml +++ b/material_theme/Cargo.toml @@ -30,6 +30,7 @@ features = ["derive"] optional = true [lints.rust] +missing_debug_implementations = "deny" unsafe_code = "deny" unused_results = "deny" diff --git a/material_theme/README.md b/material_theme/README.md new file mode 100644 index 0000000..da5a1ec --- /dev/null +++ b/material_theme/README.md @@ -0,0 +1,3 @@ +# material_theme + +## A [Material3](https://m3.material.io) inspired custom theme for [`iced`](https://iced.rs) diff --git a/material_theme/assets/themes/dark.toml b/material_theme/assets/themes/dark.toml index 4d23fc8..18a369f 100644 --- a/material_theme/assets/themes/dark.toml +++ b/material_theme/assets/themes/dark.toml @@ -1,6 +1,7 @@ name = "Dark" shadow = "#000000" +scrim = "#4d000000" [primary] color = "#9bd4a1" diff --git a/material_theme/assets/themes/light.toml b/material_theme/assets/themes/light.toml index 5288c84..a7115c4 100644 --- a/material_theme/assets/themes/light.toml +++ b/material_theme/assets/themes/light.toml @@ -1,6 +1,7 @@ name = "Light" shadow = "#000000" +scrim = "#4d000000" [primary] color = "#34693f" diff --git a/material_theme/src/lib.rs b/material_theme/src/lib.rs index ba9d478..521af2c 100644 --- a/material_theme/src/lib.rs +++ b/material_theme/src/lib.rs @@ -9,6 +9,7 @@ pub mod container; #[cfg(feature = "dialog")] pub mod dialog; pub mod menu; +pub mod pick_list; pub mod scrollable; pub mod text; pub mod utils; @@ -62,6 +63,12 @@ impl Default for Theme { } } +impl std::fmt::Display for Theme { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.name) + } +} + impl Base for Theme { fn base(&self) -> Style { Style { @@ -121,6 +128,8 @@ pub struct ColorScheme { pub outline: Outline, #[serde(with = "color_serde")] pub shadow: Color, + #[serde(with = "color_serde")] + pub scrim: Color, } #[derive(Debug, Clone, Copy, PartialEq, Deserialize)] @@ -222,49 +231,11 @@ pub struct Outline { pub variant: Color, } -pub fn parse_argb(s: &str) -> Option { - let hex = s.strip_prefix('#').unwrap_or(s); - - let parse_channel = |from: usize, to: usize| { - let num = - usize::from_str_radix(&hex[from..=to], 16).ok()? as f32 / 255.0; - - // If we only got half a byte (one letter), expand it into a full byte (two letters) - Some(if from == to { num + num * 16.0 } else { num }) - }; - - Some(match hex.len() { - 3 => Color::from_rgb( - parse_channel(0, 0)?, - parse_channel(1, 1)?, - parse_channel(2, 2)?, - ), - 4 => Color::from_rgba( - parse_channel(1, 1)?, - parse_channel(2, 2)?, - parse_channel(3, 3)?, - parse_channel(0, 0)?, - ), - 6 => Color::from_rgb( - parse_channel(0, 1)?, - parse_channel(2, 3)?, - parse_channel(4, 5)?, - ), - 8 => Color::from_rgba( - parse_channel(2, 3)?, - parse_channel(4, 5)?, - parse_channel(6, 7)?, - parse_channel(0, 1)?, - ), - _ => None?, - }) -} - mod color_serde { use iced_widget::core::Color; use serde::{Deserialize, Deserializer}; - use super::parse_argb; + use super::utils::parse_argb; pub fn deserialize<'de, D>(deserializer: D) -> Result where diff --git a/material_theme/src/menu.rs b/material_theme/src/menu.rs index d1bebec..9f43c72 100644 --- a/material_theme/src/menu.rs +++ b/material_theme/src/menu.rs @@ -2,6 +2,7 @@ use iced_widget::core::{Background, border}; use iced_widget::overlay::menu::{Catalog, Style, StyleFn}; use super::Theme; +use crate::utils::{HOVERED_LAYER_OPACITY, mix}; impl Catalog for Theme { type Class<'a> = StyleFn<'a, Self>; @@ -16,14 +17,17 @@ impl Catalog for Theme { } pub fn default(theme: &Theme) -> Style { - let surface = theme.colorscheme.surface; - let secondary = theme.colorscheme.secondary; + let colors = theme.colorscheme.surface; 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, + background: Background::Color(colors.surface_container.base), + text_color: colors.on_surface, + selected_background: Background::Color(mix( + colors.surface_container.base, + colors.on_surface, + HOVERED_LAYER_OPACITY, + )), + selected_text_color: colors.on_surface, } } diff --git a/material_theme/src/pick_list.rs b/material_theme/src/pick_list.rs new file mode 100644 index 0000000..c589100 --- /dev/null +++ b/material_theme/src/pick_list.rs @@ -0,0 +1,40 @@ +use iced_widget::core::{Background, border}; +use iced_widget::pick_list::{Catalog, Status, Style, StyleFn}; + +use super::Theme; + +impl Catalog for Theme { + type Class<'a> = StyleFn<'a, Self>; + + fn default<'a>() -> ::Class<'a> { + Box::new(default) + } + + fn style( + &self, + class: &::Class<'_>, + status: Status, + ) -> Style { + class(self, status) + } +} + +pub fn default(theme: &Theme, status: Status) -> Style { + let surface = theme.colorscheme.surface; + + let active = Style { + text_color: surface.on_surface, + placeholder_color: surface.on_surface_variant, + handle_color: surface.on_surface_variant, + background: Background::Color(surface.surface_container.highest), + border: border::rounded(4), + }; + + match status { + Status::Active => active, + Status::Hovered | Status::Opened { .. } => Style { + background: Background::Color(surface.surface_container.highest), + ..active + }, + } +} diff --git a/material_theme/src/utils.rs b/material_theme/src/utils.rs index 7efec9b..a05bc62 100644 --- a/material_theme/src/utils.rs +++ b/material_theme/src/utils.rs @@ -28,6 +28,44 @@ pub fn shadow_from_elevation(elevation: f32, color: Color) -> Shadow { } } +pub fn parse_argb(s: &str) -> Option { + let hex = s.strip_prefix('#').unwrap_or(s); + + let parse_channel = |from: usize, to: usize| { + let num = + usize::from_str_radix(&hex[from..=to], 16).ok()? as f32 / 255.0; + + // If we only got half a byte (one letter), expand it into a full byte (two letters) + Some(if from == to { num + num * 16.0 } else { num }) + }; + + Some(match hex.len() { + 3 => Color::from_rgb( + parse_channel(0, 0)?, + parse_channel(1, 1)?, + parse_channel(2, 2)?, + ), + 4 => Color::from_rgba( + parse_channel(1, 1)?, + parse_channel(2, 2)?, + parse_channel(3, 3)?, + parse_channel(0, 0)?, + ), + 6 => Color::from_rgb( + parse_channel(0, 1)?, + parse_channel(2, 3)?, + parse_channel(4, 5)?, + ), + 8 => Color::from_rgba( + parse_channel(2, 3)?, + parse_channel(4, 5)?, + parse_channel(6, 7)?, + parse_channel(0, 1)?, + ), + _ => None?, + }) +} + pub fn mix(color1: Color, color2: Color, p2: f32) -> Color { if p2 <= 0.0 { return color1; diff --git a/theme_test/Cargo.toml b/theme_test/Cargo.toml index 34008eb..5ccbefa 100644 --- a/theme_test/Cargo.toml +++ b/theme_test/Cargo.toml @@ -5,4 +5,6 @@ edition = "2024" [dependencies] iced.workspace = true -material_theme = { path = "../material_theme" } +iced_anim.workspace = true +iced_dialog.workspace = true +material_theme = { path = "../material_theme", features = ["dialog", "animate"] } diff --git a/theme_test/src/main.rs b/theme_test/src/main.rs index 26358c8..9826fe9 100644 --- a/theme_test/src/main.rs +++ b/theme_test/src/main.rs @@ -1,9 +1,9 @@ use iced::Element; -use iced::widget::{button, column, container, row, text}; -use material_theme::Theme; -use material_theme::button::{ - elevated, filled_tonal, outlined, text as text_style, -}; +use iced::Length::Fill; +use iced::widget::{button, column, container, pick_list, row}; +use iced_anim::{Animated, Animation, Event}; +use iced_dialog::dialog; +use material_theme::button::{elevated, filled_tonal, outlined, text}; use material_theme::container::{ error, error_container, inverse_surface, primary, primary_container, secondary, secondary_container, surface, surface_container, @@ -11,78 +11,130 @@ use material_theme::container::{ surface_container_lowest, tertiary, tertiary_container, }; use material_theme::text::surface_variant; +use material_theme::{DARK, LIGHT, Theme}; fn main() -> iced::Result { - iced::application(|| {}, (), view) - .theme(|_| material_theme::LIGHT.clone()) + iced::application(State::default, State::update, State::view) + .theme(|state| state.theme.value().clone()) .run() } +#[allow(dead_code)] #[derive(Debug, Clone)] enum Message { Noop, + OpenDialog, + CloseDialog, + SwitchTheme(Event), } -fn view(_: &()) -> Element<'_, Message, Theme> { - container( - row![ - column![ - button("Disabled"), - button("Filled").on_press(Message::Noop), - button("Filled Tonal") - .on_press(Message::Noop) - .style(filled_tonal), - button("Elevated").on_press(Message::Noop).style(elevated), - button("Outlined").on_press(Message::Noop).style(outlined), - button("Text").on_press(Message::Noop).style(text_style), - button("Text Disabled").style(text_style), - ] - .spacing(10), - column![ - text("None"), - container("Primary").padding(8).style(primary), - container("Primary Container") - .padding(8) - .style(primary_container), - container("Secondary").padding(8).style(secondary), - container("Secondary Container") - .padding(8) - .style(secondary_container), - container("Tertiary").padding(8).style(tertiary), - container("Tertiary Container") - .padding(8) - .style(tertiary_container), - container("Error").padding(8).style(error), - container("Error Container") - .padding(8) - .style(error_container), - container("Surface").padding(8).style(surface), - container(text("Surface Variant").style(surface_variant)) +#[derive(Debug, Default)] +pub struct State { + show_dialog: bool, + theme: Animated, +} + +impl State { + fn update(&mut self, message: Message) { + match message { + Message::Noop => {} + Message::OpenDialog => { + self.show_dialog = true; + } + Message::CloseDialog => { + self.show_dialog = false; + } + Message::SwitchTheme(event) => { + self.theme.update(event); + } + } + } + fn view(&self) -> Element<'_, Message, Theme> { + let base = container( + row![ + column![ + button("Disabled"), + button("Filled").on_press(Message::Noop), + button("Filled Tonal") + .on_press(Message::Noop) + .style(filled_tonal), + button("Elevated").on_press(Message::Noop).style(elevated), + button("Outlined").on_press(Message::Noop).style(outlined), + button("Text").on_press(Message::Noop).style(text), + button("Text Disabled").style(text), + ] + .spacing(10), + column![ + container("None").padding(8), + container("Primary").padding(8).style(primary), + container("Primary Container") + .padding(8) + .style(primary_container), + container("Secondary").padding(8).style(secondary), + container("Secondary Container") + .padding(8) + .style(secondary_container), + container("Tertiary").padding(8).style(tertiary), + container("Tertiary Container") + .padding(8) + .style(tertiary_container), + container("Error").padding(8).style(error), + container("Error Container") + .padding(8) + .style(error_container), + container("Surface").padding(8).style(surface), + container( + iced::widget::text("Surface Variant") + .style(surface_variant) + ) .padding(8) .style(surface), - container("Inverse Surface") - .padding(8) - .style(inverse_surface), - container("Surface Container Lowest") - .padding(8) - .style(surface_container_lowest), - container("Surface Container Low") - .padding(8) - .style(surface_container_low), - container("Surface Container") - .padding(8) - .style(surface_container), - container("Surface Container High") - .padding(8) - .style(surface_container_high), - container("Surface Container Highest") - .padding(8) - .style(surface_container_highest), + container("Inverse Surface") + .padding(8) + .style(inverse_surface), + container("Surface Container Lowest") + .padding(8) + .style(surface_container_lowest), + container("Surface Container Low") + .padding(8) + .style(surface_container_low), + container("Surface Container") + .padding(8) + .style(surface_container), + container("Surface Container High") + .padding(8) + .style(surface_container_high), + container("Surface Container Highest") + .padding(8) + .style(surface_container_highest), + ] + .spacing(10), + pick_list( + [LIGHT.clone(), DARK.clone()], + Some(self.theme.target()), + |theme| Message::SwitchTheme(theme.into()) + ) + .placeholder("Select a theme..."), + button("Open Dialog").on_press(Message::OpenDialog) ] - .spacing(10) - ] - .spacing(20), - ) - .padding(12) - .into() + .spacing(20), + ) + .width(Fill) + .height(Fill) + .padding(12); + + let dialog = + dialog(self.show_dialog, base, iced::widget::text("Say Hi!")) + .title("This is a Dialog.") + .push_button( + iced_dialog::button("Hi!").on_press(Message::CloseDialog), + ) + .backdrop(|theme| theme.colorscheme.scrim) + .width(280) + .height(187); + + Animation::new(&self.theme, dialog) + .on_update(Message::SwitchTheme) + .into() + } } -- cgit v1.2.3 From 606e22290e4542171ac18309d3cff27468c909fb Mon Sep 17 00:00:00 2001 From: pml68 Date: Sun, 13 Apr 2025 12:03:54 +0200 Subject: feat(PKGBUILD): update pkgver fn, dependencies --- Cargo.lock | 6 ++++++ PKGBUILD | 2 +- TODO.md | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) (limited to 'Cargo.lock') diff --git a/Cargo.lock b/Cargo.lock index 0143fbd..7a48765 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -649,6 +649,12 @@ dependencies = [ "wayland-client", ] +[[package]] +name = "camino" +version = "1.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b96ec4966b5813e2c0507c1f86115c8c5abaadc3980879c3424042a02fd1ad3" + [[package]] name = "cc" version = "1.2.19" diff --git a/PKGBUILD b/PKGBUILD index c17d10d..0297bc9 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -1,7 +1,7 @@ # Maintainer: pml68 pkgname=iced-builder -pkgver=0.1.0.r99.gd0e05b9 +pkgver=0.1.0.r115.g77b2e89 pkgrel=1 pkgdesc='UI builder for iced, built with iced.' arch=(x86_64) diff --git a/TODO.md b/TODO.md index d85bf5e..b8e9d30 100644 --- a/TODO.md +++ b/TODO.md @@ -1,3 +1,3 @@ -- [ ] Make Designer view more usable +- [X] Make Designer view more usable - [ ] Rework options backend to work on-project-load - [x] Remove GTK3 dependency -- cgit v1.2.3 From de43465ddb50dd6b0c44d8de7a05aa16ba38d312 Mon Sep 17 00:00:00 2001 From: pml68 Date: Tue, 15 Apr 2025 01:44:00 +0200 Subject: chore(deps): update `iced_dialog` --- Cargo.lock | 18 +++++++++--------- crates/material_theme/src/dialog.rs | 30 +++++++++++++++++++++++------- src/dialogs.rs | 4 ++-- theme_test/src/main.rs | 7 ++----- 4 files changed, 36 insertions(+), 23 deletions(-) (limited to 'Cargo.lock') diff --git a/Cargo.lock b/Cargo.lock index 7a48765..c8379a9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -107,9 +107,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.97" +version = "1.0.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcfed56ad506cb2c684a14971b8861fdc3baaaae314b9e5f9bb532cbe3ba7a4f" +checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487" [[package]] name = "arbitrary" @@ -860,9 +860,9 @@ dependencies = [ [[package]] name = "cosmic-text" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1db686e755000c93f73a3acc78be56a71e3efb83ed92886f45faea2b9485bad7" +checksum = "da46a9d5a8905cc538a4a5bceb6a4510de7a51049c5588c0114efce102bcbbe8" dependencies = [ "bitflags 2.9.0", "fontdb 0.16.2", @@ -1733,9 +1733,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5017294ff4bb30944501348f6f8e42e6ad28f42c8bbef7a74029aff064a4e3c2" +checksum = "75249d144030531f8dee69fe9cea04d3edf809a017ae445e2abdff6629e86633" dependencies = [ "atomic-waker", "bytes", @@ -2054,7 +2054,7 @@ dependencies = [ [[package]] name = "iced_dialog" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced_dialog?branch=iced%2Fpersonal#c0f931f38ac83e77cfb937d4166fa8d2a23988cf" +source = "git+https://github.com/pml68/iced_dialog?branch=iced%2Fpersonal#a41468011f8e4f566e9301565f3276fb10cc9551" dependencies = [ "iced_core", "iced_widget", @@ -3778,9 +3778,9 @@ dependencies = [ [[package]] name = "ravif" -version = "0.11.11" +version = "0.11.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2413fd96bd0ea5cdeeb37eaf446a22e6ed7b981d792828721e74ded1980a45c6" +checksum = "d6a5f31fcf7500f9401fea858ea4ab5525c99f2322cfcee732c0e6c74208c0c6" dependencies = [ "avif-serialize", "imgref", diff --git a/crates/material_theme/src/dialog.rs b/crates/material_theme/src/dialog.rs index 68c61b5..a022548 100644 --- a/crates/material_theme/src/dialog.rs +++ b/crates/material_theme/src/dialog.rs @@ -1,25 +1,41 @@ -use iced_widget::container::Style; +use iced_dialog::dialog::{Catalog, Style, StyleFn}; +use iced_widget::container; use iced_widget::core::{Background, border}; use super::{Theme, text}; -impl iced_dialog::dialog::Catalog for Theme { - fn default_container<'a>() - -> ::Class<'a> { +impl Catalog for Theme { + type Class<'a> = StyleFn<'a, Self>; + + fn default<'a>() -> ::Class<'a> { + Box::new(default) + } + + fn default_container<'a>() -> ::Class<'a> { Box::new(default_container) } fn default_title<'a>() -> ::Class<'a> { Box::new(text::surface) } + + fn style(&self, class: &::Class<'_>) -> Style { + class(self) + } } -pub fn default_container(theme: &Theme) -> Style { +pub fn default_container(theme: &Theme) -> container::Style { let colors = theme.colorscheme.surface; - Style { + container::Style { background: Some(Background::Color(colors.surface_container.high)), text_color: Some(colors.on_surface_variant), border: border::rounded(28), - ..Style::default() + ..container::Style::default() + } +} + +pub fn default(theme: &Theme) -> Style { + Style { + backdrop_color: theme.colorscheme.scrim, } } diff --git a/src/dialogs.rs b/src/dialogs.rs index 08513fd..a623f35 100644 --- a/src/dialogs.rs +++ b/src/dialogs.rs @@ -9,11 +9,11 @@ pub const WARNING_TITLE: &str = "Heads up!"; pub const ERROR_TITLE: &str = "Oops! Something went wrong."; pub fn ok_button<'a>() -> Element<'a, Message> { - button("Ok").on_press(Message::DialogOk).into() + button("Ok", Message::DialogOk).into() } pub fn cancel_button<'a>() -> Element<'a, Message> { - button("Cancel").on_press(Message::DialogCancel).into() + button("Cancel", Message::DialogCancel).into() } pub fn error_dialog(description: impl Into) -> Task { diff --git a/theme_test/src/main.rs b/theme_test/src/main.rs index 9826fe9..bcf16de 100644 --- a/theme_test/src/main.rs +++ b/theme_test/src/main.rs @@ -126,12 +126,9 @@ impl State { let dialog = dialog(self.show_dialog, base, iced::widget::text("Say Hi!")) .title("This is a Dialog.") - .push_button( - iced_dialog::button("Hi!").on_press(Message::CloseDialog), - ) - .backdrop(|theme| theme.colorscheme.scrim) + .push_button(iced_dialog::button("Hi!", Message::CloseDialog)) .width(280) - .height(187); + .height(186); Animation::new(&self.theme, dialog) .on_update(Message::SwitchTheme) -- cgit v1.2.3 From 911cd4ffc291d2d9b92f90ede1d03d41edc97920 Mon Sep 17 00:00:00 2001 From: pml68 Date: Tue, 15 Apr 2025 23:45:14 +0200 Subject: feat(material_theme): implement `text_input::Catalog` --- Cargo.lock | 6 +-- crates/material_theme/src/lib.rs | 1 + crates/material_theme/src/text_input.rs | 81 +++++++++++++++++++++++++++++++++ theme_test/src/main.rs | 26 +++++++---- 4 files changed, 102 insertions(+), 12 deletions(-) create mode 100644 crates/material_theme/src/text_input.rs (limited to 'Cargo.lock') diff --git a/Cargo.lock b/Cargo.lock index c8379a9..4d8371f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2054,7 +2054,7 @@ dependencies = [ [[package]] name = "iced_dialog" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced_dialog?branch=iced%2Fpersonal#a41468011f8e4f566e9301565f3276fb10cc9551" +source = "git+https://github.com/pml68/iced_dialog?branch=iced%2Fpersonal#6e901c21dbb259d337ed1ad2054da3862172b8b3" dependencies = [ "iced_core", "iced_widget", @@ -2563,9 +2563,9 @@ checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8" [[package]] name = "libc" -version = "0.2.171" +version = "0.2.172" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c19937216e9d3aa9956d9bb8dfc0b0c8beb6058fc4f7a4dc4d850edf86a237d6" +checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" [[package]] name = "libfuzzer-sys" diff --git a/crates/material_theme/src/lib.rs b/crates/material_theme/src/lib.rs index 521af2c..adffe09 100644 --- a/crates/material_theme/src/lib.rs +++ b/crates/material_theme/src/lib.rs @@ -12,6 +12,7 @@ pub mod menu; pub mod pick_list; pub mod scrollable; pub mod text; +pub mod text_input; pub mod utils; const DARK_THEME_CONTENT: &str = include_str!("../assets/themes/dark.toml"); diff --git a/crates/material_theme/src/text_input.rs b/crates/material_theme/src/text_input.rs new file mode 100644 index 0000000..5fa65ef --- /dev/null +++ b/crates/material_theme/src/text_input.rs @@ -0,0 +1,81 @@ +use iced_widget::core::{Background, Border, Color}; +use iced_widget::text_input::{Catalog, Status, Style, StyleFn}; + +use super::Theme; +use crate::utils::{DISABLED_CONTAINER_OPACITY, DISABLED_TEXT_OPACITY}; + +impl Catalog for Theme { + type Class<'a> = StyleFn<'a, Self>; + + fn default<'a>() -> Self::Class<'a> { + Box::new(default) + } + + fn style(&self, class: &Self::Class<'_>, status: Status) -> Style { + class(self, status) + } +} + +pub fn default(theme: &Theme, status: Status) -> Style { + let surface = theme.colorscheme.surface; + let primary = theme.colorscheme.primary; + + let active = Style { + background: Background::Color(surface.surface_container.highest), + border: Border { + color: theme.colorscheme.outline.color, + width: 1.0, + radius: 4.into(), + }, + icon: surface.on_surface_variant, + placeholder: surface.on_surface_variant, + value: surface.on_surface, + selection: surface.on_surface, + }; + + match status { + Status::Active => active, + Status::Hovered => Style { + border: Border { + color: surface.on_surface, + ..active.border + }, + ..active + }, + Status::Disabled => Style { + background: Color::TRANSPARENT.into(), + border: Border { + color: Color { + a: DISABLED_CONTAINER_OPACITY, + ..surface.on_surface + }, + ..active.border + }, + icon: Color { + a: DISABLED_TEXT_OPACITY, + ..surface.on_surface + }, + placeholder: Color { + a: DISABLED_TEXT_OPACITY, + ..surface.on_surface + }, + value: Color { + a: DISABLED_TEXT_OPACITY, + ..surface.on_surface + }, + selection: Color { + a: DISABLED_TEXT_OPACITY, + ..surface.on_surface + }, + }, + Status::Focused { .. } => Style { + border: Border { + color: primary.color, + width: 2.0, + ..active.border + }, + placeholder: primary.color, + ..active + }, + } +} diff --git a/theme_test/src/main.rs b/theme_test/src/main.rs index bcf16de..799d68d 100644 --- a/theme_test/src/main.rs +++ b/theme_test/src/main.rs @@ -1,6 +1,6 @@ use iced::Element; use iced::Length::Fill; -use iced::widget::{button, column, container, pick_list, row}; +use iced::widget::{button, column, container, pick_list, row, text_input}; use iced_anim::{Animated, Animation, Event}; use iced_dialog::dialog; use material_theme::button::{elevated, filled_tonal, outlined, text}; @@ -25,13 +25,15 @@ enum Message { Noop, OpenDialog, CloseDialog, + Input(String), SwitchTheme(Event), } #[derive(Debug, Default)] pub struct State { - show_dialog: bool, theme: Animated, + show_dialog: bool, + content: String, } impl State { @@ -44,6 +46,7 @@ impl State { Message::CloseDialog => { self.show_dialog = false; } + Message::Input(content) => self.content = content, Message::SwitchTheme(event) => { self.theme.update(event); } @@ -109,13 +112,18 @@ impl State { .style(surface_container_highest), ] .spacing(10), - pick_list( - [LIGHT.clone(), DARK.clone()], - Some(self.theme.target()), - |theme| Message::SwitchTheme(theme.into()) - ) - .placeholder("Select a theme..."), - button("Open Dialog").on_press(Message::OpenDialog) + column![ + pick_list( + [LIGHT.clone(), DARK.clone()], + Some(self.theme.target()), + |theme| Message::SwitchTheme(theme.into()) + ) + .placeholder("Select a theme..."), + button("Open Dialog").on_press(Message::OpenDialog), + text_input("Type something here...", &self.content) + .on_input(Message::Input) + ] + .spacing(10) ] .spacing(20), ) -- cgit v1.2.3 From 73711596ee7295b6f0d78bb443d5f39956f8892c Mon Sep 17 00:00:00 2001 From: pml68 Date: Tue, 15 Apr 2025 23:58:34 +0200 Subject: chore(deps): regenerate lockfile, update dependencies --- Cargo.lock | 120 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 60 insertions(+), 60 deletions(-) (limited to 'Cargo.lock') diff --git a/Cargo.lock b/Cargo.lock index 4d8371f..3bd023a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -577,9 +577,9 @@ dependencies = [ [[package]] name = "bytemuck_derive" -version = "1.9.2" +version = "1.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ff22c2722516255d1823ce3cc4bc0b154dbc9364be5c905d6baa6eccbbc8774" +checksum = "7ecc273b49b3205b83d648f0690daa588925572cc5063745bfe547fe7ec8e1a1" dependencies = [ "proc-macro2", "quote", @@ -1232,9 +1232,9 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" [[package]] name = "errno" -version = "0.3.10" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" +checksum = "976dd42dc7e85965fe702eb8164f21f450704bdde31faefd6471dba214cb594e" dependencies = [ "libc", "windows-sys 0.59.0", @@ -1284,9 +1284,9 @@ dependencies = [ [[package]] name = "event-listener-strategy" -version = "0.5.3" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c3e4e0dd3673c1139bf041f3008816d9cf2946bbfac2945c09e523b8d7b05b2" +checksum = "8be9f3dfaaffdae2972880079a491a1a8bb7cbed0b8dd7a347f668b4150a3b93" dependencies = [ "event-listener 5.4.0", "pin-project-lite", @@ -1324,9 +1324,9 @@ dependencies = [ [[package]] name = "flate2" -version = "1.1.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11faaf5a5236997af9848be0bef4db95824b1d534ebc64d0f0c6cf3e67bd38dc" +checksum = "7ced92e76e966ca2fd84c8f7aa01a4aea65b0eb6648d72f7c8f3e2764a67fece" dependencies = [ "crc32fast", "miniz_oxide", @@ -1352,9 +1352,9 @@ checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" [[package]] name = "font-types" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d868ec188a98bb014c606072edd47e52e7ab7297db943b0b28503121e1d037bd" +checksum = "1fa6a5e5a77b5f3f7f9e32879f484aa5b3632ddfbe568a16266c904a6f32cdaf" dependencies = [ "bytemuck", ] @@ -1909,9 +1909,9 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.10" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df2dcfbe0677734ab2f3ffa7fa7bfd4706bfdc1ef393f2ee30184aed67e631b4" +checksum = "497bbc33a26fdd4af9ed9c70d63f61cf56a938375fbb32df34db9b1cd6d643f2" dependencies = [ "bytes", "futures-channel", @@ -1919,6 +1919,7 @@ dependencies = [ "http", "http-body", "hyper", + "libc", "pin-project-lite", "socket2", "tokio", @@ -2259,9 +2260,9 @@ dependencies = [ [[package]] name = "icu_locid_transform_data" -version = "1.5.0" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fdc8ff3388f852bede6b579ad4e978ab004f139284d7b28715f773507b946f6e" +checksum = "7515e6d781098bf9f7205ab3fc7e9709d34554ae0b21ddbcb5febfa4bc7df11d" [[package]] name = "icu_normalizer" @@ -2283,9 +2284,9 @@ dependencies = [ [[package]] name = "icu_normalizer_data" -version = "1.5.0" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8cafbf7aa791e9b22bec55a167906f9e1215fd475cd22adfcf660e03e989516" +checksum = "c5e8338228bdc8ab83303f16b797e177953730f601a96c25d10cb3ab0daa0cb7" [[package]] name = "icu_properties" @@ -2304,9 +2305,9 @@ dependencies = [ [[package]] name = "icu_properties_data" -version = "1.5.0" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67a8effbc3dd3e4ba1afa8ad918d5684b8868b3b26500753effea8d2eed19569" +checksum = "85fb8799753b75aee8d2a21d7c14d9f38921b54b3dbda10f5a3c7a7b82dba5e2" [[package]] name = "icu_provider" @@ -2359,9 +2360,9 @@ dependencies = [ [[package]] name = "image" -version = "0.25.5" +version = "0.25.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd6f44aed642f18953a158afeb30206f4d50da59fbc66ecb53c66488de73563b" +checksum = "db35664ce6b9810857a38a906215e75a9c879f0696556a39f59c62829710251a" dependencies = [ "bytemuck", "byteorder-lite", @@ -2404,9 +2405,9 @@ checksum = "d0263a3d970d5c054ed9312c0057b4f3bde9c0b33836d3637361d4a9e6e7a408" [[package]] name = "indexmap" -version = "2.8.0" +version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3954d50fe15b02142bf25d3b8bdadb634ec3948f103d04ffe3031bc8fe9d7058" +checksum = "cea70ddb795996207ad57735b50c5982d8844f38ba9ee5f1aedcfb708a2aa11e" dependencies = [ "equivalent", "hashbrown", @@ -2477,10 +2478,11 @@ checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" [[package]] name = "jobserver" -version = "0.1.32" +version = "0.1.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0" +checksum = "38f262f097c174adebe41eb73d66ae9c06b2844fb0da69969647bbddd9b0538a" dependencies = [ + "getrandom 0.3.2", "libc", ] @@ -2601,7 +2603,7 @@ checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" dependencies = [ "bitflags 2.9.0", "libc", - "redox_syscall 0.5.10", + "redox_syscall 0.5.11", ] [[package]] @@ -2661,9 +2663,9 @@ checksum = "9374ef4228402d4b7e403e5838cb880d9ee663314b0a900d5a6aabf0c213552e" [[package]] name = "log" -version = "0.4.26" +version = "0.4.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30bde2b3dc3671ae49d8e2e9f044c7c005836e7a023ee57cffa25ab82764bb9e" +checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" dependencies = [ "value-bag", ] @@ -3288,9 +3290,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.21.1" +version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d75b0bedcc4fe52caa0e03d9f1151a323e4aa5e2d78ba3580400cd3c9e2bc4bc" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" [[package]] name = "onig" @@ -3316,9 +3318,9 @@ dependencies = [ [[package]] name = "openssl" -version = "0.10.71" +version = "0.10.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e14130c6a98cd258fdcb0fb6d744152343ff729cbfcb28c656a9d12b999fbcd" +checksum = "fedfea7d58a1f73118430a55da6a286e7b044961736ce96a16a17068ea25e5da" dependencies = [ "bitflags 2.9.0", "cfg-if", @@ -3348,9 +3350,9 @@ checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e" [[package]] name = "openssl-sys" -version = "0.9.106" +version = "0.9.107" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bb61ea9811cc39e3c2069f40b8b8e2e70d8569b361f879786cc7ed48b777cdd" +checksum = "8288979acd84749c744a9014b4382d42b8f7b2592847b5afb2ed29e5d16ede07" dependencies = [ "cc", "libc", @@ -3443,7 +3445,7 @@ checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if", "libc", - "redox_syscall 0.5.10", + "redox_syscall 0.5.11", "smallvec", "windows-targets 0.52.6", ] @@ -3647,9 +3649,9 @@ checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3" [[package]] name = "quick-xml" -version = "0.37.2" +version = "0.37.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "165859e9e55f79d67b96c5d96f4e88b6f2695a1972849c15a6a3f5c59fc2c003" +checksum = "a4ce8c88de324ff838700f36fb6ab86c96df0e3c4ab6ef3a9b2044465cce1369" dependencies = [ "memchr", ] @@ -3838,9 +3840,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.10" +version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b8c0c260b63a8219631167be35e6a988e9554dbd323f8bd08439c8ed1302bd1" +checksum = "d2f103c6d277498fbceb16e84d317e2a400f160f46904d5f5410848c829511a3" dependencies = [ "bitflags 2.9.0", ] @@ -4031,9 +4033,9 @@ dependencies = [ [[package]] name = "rustix" -version = "1.0.3" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e56a18552996ac8d29ecc3b190b4fdbb2d91ca4ec396de7bbffaf43f3d637e96" +checksum = "d97817398dd4bb2e6da002002db259209759911da105da92bec29ccb12cf58bf" dependencies = [ "bitflags 2.9.0", "errno", @@ -4072,9 +4074,9 @@ checksum = "917ce264624a4b4db1c364dcc35bfca9ded014d0a958cd47ad3e960e988ea51c" [[package]] name = "rustls-webpki" -version = "0.103.0" +version = "0.103.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0aa4eeac2588ffff23e9d7a7e9b3f971c5fb5b7ebc9452745e0c232c64f83b2f" +checksum = "fef8b8769aaccf73098557a87cd1816b4f9c7c16811c9c77142aa695c16f2c03" dependencies = [ "ring", "rustls-pki-types", @@ -4352,9 +4354,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.14.0" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcf8323ef1faaee30a44a340193b1ac6814fd9b7b4e88e9d4519a3e4abe1cfd" +checksum = "8917285742e9f3e1683f0a9c4e6b57960b7314d0b08d30d1ecd426713ee2eee9" [[package]] name = "smithay-client-toolkit" @@ -4403,9 +4405,9 @@ dependencies = [ [[package]] name = "socket2" -version = "0.5.8" +version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c970269d99b64e60ec3bd6ad27270092a5394c4e309314b18ae3fe575695fbe8" +checksum = "4f5fd57c80058a56cf5c777ab8a126398ece8e442983605d280a44ce79d0edef" dependencies = [ "libc", "windows-sys 0.52.0", @@ -4431,7 +4433,7 @@ dependencies = [ "objc2-foundation 0.2.2", "objc2-quartz-core", "raw-window-handle", - "redox_syscall 0.5.10", + "redox_syscall 0.5.11", "rustix 0.38.44", "tiny-xlib", "wasm-bindgen", @@ -4519,9 +4521,9 @@ dependencies = [ [[package]] name = "swash" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13d5bbc2aa266907ed8ee977c9c9e16363cc2b001266104e13397b57f1d15f71" +checksum = "fae9a562c7b46107d9c78cd78b75bbe1e991c16734c0aee8ff0ee711fb8b620a" dependencies = [ "skrifa", "yazi", @@ -4637,7 +4639,7 @@ dependencies = [ "fastrand", "getrandom 0.3.2", "once_cell", - "rustix 1.0.3", + "rustix 1.0.5", "windows-sys 0.59.0", ] @@ -4713,9 +4715,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.40" +version = "0.3.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d9c75b47bdff86fa3334a3db91356b8d7d86a9b839dab7d0bdc5c3d3a077618" +checksum = "8a7619e19bc266e0f9c5e6686659d394bc57973859340060a69221e57dbc0c40" dependencies = [ "deranged", "num-conv", @@ -5157,9 +5159,9 @@ dependencies = [ [[package]] name = "value-bag" -version = "1.10.0" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ef4c4aa54d5d05a279399bfa921ec387b7aba77caf7a682ae8d86785b8fdad2" +checksum = "943ce29a8a743eb10d6082545d861b24f9d1b160b7d741e0f2cdf726bec909c5" [[package]] name = "vcpkg" @@ -5506,9 +5508,9 @@ dependencies = [ [[package]] name = "wgpu-hal" -version = "24.0.2" +version = "24.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4317a17171dc20e6577bf606796794580accae0716a69edbc7388c86a3ec9f23" +checksum = "f112f464674ca69f3533248508ee30cb84c67cf06c25ff6800685f5e0294e259" dependencies = [ "android_system_properties", "arrayvec", @@ -6389,9 +6391,9 @@ dependencies = [ [[package]] name = "zip" -version = "2.4.2" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fabe6324e908f85a1c52063ce7aa26b68dcb7eb6dbc83a2d148403c9bc3eba50" +checksum = "1dcb24d0152526ae49b9b96c1dcf71850ca1e0b882e4e28ed898a93c41334744" dependencies = [ "aes", "arbitrary", @@ -6400,7 +6402,6 @@ dependencies = [ "crc32fast", "crossbeam-utils", "deflate64", - "displaydoc", "flate2", "getrandom 0.3.2", "hmac", @@ -6409,7 +6410,6 @@ dependencies = [ "memchr", "pbkdf2", "sha1", - "thiserror 2.0.12", "time", "xz2", "zeroize", -- cgit v1.2.3 From b2b7dddb28732fbf8b070dd96922eb7df50318cb Mon Sep 17 00:00:00 2001 From: pml68 Date: Thu, 17 Apr 2025 00:30:03 +0200 Subject: feat(material_theme): implement `qr_code::Catalog` (under feature flag) --- Cargo.lock | 98 ++++++++++++++++++++++++++++++++++++ crates/material_theme/Cargo.toml | 2 + crates/material_theme/src/lib.rs | 2 + crates/material_theme/src/qr_code.rs | 24 +++++++++ 4 files changed, 126 insertions(+) create mode 100644 crates/material_theme/src/qr_code.rs (limited to 'Cargo.lock') diff --git a/Cargo.lock b/Cargo.lock index 3bd023a..6f5e4cb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1338,6 +1338,12 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4" +[[package]] +name = "float_next_after" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bf7cc16383c4b8d58b9905a8509f02926ce3058053c056376248d958c9df1e8" + [[package]] name = "fnv" version = "1.0.7" @@ -1579,6 +1585,15 @@ dependencies = [ "windows-targets 0.48.5", ] +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + [[package]] name = "getrandom" version = "0.2.15" @@ -2110,6 +2125,7 @@ dependencies = [ "image", "kamadak-exif", "log", + "lyon_path", "raw-window-handle", "rustc-hash 2.1.1", "thiserror 1.0.69", @@ -2181,6 +2197,7 @@ dependencies = [ "iced_debug", "iced_graphics", "log", + "lyon", "resvg", "rustc-hash 2.1.1", "thiserror 1.0.69", @@ -2197,9 +2214,12 @@ dependencies = [ "log", "num-traits", "ouroboros", + "pulldown-cmark", + "qrcode", "rustc-hash 2.1.1", "thiserror 1.0.69", "unicode-segmentation", + "url", ] [[package]] @@ -2685,6 +2705,58 @@ version = "0.12.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "234cf4f4a04dc1f57e24b96cc0cd600cf2af460d4161ac5ecdd0af8e1f3b2a38" +[[package]] +name = "lyon" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e7f9cda98b5430809e63ca5197b06c7d191bf7e26dfc467d5a3f0290e2a74f" +dependencies = [ + "lyon_algorithms", + "lyon_tessellation", +] + +[[package]] +name = "lyon_algorithms" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f13c9be19d257c7d37e70608ed858e8eab4b2afcea2e3c9a622e892acbf43c08" +dependencies = [ + "lyon_path", + "num-traits", +] + +[[package]] +name = "lyon_geom" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8af69edc087272df438b3ee436c4bb6d7c04aa8af665cfd398feae627dbd8570" +dependencies = [ + "arrayvec", + "euclid", + "num-traits", +] + +[[package]] +name = "lyon_path" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0047f508cd7a85ad6bad9518f68cce7b1bf6b943fb71f6da0ee3bc1e8cb75f25" +dependencies = [ + "lyon_geom", + "num-traits", +] + +[[package]] +name = "lyon_tessellation" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "579d42360a4b09846eff2feef28f538696c7d6c7439bfa65874ff3cbe0951b2c" +dependencies = [ + "float_next_after", + "lyon_path", + "num-traits", +] + [[package]] name = "lzma-rs" version = "0.3.0" @@ -2992,6 +3064,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", + "libm", ] [[package]] @@ -3632,6 +3705,25 @@ dependencies = [ "syn", ] +[[package]] +name = "pulldown-cmark" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f86ba2052aebccc42cbbb3ed234b8b13ce76f75c3551a303cb2bcffcff12bb14" +dependencies = [ + "bitflags 2.9.0", + "getopts", + "memchr", + "pulldown-cmark-escape", + "unicase", +] + +[[package]] +name = "pulldown-cmark-escape" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "007d8adb5ddab6f8e3f491ac63566a7d5002cc7ed73901f72057943fa71ae1ae" + [[package]] name = "qoi" version = "0.4.1" @@ -3641,6 +3733,12 @@ dependencies = [ "bytemuck", ] +[[package]] +name = "qrcode" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "166f136dfdb199f98186f3649cf7a0536534a61417a1a30221b492b4fb60ce3f" + [[package]] name = "quick-error" version = "2.0.1" diff --git a/crates/material_theme/Cargo.toml b/crates/material_theme/Cargo.toml index ad825fd..e1da2fb 100644 --- a/crates/material_theme/Cargo.toml +++ b/crates/material_theme/Cargo.toml @@ -21,6 +21,8 @@ dialog = ["dep:iced_dialog"] markdown = ["iced_widget/markdown"] # Provides support for the SVG widget. svg = ["iced_widget/svg"] +# Provides support for the QR code widget. +qr_code = ["iced_widget/qr_code"] [dependencies] iced_widget = "0.14.0-dev" diff --git a/crates/material_theme/src/lib.rs b/crates/material_theme/src/lib.rs index a41dfd5..06ad838 100644 --- a/crates/material_theme/src/lib.rs +++ b/crates/material_theme/src/lib.rs @@ -13,6 +13,8 @@ pub mod dialog; pub mod markdown; pub mod menu; pub mod pick_list; +#[cfg(feature = "qr_code")] +pub mod qr_code; pub mod scrollable; #[cfg(feature = "svg")] pub mod svg; diff --git a/crates/material_theme/src/qr_code.rs b/crates/material_theme/src/qr_code.rs new file mode 100644 index 0000000..f93fb77 --- /dev/null +++ b/crates/material_theme/src/qr_code.rs @@ -0,0 +1,24 @@ +use iced_widget::qr_code::{Catalog, Style, StyleFn}; + +use super::Theme; + +impl Catalog for Theme { + type Class<'a> = StyleFn<'a, Self>; + + fn default<'a>() -> Self::Class<'a> { + Box::new(default) + } + + fn style(&self, class: &Self::Class<'_>) -> Style { + class(self) + } +} + +pub fn default(theme: &Theme) -> Style { + let surface = theme.colorscheme.surface; + + Style { + cell: surface.on_surface, + background: surface.color, + } +} -- cgit v1.2.3 From ce62ff16fbd8e839b5f707f8d9637db083945803 Mon Sep 17 00:00:00 2001 From: pml68 Date: Thu, 17 Apr 2025 03:00:52 +0200 Subject: refactor: inline Dark and Light theme definitions, remove toml files --- Cargo.lock | 1 - crates/material_theme/Cargo.toml | 8 +- crates/material_theme/assets/themes/dark.toml | 49 ----- crates/material_theme/assets/themes/light.toml | 49 ----- crates/material_theme/src/lib.rs | 238 +++++++++++++++++++------ crates/material_theme/src/utils.rs | 20 +++ theme_test/src/main.rs | 15 +- 7 files changed, 222 insertions(+), 158 deletions(-) delete mode 100644 crates/material_theme/assets/themes/dark.toml delete mode 100644 crates/material_theme/assets/themes/light.toml (limited to 'Cargo.lock') diff --git a/Cargo.lock b/Cargo.lock index 6f5e4cb..e8a5b71 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2796,7 +2796,6 @@ dependencies = [ "iced_dialog", "iced_widget", "serde", - "toml", ] [[package]] diff --git a/crates/material_theme/Cargo.toml b/crates/material_theme/Cargo.toml index e1da2fb..941bc3e 100644 --- a/crates/material_theme/Cargo.toml +++ b/crates/material_theme/Cargo.toml @@ -13,6 +13,8 @@ rust-version = "1.85" [features] default = [] +# Provides `serde` support +serde = ["dep:serde"] # Provides support for animating with `iced_anim`. animate = ["dep:iced_anim"] # Provides support for `iced_dialog`. @@ -26,9 +28,11 @@ qr_code = ["iced_widget/qr_code"] [dependencies] iced_widget = "0.14.0-dev" -serde.workspace = true -toml.workspace = true dark-light = "2.0.0" + +serde.workspace = true +serde.optional = true + iced_dialog.workspace = true iced_dialog.optional = true diff --git a/crates/material_theme/assets/themes/dark.toml b/crates/material_theme/assets/themes/dark.toml deleted file mode 100644 index 18a369f..0000000 --- a/crates/material_theme/assets/themes/dark.toml +++ /dev/null @@ -1,49 +0,0 @@ -name = "Dark" - -shadow = "#000000" -scrim = "#4d000000" - -[primary] -color = "#9bd4a1" -on_primary = "#003916" -primary_container = "#1b5129" -on_primary_container = "#b6f1bb" - -[secondary] -color = "#b8ccb6" -on_secondary = "#233425" -secondary_container = "#394b3a" -on_secondary_container = "#d3e8d1" - -[tertiary] -color = "#a1ced7" -on_tertiary = "#00363e" -tertiary_container = "#1f4d55" -on_tertiary_container = "#bdeaf4" - -[error] -color = "#ffb4ab" -on_error = "#690005" -error_container = "#93000a" -on_error_container = "#ffdad6" - -[surface] -color = "#101510" -on_surface = "#e0e4dc" -on_surface_variant = "#c1c9be" - -[surface.surface_container] -lowest = "#0b0f0b" -low = "#181d18" -base = "#1c211c" -high = "#262b26" -highest = "#313631" - -[inverse] -inverse_surface = "#e0e4dc" -inverse_on_surface = "#2d322c" -inverse_primary = "#34693f" - -[outline] -color = "#8b9389" -variant = "#414941" diff --git a/crates/material_theme/assets/themes/light.toml b/crates/material_theme/assets/themes/light.toml deleted file mode 100644 index a7115c4..0000000 --- a/crates/material_theme/assets/themes/light.toml +++ /dev/null @@ -1,49 +0,0 @@ -name = "Light" - -shadow = "#000000" -scrim = "#4d000000" - -[primary] -color = "#34693f" -on_primary = "#ffffff" -primary_container = "#b6f1bb" -on_primary_container = "#1b5129" - -[secondary] -color = "#516351" -on_secondary = "#ffffff" -secondary_container = "#d3e8d1" -on_secondary_container = "#394b3a" - -[tertiary] -color = "#39656d" -on_tertiary = "#ffffff" -tertiary_container = "#bdeaf4" -on_tertiary_container = "#1f4d55" - -[error] -color = "#ba1a1a" -on_error = "#ffffff" -error_container = "#ffdad6" -on_error_container = "#93000a" - -[surface] -color = "#f7fbf2" -on_surface = "#181d18" -on_surface_variant = "#414941" - -[surface.surface_container] -lowest = "#ffffff" -low = "#f1f5ed" -base = "#ebefe7" -high = "#e5e9e1" -highest = "#e0e4dc" - -[inverse] -inverse_surface = "#2d322c" -inverse_on_surface = "#eef2ea" -inverse_primary = "#9bd4a1" - -[outline] -color = "#727970" -variant = "#c1c9be" diff --git a/crates/material_theme/src/lib.rs b/crates/material_theme/src/lib.rs index cbebdc9..a9beb2a 100644 --- a/crates/material_theme/src/lib.rs +++ b/crates/material_theme/src/lib.rs @@ -1,8 +1,7 @@ use std::sync::LazyLock; -use iced_widget::core::Color; use iced_widget::core::theme::{Base, Style}; -use serde::Deserialize; +use iced_widget::core::{Color, color}; pub mod button; pub mod checkbox; @@ -25,13 +24,16 @@ pub mod text; pub mod text_input; pub mod utils; -const DARK_THEME_CONTENT: &str = include_str!("../assets/themes/dark.toml"); -const LIGHT_THEME_CONTENT: &str = include_str!("../assets/themes/light.toml"); +pub static DARK: LazyLock = + LazyLock::new(|| Theme::new("Dark", ColorScheme::DARK)); +pub static LIGHT: LazyLock = + LazyLock::new(|| Theme::new("Light", ColorScheme::LIGHT)); -#[derive(Debug, PartialEq, Deserialize)] +#[derive(Debug, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Theme { pub name: String, - #[serde(flatten)] + #[cfg_attr(feature = "serde", serde(flatten))] pub colorscheme: ColorScheme, } @@ -119,16 +121,9 @@ impl iced_anim::Animate for Theme { } } -pub static DARK: LazyLock = LazyLock::new(|| { - toml::from_str(DARK_THEME_CONTENT).expect("parse dark theme") -}); - -pub static LIGHT: LazyLock = LazyLock::new(|| { - toml::from_str(LIGHT_THEME_CONTENT).expect("parse light theme") -}); - -#[derive(Debug, Clone, Copy, PartialEq, Deserialize)] +#[derive(Debug, Clone, Copy, PartialEq)] #[cfg_attr(feature = "animate", derive(iced_anim::Animate))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct ColorScheme { pub primary: Primary, pub secondary: Secondary, @@ -137,116 +132,240 @@ pub struct ColorScheme { pub surface: Surface, pub inverse: Inverse, pub outline: Outline, - #[serde(with = "color_serde")] + #[cfg_attr(feature = "serde", serde(with = "color_serde"))] pub shadow: Color, - #[serde(with = "color_serde")] + #[cfg_attr(feature = "serde", serde(with = "color_serde"))] pub scrim: Color, } -#[derive(Debug, Clone, Copy, PartialEq, Deserialize)] +macro_rules! from_argb { + ($hex:expr) => {{ + let hex = $hex as u32; + + let a = ((hex & 0xff000000) >> 24) as f32 / 255.0; + let r = (hex & 0x00ff0000) >> 16; + let g = (hex & 0x0000ff00) >> 8; + let b = (hex & 0x000000ff); + + color!(r as u8, g as u8, b as u8, a) + }}; +} + +impl ColorScheme { + const DARK: Self = Self { + primary: Primary { + color: from_argb!(0xff9bd4a1), + on_primary: from_argb!(0xff003916), + primary_container: from_argb!(0xff1b5129), + on_primary_container: from_argb!(0xffb6f1bb), + }, + secondary: Secondary { + color: from_argb!(0xffb8ccb6), + on_secondary: from_argb!(0xff233425), + secondary_container: from_argb!(0xff394b3a), + on_secondary_container: from_argb!(0xffd3e8d1), + }, + tertiary: Tertiary { + color: from_argb!(0xffa1ced7), + on_tertiary: from_argb!(0xff00363e), + tertiary_container: from_argb!(0xff1f4d55), + on_tertiary_container: from_argb!(0xffbdeaf4), + }, + error: Error { + color: from_argb!(0xffffb4ab), + on_error: from_argb!(0xff690005), + error_container: from_argb!(0xff93000a), + on_error_container: from_argb!(0xffffdad6), + }, + surface: Surface { + color: from_argb!(0xff101510), + on_surface: from_argb!(0xffe0e4dc), + on_surface_variant: from_argb!(0xffc1c9be), + surface_container: SurfaceContainer { + lowest: from_argb!(0xff0b0f0b), + low: from_argb!(0xff181d18), + base: from_argb!(0xff1c211c), + high: from_argb!(0xff262b26), + highest: from_argb!(0xff313631), + }, + }, + inverse: Inverse { + inverse_surface: from_argb!(0xffe0e4dc), + inverse_on_surface: from_argb!(0xff2d322c), + inverse_primary: from_argb!(0xff34693f), + }, + outline: Outline { + color: from_argb!(0xff8b9389), + variant: from_argb!(0xff414941), + }, + shadow: from_argb!(0xff000000), + scrim: from_argb!(0x4d000000), + }; + + const LIGHT: Self = Self { + primary: Primary { + color: from_argb!(0xff34693f), + on_primary: from_argb!(0xffffffff), + primary_container: from_argb!(0xffb6f1bb), + on_primary_container: from_argb!(0xff1b5129), + }, + secondary: Secondary { + color: from_argb!(0xff516351), + on_secondary: from_argb!(0xffffffff), + secondary_container: from_argb!(0xffd3e8d1), + on_secondary_container: from_argb!(0xff394b3a), + }, + tertiary: Tertiary { + color: from_argb!(0xff39656d), + on_tertiary: from_argb!(0xffffffff), + tertiary_container: from_argb!(0xffbdeaf4), + on_tertiary_container: from_argb!(0xff1f4d55), + }, + error: Error { + color: from_argb!(0xffba1a1a), + on_error: from_argb!(0xffffffff), + error_container: from_argb!(0xffffdad6), + on_error_container: from_argb!(0xff93000a), + }, + surface: Surface { + color: from_argb!(0xfff7fbf2), + on_surface: from_argb!(0xff181d18), + on_surface_variant: from_argb!(0xff414941), + surface_container: SurfaceContainer { + lowest: from_argb!(0xffffffff), + low: from_argb!(0xfff1f5ed), + base: from_argb!(0xffebefe7), + high: from_argb!(0xffe5e9e1), + highest: from_argb!(0xffe0e4dc), + }, + }, + inverse: Inverse { + inverse_surface: from_argb!(0xff2d322c), + inverse_on_surface: from_argb!(0xffeef2ea), + inverse_primary: from_argb!(0xff9bd4a1), + }, + outline: Outline { + color: from_argb!(0xff727970), + variant: from_argb!(0xffc1c9be), + }, + shadow: from_argb!(0xff000000), + scrim: from_argb!(0x4d000000), + }; +} + +#[derive(Debug, Clone, Copy, PartialEq)] #[cfg_attr(feature = "animate", derive(iced_anim::Animate))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Primary { - #[serde(with = "color_serde")] + #[cfg_attr(feature = "serde", serde(with = "color_serde"))] pub color: Color, - #[serde(with = "color_serde")] + #[cfg_attr(feature = "serde", serde(with = "color_serde"))] pub on_primary: Color, - #[serde(with = "color_serde")] + #[cfg_attr(feature = "serde", serde(with = "color_serde"))] pub primary_container: Color, - #[serde(with = "color_serde")] + #[cfg_attr(feature = "serde", serde(with = "color_serde"))] pub on_primary_container: Color, } -#[derive(Debug, Clone, Copy, PartialEq, Deserialize)] +#[derive(Debug, Clone, Copy, PartialEq)] #[cfg_attr(feature = "animate", derive(iced_anim::Animate))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Secondary { - #[serde(with = "color_serde")] + #[cfg_attr(feature = "serde", serde(with = "color_serde"))] pub color: Color, - #[serde(with = "color_serde")] + #[cfg_attr(feature = "serde", serde(with = "color_serde"))] pub on_secondary: Color, - #[serde(with = "color_serde")] + #[cfg_attr(feature = "serde", serde(with = "color_serde"))] pub secondary_container: Color, - #[serde(with = "color_serde")] + #[cfg_attr(feature = "serde", serde(with = "color_serde"))] pub on_secondary_container: Color, } -#[derive(Debug, Clone, Copy, PartialEq, Deserialize)] +#[derive(Debug, Clone, Copy, PartialEq)] #[cfg_attr(feature = "animate", derive(iced_anim::Animate))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Tertiary { - #[serde(with = "color_serde")] + #[cfg_attr(feature = "serde", serde(with = "color_serde"))] pub color: Color, - #[serde(with = "color_serde")] + #[cfg_attr(feature = "serde", serde(with = "color_serde"))] pub on_tertiary: Color, - #[serde(with = "color_serde")] + #[cfg_attr(feature = "serde", serde(with = "color_serde"))] pub tertiary_container: Color, - #[serde(with = "color_serde")] + #[cfg_attr(feature = "serde", serde(with = "color_serde"))] pub on_tertiary_container: Color, } -#[derive(Debug, Clone, Copy, PartialEq, Deserialize)] +#[derive(Debug, Clone, Copy, PartialEq)] #[cfg_attr(feature = "animate", derive(iced_anim::Animate))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Error { - #[serde(with = "color_serde")] + #[cfg_attr(feature = "serde", serde(with = "color_serde"))] pub color: Color, - #[serde(with = "color_serde")] + #[cfg_attr(feature = "serde", serde(with = "color_serde"))] pub on_error: Color, - #[serde(with = "color_serde")] + #[cfg_attr(feature = "serde", serde(with = "color_serde"))] pub error_container: Color, - #[serde(with = "color_serde")] + #[cfg_attr(feature = "serde", serde(with = "color_serde"))] pub on_error_container: Color, } -#[derive(Debug, Clone, Copy, PartialEq, Deserialize)] +#[derive(Debug, Clone, Copy, PartialEq)] #[cfg_attr(feature = "animate", derive(iced_anim::Animate))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Surface { - #[serde(with = "color_serde")] + #[cfg_attr(feature = "serde", serde(with = "color_serde"))] pub color: Color, - #[serde(with = "color_serde")] + #[cfg_attr(feature = "serde", serde(with = "color_serde"))] pub on_surface: Color, - #[serde(with = "color_serde")] + #[cfg_attr(feature = "serde", serde(with = "color_serde"))] pub on_surface_variant: Color, pub surface_container: SurfaceContainer, } -#[derive(Debug, Clone, Copy, PartialEq, Deserialize)] +#[derive(Debug, Clone, Copy, PartialEq)] #[cfg_attr(feature = "animate", derive(iced_anim::Animate))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct SurfaceContainer { - #[serde(with = "color_serde")] + #[cfg_attr(feature = "serde", serde(with = "color_serde"))] pub lowest: Color, - #[serde(with = "color_serde")] + #[cfg_attr(feature = "serde", serde(with = "color_serde"))] pub low: Color, - #[serde(with = "color_serde")] + #[cfg_attr(feature = "serde", serde(with = "color_serde"))] pub base: Color, - #[serde(with = "color_serde")] + #[cfg_attr(feature = "serde", serde(with = "color_serde"))] pub high: Color, - #[serde(with = "color_serde")] + #[cfg_attr(feature = "serde", serde(with = "color_serde"))] pub highest: Color, } -#[derive(Debug, Clone, Copy, PartialEq, Deserialize)] +#[derive(Debug, Clone, Copy, PartialEq)] #[cfg_attr(feature = "animate", derive(iced_anim::Animate))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Inverse { - #[serde(with = "color_serde")] + #[cfg_attr(feature = "serde", serde(with = "color_serde"))] pub inverse_surface: Color, - #[serde(with = "color_serde")] + #[cfg_attr(feature = "serde", serde(with = "color_serde"))] pub inverse_on_surface: Color, - #[serde(with = "color_serde")] + #[cfg_attr(feature = "serde", serde(with = "color_serde"))] pub inverse_primary: Color, } -#[derive(Debug, Clone, Copy, PartialEq, Deserialize)] +#[derive(Debug, Clone, Copy, PartialEq)] #[cfg_attr(feature = "animate", derive(iced_anim::Animate))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Outline { - #[serde(with = "color_serde")] + #[cfg_attr(feature = "serde", serde(with = "color_serde"))] pub color: Color, - #[serde(with = "color_serde")] + #[cfg_attr(feature = "serde", serde(with = "color_serde"))] pub variant: Color, } +#[cfg(feature = "serde")] mod color_serde { use iced_widget::core::Color; - use serde::{Deserialize, Deserializer}; + use serde::{Deserialize, Deserializer, Serialize, Serializer}; - use super::utils::parse_argb; + use super::utils::{color_to_argb, parse_argb}; pub fn deserialize<'de, D>(deserializer: D) -> Result where @@ -256,4 +375,11 @@ mod color_serde { .map(|hex| parse_argb(&hex))? .unwrap_or(Color::TRANSPARENT)) } + + pub fn serialize(color: &Color, serializer: S) -> Result + where + S: Serializer, + { + color_to_argb(*color).serialize(serializer) + } } diff --git a/crates/material_theme/src/utils.rs b/crates/material_theme/src/utils.rs index a05bc62..f35396f 100644 --- a/crates/material_theme/src/utils.rs +++ b/crates/material_theme/src/utils.rs @@ -66,6 +66,26 @@ pub fn parse_argb(s: &str) -> Option { }) } +pub fn color_to_argb(color: Color) -> String { + use std::fmt::Write; + + let mut hex = String::with_capacity(9); + + let [r, g, b, a] = color.into_rgba8(); + + let _ = write!(&mut hex, "#"); + + if a < u8::MAX { + let _ = write!(&mut hex, "{a:02X}"); + } + + let _ = write!(&mut hex, "{r:02X}"); + let _ = write!(&mut hex, "{g:02X}"); + let _ = write!(&mut hex, "{b:02X}"); + + hex +} + pub fn mix(color1: Color, color2: Color, p2: f32) -> Color { if p2 <= 0.0 { return color1; diff --git a/theme_test/src/main.rs b/theme_test/src/main.rs index 953d4e0..9aab2fe 100644 --- a/theme_test/src/main.rs +++ b/theme_test/src/main.rs @@ -1,7 +1,7 @@ use iced::Element; use iced::Length::Fill; use iced::widget::{ - button, checkbox, column, container, pick_list, row, text_input, + button, checkbox, column, container, pick_list, radio, row, text_input, }; use iced_anim::{Animated, Animation, Event}; use iced_dialog::dialog; @@ -29,6 +29,7 @@ enum Message { CloseDialog, Input(String), CheckBox(bool), + Radio(Choice), SwitchTheme(Event), } @@ -38,6 +39,14 @@ pub struct State { show_dialog: bool, content: String, is_checked: bool, + selection: Option, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum Choice { + A, + B, + C, } impl State { @@ -52,6 +61,7 @@ impl State { } Message::Input(content) => self.content = content, Message::CheckBox(is_checked) => self.is_checked = is_checked, + Message::Radio(choice) => self.selection = Some(choice), Message::SwitchTheme(event) => { self.theme.update(event); } @@ -133,6 +143,9 @@ impl State { .on_toggle(Message::CheckBox) .style(material_theme::checkbox::error), checkbox("Disabled", self.is_checked), + radio("A", Choice::A, self.selection, Message::Radio,), + radio("B", Choice::B, self.selection, Message::Radio,), + radio("C", Choice::C, self.selection, Message::Radio,), ] .spacing(10) ] -- cgit v1.2.3 From 1683717e93899d4c90641e605bfc96cbc2bf5ef1 Mon Sep 17 00:00:00 2001 From: pml68 Date: Fri, 18 Apr 2025 00:52:13 +0200 Subject: fix: `iced` 0.14 codegen --- Cargo.lock | 43 +++++++++++++++++++++---------------------- src/types/project.rs | 2 +- src/types/rendered_element.rs | 13 ++++++++++--- 3 files changed, 32 insertions(+), 26 deletions(-) (limited to 'Cargo.lock') diff --git a/Cargo.lock b/Cargo.lock index e8a5b71..4f0a992 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -187,7 +187,7 @@ dependencies = [ "enumflags2", "futures-channel", "futures-util", - "rand 0.9.0", + "rand 0.9.1", "raw-window-handle", "serde", "serde_repr", @@ -1945,7 +1945,7 @@ dependencies = [ [[package]] name = "iced" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#4f933c3b8919a115fa82d9aee94ec5b1c81c4dfe" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#b6433c4637ddf4697154feeb14c66e06200e4e1b" dependencies = [ "iced_core", "iced_debug", @@ -1980,7 +1980,7 @@ dependencies = [ [[package]] name = "iced_beacon" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#4f933c3b8919a115fa82d9aee94ec5b1c81c4dfe" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#b6433c4637ddf4697154feeb14c66e06200e4e1b" dependencies = [ "bincode", "futures", @@ -2021,7 +2021,7 @@ dependencies = [ [[package]] name = "iced_core" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#4f933c3b8919a115fa82d9aee94ec5b1c81c4dfe" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#b6433c4637ddf4697154feeb14c66e06200e4e1b" dependencies = [ "bitflags 2.9.0", "bytes", @@ -2050,7 +2050,7 @@ dependencies = [ [[package]] name = "iced_debug" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#4f933c3b8919a115fa82d9aee94ec5b1c81c4dfe" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#b6433c4637ddf4697154feeb14c66e06200e4e1b" dependencies = [ "iced_beacon", "iced_core", @@ -2060,7 +2060,7 @@ dependencies = [ [[package]] name = "iced_devtools" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#4f933c3b8919a115fa82d9aee94ec5b1c81c4dfe" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#b6433c4637ddf4697154feeb14c66e06200e4e1b" dependencies = [ "iced_debug", "iced_program", @@ -2100,7 +2100,7 @@ dependencies = [ [[package]] name = "iced_futures" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#4f933c3b8919a115fa82d9aee94ec5b1c81c4dfe" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#b6433c4637ddf4697154feeb14c66e06200e4e1b" dependencies = [ "futures", "iced_core", @@ -2114,7 +2114,7 @@ dependencies = [ [[package]] name = "iced_graphics" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#4f933c3b8919a115fa82d9aee94ec5b1c81c4dfe" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#b6433c4637ddf4697154feeb14c66e06200e4e1b" dependencies = [ "bitflags 2.9.0", "bytemuck", @@ -2135,7 +2135,7 @@ dependencies = [ [[package]] name = "iced_program" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#4f933c3b8919a115fa82d9aee94ec5b1c81c4dfe" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#b6433c4637ddf4697154feeb14c66e06200e4e1b" dependencies = [ "iced_graphics", "iced_runtime", @@ -2144,7 +2144,7 @@ dependencies = [ [[package]] name = "iced_renderer" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#4f933c3b8919a115fa82d9aee94ec5b1c81c4dfe" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#b6433c4637ddf4697154feeb14c66e06200e4e1b" dependencies = [ "iced_graphics", "iced_tiny_skia", @@ -2156,7 +2156,7 @@ dependencies = [ [[package]] name = "iced_runtime" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#4f933c3b8919a115fa82d9aee94ec5b1c81c4dfe" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#b6433c4637ddf4697154feeb14c66e06200e4e1b" dependencies = [ "bytes", "iced_core", @@ -2169,7 +2169,7 @@ dependencies = [ [[package]] name = "iced_tiny_skia" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#4f933c3b8919a115fa82d9aee94ec5b1c81c4dfe" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#b6433c4637ddf4697154feeb14c66e06200e4e1b" dependencies = [ "bytemuck", "cosmic-text", @@ -2186,7 +2186,7 @@ dependencies = [ [[package]] name = "iced_wgpu" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#4f933c3b8919a115fa82d9aee94ec5b1c81c4dfe" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#b6433c4637ddf4697154feeb14c66e06200e4e1b" dependencies = [ "bitflags 2.9.0", "bytemuck", @@ -2207,7 +2207,7 @@ dependencies = [ [[package]] name = "iced_widget" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#4f933c3b8919a115fa82d9aee94ec5b1c81c4dfe" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#b6433c4637ddf4697154feeb14c66e06200e4e1b" dependencies = [ "iced_renderer", "iced_runtime", @@ -2225,7 +2225,7 @@ dependencies = [ [[package]] name = "iced_winit" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#4f933c3b8919a115fa82d9aee94ec5b1c81c4dfe" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#b6433c4637ddf4697154feeb14c66e06200e4e1b" dependencies = [ "iced_debug", "iced_program", @@ -3665,9 +3665,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.94" +version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84" +checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" dependencies = [ "unicode-ident", ] @@ -3781,13 +3781,12 @@ dependencies = [ [[package]] name = "rand" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3779b94aeb87e8bd4e834cee3650289ee9e0d5677f976ecdb6d219e5f4f6cd94" +checksum = "9fbfd9d094a40bf3ae768db9361049ace4c0e04a4fd6b359518bd7b73a73dd97" dependencies = [ "rand_chacha 0.9.0", "rand_core 0.9.3", - "zerocopy 0.8.24", ] [[package]] @@ -4602,9 +4601,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "svg_fmt" -version = "0.4.4" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce5d813d71d82c4cbc1742135004e4a79fd870214c155443451c139c9470a0aa" +checksum = "0193cc4331cfd2f3d2011ef287590868599a2f33c3e69bc22c1a3d3acf9e02fb" [[package]] name = "svgtypes" diff --git a/src/types/project.rs b/src/types/project.rs index 50cbb69..145ab18 100644 --- a/src/types/project.rs +++ b/src/types/project.rs @@ -103,7 +103,7 @@ use iced::{{widget::{{{imports}}},Element}}; {theme_imports} fn main() -> iced::Result {{ - iced::application("{}", State::update, State::view).theme(State::theme).run() + iced::application(State::default, State::update, State::view).title("{}").theme(State::theme).run() }} #[derive(Default)] diff --git a/src/types/rendered_element.rs b/src/types/rendered_element.rs index bd8187e..9639299 100755 --- a/src/types/rendered_element.rs +++ b/src/types/rendered_element.rs @@ -223,7 +223,14 @@ impl RenderedElement { match &self.name { ElementName::Container => { imports = format!("{imports}container,"); - view = format!("{view}\ncontainer({elements}){options}"); + view = format!( + "{view}\ncontainer({}){options}", + if elements.is_empty() { + String::from("\"\"") + } else { + elements.to_string() + } + ); } ElementName::Row => { imports = format!("{imports}row,"); @@ -237,7 +244,7 @@ impl RenderedElement { imports = format!("{imports}text,"); view = format!( "{view}\ntext(\"{}\"){options}", - if *string == String::new() { + if string.is_empty() { "New Text" } else { string @@ -248,7 +255,7 @@ impl RenderedElement { imports = format!("{imports}button,"); view = format!( "{view}\nbutton(\"{}\"){options}", - if *string == String::new() { + if string.is_empty() { "New Button" } else { string -- cgit v1.2.3 From c3c05cef555de305729e53cef8b8e660e31eaf27 Mon Sep 17 00:00:00 2001 From: pml68 Date: Tue, 22 Apr 2025 14:33:36 +0200 Subject: refactor: apply some clippy suggestions --- Cargo.lock | 99 ++++++++++++++++------------------- crates/material_theme/src/button.rs | 4 +- crates/material_theme/src/checkbox.rs | 6 +-- crates/material_theme/src/lib.rs | 5 +- crates/material_theme/src/utils.rs | 6 ++- src/panes/code_view.rs | 2 +- 6 files changed, 59 insertions(+), 63 deletions(-) (limited to 'Cargo.lock') diff --git a/Cargo.lock b/Cargo.lock index 4f0a992..fd31403 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -534,11 +534,11 @@ dependencies = [ [[package]] name = "block2" -version = "0.6.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d59b4c170e16f0405a2e95aff44432a0d41aa97675f3d52623effe95792a037" +checksum = "340d2f0bdb2a43c1d3cd40513185b2bd7def0aa1052f956455114bc98f82dcf2" dependencies = [ - "objc2 0.6.0", + "objc2 0.6.1", ] [[package]] @@ -1070,9 +1070,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a0d569e003ff27784e0e14e4a594048698e0c0f0b66cabcb51511be55a7caa0" dependencies = [ "bitflags 2.9.0", - "block2 0.6.0", + "block2 0.6.1", "libc", - "objc2 0.6.0", + "objc2 0.6.1", +] + +[[package]] +name = "dispatch2" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89a09f22a6c6069a18470eb92d2298acf25463f14256d24778e1230d789a2aec" +dependencies = [ + "bitflags 2.9.0", + "objc2 0.6.1", ] [[package]] @@ -1160,20 +1170,6 @@ version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" -[[package]] -name = "embed-resource" -version = "2.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b68b6f9f63a0b6a38bc447d4ce84e2b388f3ec95c99c641c8ff0dd3ef89a6379" -dependencies = [ - "cc", - "memchr", - "rustc_version", - "toml", - "vswhom", - "winreg", -] - [[package]] name = "embed-resource" version = "3.0.2" @@ -1997,7 +1993,7 @@ name = "iced_builder" version = "0.1.0" dependencies = [ "dirs-next", - "embed-resource 3.0.2", + "embed-resource", "fxhash", "iced", "iced_anim", @@ -2611,9 +2607,9 @@ dependencies = [ [[package]] name = "libm" -version = "0.2.11" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa" +checksum = "c9627da5196e5d8ed0b0495e61e518847578da83483c37288316d9b2e03a7f72" [[package]] name = "libredox" @@ -2675,12 +2671,6 @@ dependencies = [ "scopeguard", ] -[[package]] -name = "lockfree-object-pool" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9374ef4228402d4b7e403e5838cb880d9ee663314b0a900d5a6aabf0c213552e" - [[package]] name = "log" version = "0.4.27" @@ -3124,9 +3114,9 @@ dependencies = [ [[package]] name = "objc2" -version = "0.6.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3531f65190d9cff863b77a99857e74c314dd16bf56c538c4b57c7cbc3f3a6e59" +checksum = "88c6597e14493ab2e44ce58f2fdecf095a51f12ca57bec060a11c57332520551" dependencies = [ "objc2-encode", ] @@ -3149,14 +3139,14 @@ dependencies = [ [[package]] name = "objc2-app-kit" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5906f93257178e2f7ae069efb89fbd6ee94f0592740b5f8a1512ca498814d0fb" +checksum = "e6f29f568bec459b0ddff777cec4fe3fd8666d82d5a40ebd0ff7e66134f89bcc" dependencies = [ "bitflags 2.9.0", - "block2 0.6.0", - "objc2 0.6.0", - "objc2-foundation 0.3.0", + "block2 0.6.1", + "objc2 0.6.1", + "objc2-foundation 0.3.1", ] [[package]] @@ -3197,12 +3187,13 @@ dependencies = [ [[package]] name = "objc2-core-foundation" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "daeaf60f25471d26948a1c2f840e3f7d86f4109e3af4e8e4b5cd70c39690d925" +checksum = "1c10c2894a6fed806ade6027bcd50662746363a9589d3ec9d9bef30a4e4bc166" dependencies = [ "bitflags 2.9.0", - "objc2 0.6.0", + "dispatch2 0.3.0", + "objc2 0.6.1", ] [[package]] @@ -3250,12 +3241,12 @@ dependencies = [ [[package]] name = "objc2-foundation" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a21c6c9014b82c39515db5b396f91645182611c97d24637cf56ac01e5f8d998" +checksum = "900831247d2fe1a09a683278e5384cfb8c80c79fe6b166f9d14bfdde0ea1b03c" dependencies = [ "bitflags 2.9.0", - "objc2 0.6.0", + "objc2 0.6.1", "objc2-core-foundation", ] @@ -4035,14 +4026,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "80c844748fdc82aae252ee4594a89b6e7ebef1063de7951545564cbc4e57075d" dependencies = [ "ashpd 0.11.0", - "block2 0.6.0", - "dispatch2", + "block2 0.6.1", + "dispatch2 0.2.0", "js-sys", "log", - "objc2 0.6.0", - "objc2-app-kit 0.3.0", + "objc2 0.6.1", + "objc2-app-kit 0.3.1", "objc2-core-foundation", - "objc2-foundation 0.3.0", + "objc2-foundation 0.3.1", "pollster", "raw-window-handle", "urlencoding", @@ -4383,9 +4374,9 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "signal-hook-registry" -version = "1.4.2" +version = "1.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +checksum = "9203b8055f63a2a00e2f593bb0510367fe707d7ff1e5c872de2f537b339e5410" dependencies = [ "libc", ] @@ -5952,12 +5943,12 @@ checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c" [[package]] name = "windows_exe_info" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0960cd3c8e7c1a55327ac8206395748c8145dc56c524057d1d50ab80300f49f" +checksum = "3a7c2cd292e8e58e012eaf18f18f6b64ef74e0b90677b4f9e1f15bfca24056c7" dependencies = [ "camino", - "embed-resource 2.5.1", + "embed-resource", ] [[package]] @@ -6515,15 +6506,13 @@ dependencies = [ [[package]] name = "zopfli" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5019f391bac5cf252e93bbcc53d039ffd62c7bfb7c150414d61369afe57e946" +checksum = "edfc5ee405f504cd4984ecc6f14d02d55cfda60fa4b689434ef4102aae150cd7" dependencies = [ "bumpalo", "crc32fast", - "lockfree-object-pool", "log", - "once_cell", "simd-adler32", ] diff --git a/crates/material_theme/src/button.rs b/crates/material_theme/src/button.rs index 21d77b7..e1369eb 100644 --- a/crates/material_theme/src/button.rs +++ b/crates/material_theme/src/button.rs @@ -143,7 +143,7 @@ pub fn outlined(theme: &Theme, status: Status) -> Style { Status::Active | Status::Pressed | Status::Hovered => Border { color: outline, width: 1.0, - radius: 400.0.into(), + radius: 400.into(), }, Status::Disabled => Border { color: Color { @@ -151,7 +151,7 @@ pub fn outlined(theme: &Theme, status: Status) -> Style { ..disabled }, width: 1.0, - radius: 400.0.into(), + radius: 400.into(), }, }; diff --git a/crates/material_theme/src/checkbox.rs b/crates/material_theme/src/checkbox.rs index ac1f974..ff038b0 100644 --- a/crates/material_theme/src/checkbox.rs +++ b/crates/material_theme/src/checkbox.rs @@ -18,7 +18,7 @@ impl Catalog for Theme { pub fn styled( background_color: Color, - background_hover: Option, + background_unchecked: Option, icon_color: Color, border_color: Color, text_color: Option, @@ -28,7 +28,7 @@ pub fn styled( background: Background::Color(if is_checked { background_color } else { - background_hover.unwrap_or(Color::TRANSPARENT) + background_unchecked.unwrap_or(Color::TRANSPARENT) }), icon_color, border: if is_checked { @@ -37,7 +37,7 @@ pub fn styled( Border { color: border_color, width: 2.0, - radius: border::radius(2), + radius: 2.into(), } }, text_color, diff --git a/crates/material_theme/src/lib.rs b/crates/material_theme/src/lib.rs index 416c958..13f13b1 100644 --- a/crates/material_theme/src/lib.rs +++ b/crates/material_theme/src/lib.rs @@ -24,6 +24,7 @@ pub mod slider; #[cfg(feature = "svg")] pub mod svg; pub mod text; +pub mod text_editor; pub mod text_input; pub mod toggler; pub mod utils; @@ -59,7 +60,7 @@ impl Clone for Theme { } fn clone_from(&mut self, source: &Self) { - self.name = source.name.clone(); + self.name.clone_from(&source.name); self.colorscheme = source.colorscheme; } } @@ -142,6 +143,7 @@ pub struct ColorScheme { pub scrim: Color, } +#[allow(clippy::cast_precision_loss)] macro_rules! from_argb { ($hex:expr) => {{ let hex = $hex as u32; @@ -155,6 +157,7 @@ macro_rules! from_argb { }}; } +#[allow(clippy::cast_precision_loss)] impl ColorScheme { const DARK: Self = Self { primary: Primary { diff --git a/crates/material_theme/src/utils.rs b/crates/material_theme/src/utils.rs index f35396f..5ad137e 100644 --- a/crates/material_theme/src/utils.rs +++ b/crates/material_theme/src/utils.rs @@ -1,5 +1,7 @@ use iced_widget::core::{Color, Shadow, Vector}; +const COLOR_ERROR_MARGIN: f32 = 0.0001; + pub const HOVERED_LAYER_OPACITY: f32 = 0.08; pub const PRESSED_LAYER_OPACITY: f32 = 0.1; @@ -95,7 +97,9 @@ pub fn mix(color1: Color, color2: Color, p2: f32) -> Color { let p1 = 1.0 - p2; - if color1.a != 1.0 || color2.a != 1.0 { + if (color1.a - 1.0).abs() > COLOR_ERROR_MARGIN + || (color2.a - 1.0) > COLOR_ERROR_MARGIN + { let a = color1.a * p1 + color2.a * p2; if a > 0.0 { let c1 = color1.into_linear().map(|c| c * color1.a * p1); diff --git a/src/panes/code_view.rs b/src/panes/code_view.rs index 85b0bbe..890af8a 100644 --- a/src/panes/code_view.rs +++ b/src/panes/code_view.rs @@ -71,7 +71,7 @@ pub fn view( palette.background.base.color, ), border: Border { - radius: 2.0.into(), + radius: 2.into(), width: 1.0, color: palette.background.strong.color, }, -- cgit v1.2.3 From 3bdd724119eb2dbcb2480e441cd13f82575c6536 Mon Sep 17 00:00:00 2001 From: pml68 Date: Sat, 26 Apr 2025 13:17:58 +0200 Subject: feat(material_theme): implement `image::Catalog` (under feature flag) --- Cargo.lock | 89 +++++++++++++++++--------------- crates/iced_drop/src/widget/droppable.rs | 2 + crates/material_theme/Cargo.toml | 2 + crates/material_theme/src/image.rs | 21 ++++++++ crates/material_theme/src/lib.rs | 2 + theme_test/src/main.rs | 4 +- 6 files changed, 78 insertions(+), 42 deletions(-) create mode 100644 crates/material_theme/src/image.rs (limited to 'Cargo.lock') diff --git a/Cargo.lock b/Cargo.lock index fd31403..9154eb4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -51,7 +51,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ "cfg-if", - "getrandom 0.2.15", + "getrandom 0.2.16", "once_cell", "version_check", "zerocopy 0.7.35", @@ -657,9 +657,9 @@ checksum = "8b96ec4966b5813e2c0507c1f86115c8c5abaadc3980879c3424042a02fd1ad3" [[package]] name = "cc" -version = "1.2.19" +version = "1.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e3a13707ac958681c13b39b458c073d0d9bc8a22cb1b2f4c8e55eb72c13f362" +checksum = "04da6a0d40b948dfc4fa8f5bbf402b0fc1a64a28dbf7d12ffd683550f2c1b63a" dependencies = [ "jobserver", "libc", @@ -1592,9 +1592,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" dependencies = [ "cfg-if", "libc", @@ -1941,7 +1941,7 @@ dependencies = [ [[package]] name = "iced" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#b6433c4637ddf4697154feeb14c66e06200e4e1b" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#64d4a365f3eb25f716c0632316d46d82bfe818c6" dependencies = [ "iced_core", "iced_debug", @@ -1958,7 +1958,7 @@ dependencies = [ [[package]] name = "iced_anim" version = "0.2.1" -source = "git+https://github.com/pml68/iced_anim#0c833c0943493c8fc22a60e138785e4c688ef8d8" +source = "git+https://github.com/pml68/iced_anim#c881a8a9c49b0536f4ee3c236ec24285eabc0d76" dependencies = [ "iced", "iced_anim_derive", @@ -1967,7 +1967,7 @@ dependencies = [ [[package]] name = "iced_anim_derive" version = "0.2.0" -source = "git+https://github.com/pml68/iced_anim#0c833c0943493c8fc22a60e138785e4c688ef8d8" +source = "git+https://github.com/pml68/iced_anim#c881a8a9c49b0536f4ee3c236ec24285eabc0d76" dependencies = [ "quote", "syn", @@ -1976,7 +1976,7 @@ dependencies = [ [[package]] name = "iced_beacon" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#b6433c4637ddf4697154feeb14c66e06200e4e1b" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#64d4a365f3eb25f716c0632316d46d82bfe818c6" dependencies = [ "bincode", "futures", @@ -2017,7 +2017,7 @@ dependencies = [ [[package]] name = "iced_core" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#b6433c4637ddf4697154feeb14c66e06200e4e1b" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#64d4a365f3eb25f716c0632316d46d82bfe818c6" dependencies = [ "bitflags 2.9.0", "bytes", @@ -2046,7 +2046,7 @@ dependencies = [ [[package]] name = "iced_debug" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#b6433c4637ddf4697154feeb14c66e06200e4e1b" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#64d4a365f3eb25f716c0632316d46d82bfe818c6" dependencies = [ "iced_beacon", "iced_core", @@ -2056,7 +2056,7 @@ dependencies = [ [[package]] name = "iced_devtools" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#b6433c4637ddf4697154feeb14c66e06200e4e1b" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#64d4a365f3eb25f716c0632316d46d82bfe818c6" dependencies = [ "iced_debug", "iced_program", @@ -2066,7 +2066,7 @@ dependencies = [ [[package]] name = "iced_dialog" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced_dialog?branch=iced%2Fpersonal#6e901c21dbb259d337ed1ad2054da3862172b8b3" +source = "git+https://github.com/pml68/iced_dialog?branch=iced%2Fpersonal#57388a202159052ccc771bfb537bd46e8f3b9e70" dependencies = [ "iced_core", "iced_widget", @@ -2096,7 +2096,7 @@ dependencies = [ [[package]] name = "iced_futures" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#b6433c4637ddf4697154feeb14c66e06200e4e1b" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#64d4a365f3eb25f716c0632316d46d82bfe818c6" dependencies = [ "futures", "iced_core", @@ -2110,7 +2110,7 @@ dependencies = [ [[package]] name = "iced_graphics" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#b6433c4637ddf4697154feeb14c66e06200e4e1b" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#64d4a365f3eb25f716c0632316d46d82bfe818c6" dependencies = [ "bitflags 2.9.0", "bytemuck", @@ -2131,7 +2131,7 @@ dependencies = [ [[package]] name = "iced_program" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#b6433c4637ddf4697154feeb14c66e06200e4e1b" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#64d4a365f3eb25f716c0632316d46d82bfe818c6" dependencies = [ "iced_graphics", "iced_runtime", @@ -2140,7 +2140,7 @@ dependencies = [ [[package]] name = "iced_renderer" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#b6433c4637ddf4697154feeb14c66e06200e4e1b" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#64d4a365f3eb25f716c0632316d46d82bfe818c6" dependencies = [ "iced_graphics", "iced_tiny_skia", @@ -2152,7 +2152,7 @@ dependencies = [ [[package]] name = "iced_runtime" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#b6433c4637ddf4697154feeb14c66e06200e4e1b" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#64d4a365f3eb25f716c0632316d46d82bfe818c6" dependencies = [ "bytes", "iced_core", @@ -2165,7 +2165,7 @@ dependencies = [ [[package]] name = "iced_tiny_skia" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#b6433c4637ddf4697154feeb14c66e06200e4e1b" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#64d4a365f3eb25f716c0632316d46d82bfe818c6" dependencies = [ "bytemuck", "cosmic-text", @@ -2182,7 +2182,7 @@ dependencies = [ [[package]] name = "iced_wgpu" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#b6433c4637ddf4697154feeb14c66e06200e4e1b" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#64d4a365f3eb25f716c0632316d46d82bfe818c6" dependencies = [ "bitflags 2.9.0", "bytemuck", @@ -2203,7 +2203,7 @@ dependencies = [ [[package]] name = "iced_widget" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#b6433c4637ddf4697154feeb14c66e06200e4e1b" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#64d4a365f3eb25f716c0632316d46d82bfe818c6" dependencies = [ "iced_renderer", "iced_runtime", @@ -2221,7 +2221,7 @@ dependencies = [ [[package]] name = "iced_winit" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#b6433c4637ddf4697154feeb14c66e06200e4e1b" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#64d4a365f3eb25f716c0632316d46d82bfe818c6" dependencies = [ "iced_debug", "iced_program", @@ -3636,7 +3636,7 @@ version = "0.2.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" dependencies = [ - "zerocopy 0.8.24", + "zerocopy 0.8.25", ] [[package]] @@ -3806,7 +3806,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom 0.2.15", + "getrandom 0.2.16", ] [[package]] @@ -3940,7 +3940,7 @@ version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" dependencies = [ - "getrandom 0.2.15", + "getrandom 0.2.16", "libredox", "thiserror 1.0.69", ] @@ -4060,7 +4060,7 @@ checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" dependencies = [ "cc", "cfg-if", - "getrandom 0.2.15", + "getrandom 0.2.16", "libc", "untrusted", "windows-sys 0.52.0", @@ -4943,9 +4943,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.14" +version = "0.7.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b9590b93e6fcc1739458317cccd391ad3955e2bde8913edf6f95f9e65a8f034" +checksum = "66a539a9ad6d5d281510d5bd368c973d636c02dbf8a67300bfb6b950696ad7df" dependencies = [ "bytes", "futures-core", @@ -4956,9 +4956,9 @@ dependencies = [ [[package]] name = "toml" -version = "0.8.20" +version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd87a5cdd6ffab733b2f74bc4fd7ee5fff6634124999ac278c35fc78c6120148" +checksum = "900f6c86a685850b1bc9f6223b20125115ee3f31e01207d81655bbcc0aea9231" dependencies = [ "serde", "serde_spanned", @@ -4968,26 +4968,33 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "0.6.8" +version = "0.6.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" +checksum = "3da5db5a963e24bc68be8b17b6fa82814bb22ee8660f192bb182771d498f09a3" dependencies = [ "serde", ] [[package]] name = "toml_edit" -version = "0.22.24" +version = "0.22.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17b4795ff5edd201c7cd6dca065ae59972ce77d1b80fa0a84d94950ece7d1474" +checksum = "10558ed0bd2a1562e630926a2d1f0b98c827da99fabd3fe20920a59642504485" dependencies = [ "indexmap", "serde", "serde_spanned", "toml_datetime", + "toml_write", "winnow", ] +[[package]] +name = "toml_write" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28391a4201ba7eb1984cfeb6862c0b3ea2cfe23332298967c749dddc0d6cd976" + [[package]] name = "tower" version = "0.5.2" @@ -6136,9 +6143,9 @@ dependencies = [ [[package]] name = "winnow" -version = "0.7.6" +version = "0.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63d3fcd9bba44b03821e7d699eeee959f3126dcc4aa8e4ae18ec617c2a5cea10" +checksum = "6cb8234a863ea0e8cd7284fcdd4f145233eb00fee02bbdd9861aec44e6477bc5" dependencies = [ "memchr", ] @@ -6384,11 +6391,11 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.8.24" +version = "0.8.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2586fea28e186957ef732a5f8b3be2da217d65c5969d4b1e17f973ebbe876879" +checksum = "a1702d9583232ddb9174e01bb7c15a2ab8fb1bc6f227aa1233858c351a3ba0cb" dependencies = [ - "zerocopy-derive 0.8.24", + "zerocopy-derive 0.8.25", ] [[package]] @@ -6404,9 +6411,9 @@ dependencies = [ [[package]] name = "zerocopy-derive" -version = "0.8.24" +version = "0.8.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a996a8f63c5c4448cd959ac1bab0aaa3306ccfd060472f85943ee0750f0169be" +checksum = "28a6e20d751156648aa063f3800b706ee209a32c0b4d9f24be3d980b01be55ef" dependencies = [ "proc-macro2", "quote", diff --git a/crates/iced_drop/src/widget/droppable.rs b/crates/iced_drop/src/widget/droppable.rs index 947cf5b..196464a 100644 --- a/crates/iced_drop/src/widget/droppable.rs +++ b/crates/iced_drop/src/widget/droppable.rs @@ -418,6 +418,7 @@ where tree: &'b mut Tree, layout: Layout<'_>, renderer: &Renderer, + _viewport: &iced::Rectangle, _translation: Vector, ) -> Option> { let state: &mut State = tree.state.downcast_mut::(); @@ -434,6 +435,7 @@ where &mut tree.children[0], layout, renderer, + _viewport, _translation, ) } diff --git a/crates/material_theme/Cargo.toml b/crates/material_theme/Cargo.toml index 941bc3e..30de38b 100644 --- a/crates/material_theme/Cargo.toml +++ b/crates/material_theme/Cargo.toml @@ -21,6 +21,8 @@ animate = ["dep:iced_anim"] dialog = ["dep:iced_dialog"] # Provides support for the markdown widget. markdown = ["iced_widget/markdown"] +# Provides support for the image widget. +image = ["iced_widget/image"] # Provides support for the SVG widget. svg = ["iced_widget/svg"] # Provides support for the QR code widget. diff --git a/crates/material_theme/src/image.rs b/crates/material_theme/src/image.rs new file mode 100644 index 0000000..de5942a --- /dev/null +++ b/crates/material_theme/src/image.rs @@ -0,0 +1,21 @@ +use iced_widget::core::{Background, Border, Color, border}; +use iced_widget::image::{Catalog, Style, StyleFn}; + +use super::Theme; +use crate::utils::{elevation, shadow_from_elevation}; + +impl Catalog for Theme { + type Class<'a> = StyleFn<'a, Self>; + + fn default<'a>() -> Self::Class<'a> { + Box::new(default) + } + + fn style(&self, class: &Self::Class<'_>) -> Style { + class(self) + } +} + +pub fn default(_theme: &Theme) -> Style { + Style::default() +} diff --git a/crates/material_theme/src/lib.rs b/crates/material_theme/src/lib.rs index 569b06c..1b4f90e 100644 --- a/crates/material_theme/src/lib.rs +++ b/crates/material_theme/src/lib.rs @@ -9,6 +9,8 @@ pub mod combo_box; pub mod container; #[cfg(feature = "dialog")] pub mod dialog; +#[cfg(feature = "image")] +pub mod image; #[cfg(feature = "markdown")] pub mod markdown; pub mod menu; diff --git a/theme_test/src/main.rs b/theme_test/src/main.rs index 7ec7f15..b4a7731 100644 --- a/theme_test/src/main.rs +++ b/theme_test/src/main.rs @@ -1,6 +1,7 @@ use iced::widget::{ button, center, checkbox, column, container, horizontal_rule, pane_grid, - pick_list, radio, row, slider, text_editor, text_input, toggler, + pick_list, progress_bar, radio, row, slider, text_editor, text_input, + toggler, }; use iced::{Element, Length}; use iced_anim::{Animated, Animation, Event}; @@ -238,6 +239,7 @@ impl State { .height(Length::Shrink), slider(0.0..=100.0, self.value, Message::Slider) .step(0.1), + progress_bar(0.0..=100.0, self.value), horizontal_rule(1), // Toggler toggler(self.is_checked) -- cgit v1.2.3 From 9dfb469d1ba975e59f39f3bb799b019204315784 Mon Sep 17 00:00:00 2001 From: pml68 Date: Mon, 28 Apr 2025 10:57:42 +0200 Subject: feat: switch to modified `iced_fontello` for custom Theme support --- Cargo.lock | 10 +- Cargo.toml | 8 +- crates/iced_fontello/.gitignore | 2 + crates/iced_fontello/Cargo.toml | 18 ++ crates/iced_fontello/README.md | 109 +++++++++++ crates/iced_fontello/src/lib.rs | 394 ++++++++++++++++++++++++++++++++++++++++ src/icon.rs | 4 +- 7 files changed, 534 insertions(+), 11 deletions(-) create mode 100644 crates/iced_fontello/.gitignore create mode 100644 crates/iced_fontello/Cargo.toml create mode 100644 crates/iced_fontello/README.md create mode 100644 crates/iced_fontello/src/lib.rs (limited to 'Cargo.lock') diff --git a/Cargo.lock b/Cargo.lock index 9154eb4..02b475d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2082,8 +2082,6 @@ dependencies = [ [[package]] name = "iced_fontello" version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1088f296a44a5c7e51ae5e533954429bfa479d44b304cb7c370480994abab7ef" dependencies = [ "reqwest", "serde", @@ -3737,9 +3735,9 @@ checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3" [[package]] name = "quick-xml" -version = "0.37.4" +version = "0.37.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4ce8c88de324ff838700f36fb6ab86c96df0e3c4ab6ef3a9b2044465cce1369" +checksum = "331e97a1af0bf59823e6eadffe373d7b27f485be8748f71471c662c1f269b7fb" dependencies = [ "memchr", ] @@ -4619,9 +4617,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.100" +version = "2.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0" +checksum = "8ce2b7fc941b3a24138a0a7cf8e858bfc6a992e7978a068a5c760deb0ed43caf" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 0a7d769..9ffaa5d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ iced_anim.workspace = true iced_custom_highlighter = { git = "https://github.com/pml68/iced_custom_highlighter", branch = "master" } iced_drop = { path = "crates/iced_drop" } iced_dialog.workspace = true -material_theme = { path = "crates/material_theme" } +material_theme = { path = "crates/material_theme", features = ["animate", "serde", "dialog", "image", "svg"] } serde.workspace = true serde_json = "1.0.140" toml.workspace = true @@ -38,16 +38,16 @@ dirs-next = "2.0.0" 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" +toml = "0.8.21" [workspace.dependencies.iced] git = "https://github.com/pml68/iced" branch = "feat/rehighlight-on-redraw" default-features = false -features = ["wgpu", "tiny-skia", "web-colors", "auto-detect-theme", "image", "svg", "advanced", "tokio", "lazy"] +features = ["wgpu", "tiny-skia", "web-colors", "auto-detect-theme", "advanced", "tokio", "image", "svg", "lazy"] [build-dependencies] -iced_fontello = "0.13.2" +iced_fontello = { path = "crates/iced_fontello" } [target.'cfg(target_os = "macos")'.dependencies] xdg = "2.5.2" diff --git a/crates/iced_fontello/.gitignore b/crates/iced_fontello/.gitignore new file mode 100644 index 0000000..96ef6c0 --- /dev/null +++ b/crates/iced_fontello/.gitignore @@ -0,0 +1,2 @@ +/target +Cargo.lock diff --git a/crates/iced_fontello/Cargo.toml b/crates/iced_fontello/Cargo.toml new file mode 100644 index 0000000..8c170a1 --- /dev/null +++ b/crates/iced_fontello/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "iced_fontello" +version = "0.13.2" +edition = "2021" +description = "Generate type-safe icon fonts for `iced` at compile time" +repository = "https://github.com/hecrj/iced_fontello" +license = "MIT" +categories = ["gui"] +keywords = ["gui", "ui", "graphics", "interface", "widgets"] +rust-version = "1.85" + +[dependencies] +reqwest = { version = "0.12", features = ["blocking", "json", "multipart"] } +sha2 = "0.10" +serde = { version = "1", features = ["derive"] } +serde_json = "1" +toml = "0.8" +zip = "2" diff --git a/crates/iced_fontello/README.md b/crates/iced_fontello/README.md new file mode 100644 index 0000000..52a59c1 --- /dev/null +++ b/crates/iced_fontello/README.md @@ -0,0 +1,109 @@ +
+ +# iced_fontello + +[![Documentation](https://docs.rs/iced_fontello/badge.svg)](https://docs.rs/iced_fontello) +[![Crates.io](https://img.shields.io/crates/v/iced_fontello.svg)](https://crates.io/crates/iced_fontello) +[![License](https://img.shields.io/crates/l/iced_fontello.svg)](https://github.com/hecrj/iced_fontello/blob/master/LICENSE) +[![Downloads](https://img.shields.io/crates/d/iced_fontello.svg)](https://crates.io/crates/iced_fontello) +[![Test Status](https://img.shields.io/github/actions/workflow/status/hecrj/iced_fontello/test.yml?branch=master&event=push&label=test)](https://github.com/hecrj/iced_fontello/actions) +[![Discourse](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fdiscourse.iced.rs%2Fsite%2Fstatistics.json&query=%24.users_count&suffix=%20users&label=discourse&color=5e7ce2)](https://discourse.iced.rs/) +[![Discord Server](https://img.shields.io/discord/628993209984614400?label=&labelColor=6A7EC2&logo=discord&logoColor=ffffff&color=7389D8)](https://discord.gg/3xZJ65GAhd) + +A compile-time, type-safe icon font generator for [`iced`]. +Powered by [Fontello]. + +[`iced`]: https://github.com/iced-rs/iced +[Fontello]: https://github.com/fontello/fontello + +
+ +## Usage +Create a `.toml` file somewhere in your crate with the font definition: + +```toml +# fonts/example-icons.toml +module = "icon" + +[glyphs] +edit = "fontawesome-pencil" +save = "entypo-floppy" +trash = "typicons-trash" +``` + +The `module` value defines the Rust module that will be generated in your `src` +directory containing a type-safe API to use the font. + +Each entry in the `[glyphs]` section corresponds to an icon. The keys will be +used as names for the functions of the module of the font; while the values +specify the glyph for that key using the format: `-`. You can browse +the available glyphs in [Fontello] or [the `fonts.json` file](fonts.json). + +Next, add `iced_fontello` to your `build-dependencies`: + +```rust +[build-dependencies] +iced_fontello = "0.13" +``` + +Then, call `iced_fontello::build` in your [build script](https://doc.rust-lang.org/cargo/reference/build-scripts.html), +passing the path of your font definition: + +```rust +pub fn main() { + println!("cargo::rerun-if-changed=fonts/example-icons.toml"); + iced_fontello::build("fonts/example-icons.toml").expect("Build example-icons font"); +} +``` + +The library will generate the font and save its `.ttf` file right next to its definition. +In this example, the library would generate `fonts/example-icons.ttf`. + +Finally, it will generate a type-safe `iced` API that lets you use the font. In our example: + +```rust +// Generated automatically by iced_fontello at build time. +// Do not edit manually. +// d24460a00249b2acd0ccc64c3176452c546ad12d1038974e974d7bdb4cdb4a8f +use iced::widget::{text, Text}; +use iced::Font; + +pub const FONT: &[u8] = include_bytes!("../fonts/example-icons.ttf"); + +pub fn edit<'a>() -> Text<'a> { + icon("\u{270E}") +} + +pub fn save<'a>() -> Text<'a> { + icon("\u{1F4BE}") +} + +pub fn trash<'a>() -> Text<'a> { + icon("\u{E10A}") +} + +fn icon<'a>(codepoint: &'a str) -> Text<'a> { + text(codepoint).font(Font::with_name("example-icons")) +} +``` + +Now you can simply add `mod icon;` to your `lib.rs` or `main.rs` file and enjoy your new font: + +```rust +mod icon; + +use iced::widget::row; + +// ... + +row![icon::edit(), icon::save(), icon::trash()].spacing(10) + +// ... +``` + +Check out [the full example](example) to see it all in action. + +## Packaging +If you plan to package your crate, you must make sure you include the generated module +and font file in the final package. `build` is effectively a no-op when the module and +the font already exist and are up-to-date. diff --git a/crates/iced_fontello/src/lib.rs b/crates/iced_fontello/src/lib.rs new file mode 100644 index 0000000..2b39647 --- /dev/null +++ b/crates/iced_fontello/src/lib.rs @@ -0,0 +1,394 @@ +#![allow(clippy::needless_doctest_main)] +//! A compile-time, type-safe icon font generator for [`iced`]. +//! Powered by [Fontello]. +//! +//! [`iced`]: https://github.com/iced-rs/iced +//! [Fontello]: https://github.com/fontello/fontello +//! +//! # Usage +//! Create a `.toml` file somewhere in your crate with the font definition: +//! +//! ```toml +//! # fonts/example-icons.toml +//! module = "icon" +//! +//! [glyphs] +//! edit = "fontawesome-pencil" +//! save = "entypo-floppy" +//! trash = "typicons-trash" +//! ``` +//! +//! The `module` value defines the Rust module that will be generated in your `src` +//! directory containing a type-safe API to use the font. +//! +//! Each entry in the `[glyphs]` section corresponds to an icon. The keys will be +//! used as names for the functions of the module of the font; while the values +//! specify the glyph for that key using the format: `-`. You can browse +//! the available glyphs in [Fontello] or [the `fonts.json` file](fonts.json). +//! +//! Next, add `iced_fontello` to your `build-dependencies`: +//! +//! ```toml +//! [build-dependencies] +//! iced_fontello = "0.13" +//! ``` +//! +//! Then, call `iced_fontello::build` in your [build script](https://doc.rust-lang.org/cargo/reference/build-scripts.html), +//! passing the path of your font definition: +//! +//! ```rust,no_run +//! pub fn main() { +//! println!("cargo::rerun-if-changed=fonts/example-icons.toml"); +//! iced_fontello::build("fonts/example-icons.toml").expect("Build example-icons font"); +//! } +//! ``` +//! +//! The library will generate the font and save its `.ttf` file right next to its definition. +//! In this example, the library would generate `fonts/example-icons.ttf`. +//! +//! Finally, it will generate a type-safe `iced` API that lets you use the font. In our example: +//! +//! ```rust,ignore +//! // Generated automatically by iced_fontello at build time. +//! // Do not edit manually. +//! // d24460a00249b2acd0ccc64c3176452c546ad12d1038974e974d7bdb4cdb4a8f +//! use iced::widget::{text, Text}; +//! use iced::Font; +//! +//! pub const FONT: &[u8] = include_bytes!("../fonts/example-icons.ttf"); +//! +//! pub fn edit<'a>() -> Text<'a> { +//! icon("\u{270E}") +//! } +//! +//! pub fn save<'a>() -> Text<'a> { +//! icon("\u{1F4BE}") +//! } +//! +//! pub fn trash<'a>() -> Text<'a> { +//! icon("\u{E10A}") +//! } +//! +//! fn icon<'a>(codepoint: &'a str) -> Text<'a> { +//! text(codepoint).font(Font::with_name("example-icons")) +//! } +//! ``` +//! +//! Now you can simply add `mod icon;` to your `lib.rs` or `main.rs` file and enjoy your new font: +//! +//! ```rust,ignore +//! mod icon; +//! +//! use iced::widget::row; +//! +//! // ... +//! +//! row![icon::edit(), icon::save(), icon::trash()].spacing(10) +//! +//! // ... +//! ``` +//! +//! Check out [the full example](example) to see it all in action. +//! +//! # Packaging +//! If you plan to package your crate, you must make sure you include the generated module +//! and font file in the final package. `build` is effectively a no-op when the module and +//! the font already exist and are up-to-date. +use std::collections::BTreeMap; +use std::path::{Path, PathBuf}; +use std::{fs, io}; + +use reqwest::blocking as reqwest; +use serde::{Deserialize, Serialize}; + +pub fn build(path: impl AsRef) -> Result<(), Error> { + let path = path.as_ref(); + + let definition: Definition = { + let contents = fs::read_to_string(path).unwrap_or_else(|error| { + panic!( + "Font definition {path} could not be read: {error}", + path = path.display() + ) + }); + + toml::from_str(&contents).unwrap_or_else(|error| { + panic!( + "Font definition {path} is invalid: {error}", + path = path.display() + ) + }) + }; + + let fonts = parse_fonts(); + + let glyphs: BTreeMap = definition + .glyphs + .into_iter() + .map(|(name, id)| { + let Some((font_name, glyph)) = id.split_once('-') else { + panic!( + "Invalid glyph identifier: \"{id}\"\n\ + Glyph identifier must have \"-\" format" + ) + }; + + let Some(font) = fonts.get(font_name) else { + panic!( + "Font \"{font_name}\" was not found. Available fonts are:\n{}", + fonts + .keys() + .map(|name| format!("- {name}")) + .collect::>() + .join("\n") + ); + }; + + let Some(glyph) = font.glyphs.get(glyph) else { + // TODO: Display similarly named candidates + panic!( + "Glyph \"{glyph}\" was not found. Available glyphs are:\n{}", + font.glyphs + .keys() + .map(|name| format!("- {name}")) + .collect::>() + .join("\n") + ); + }; + + ( + name, + ChosenGlyph { + uid: glyph.uid.clone(), + css: glyph.name.clone(), + code: glyph.code, + src: font.name.clone(), + }, + ) + }) + .collect(); + + #[derive(Serialize)] + struct Config { + name: String, + css_prefix_text: &'static str, + css_use_suffix: bool, + hinting: bool, + units_per_em: u32, + ascent: u32, + glyphs: Vec, + } + + #[derive(Clone, Serialize)] + struct ChosenGlyph { + uid: Id, + css: String, + code: u64, + src: String, + } + + let file_name = path + .file_stem() + .expect("Get file stem from definition path") + .to_string_lossy() + .into_owned(); + + let config = Config { + name: file_name.clone(), + css_prefix_text: "icon-", + css_use_suffix: false, + hinting: true, + units_per_em: 1000, + ascent: 850, + glyphs: glyphs.values().cloned().collect(), + }; + + let hash = { + use sha2::Digest as _; + + let mut hasher = sha2::Sha256::new(); + hasher.update( + serde_json::to_string(&config).expect("Serialize config as JSON"), + ); + + format!("{:x}", hasher.finalize()) + }; + + let module_target = PathBuf::new() + .join("src") + .join(definition.module.replace("::", "/")) + .with_extension("rs"); + + let module_contents = + fs::read_to_string(&module_target).unwrap_or_default(); + let module_hash = module_contents + .lines() + .nth(2) + .unwrap_or_default() + .trim_start_matches("// "); + + if hash != module_hash || !path.with_extension("ttf").exists() { + let client = reqwest::Client::new(); + let session = client + .post("https://fontello.com/") + .multipart( + reqwest::multipart::Form::new().part( + "config", + reqwest::multipart::Part::text( + serde_json::to_string(&config) + .expect("Serialize Fontello config"), + ) + .file_name("config.json"), + ), + ) + .send() + .and_then(reqwest::Response::error_for_status) + .and_then(reqwest::Response::text) + .expect("Create Fontello session"); + + let font = client + .get(format!("https://fontello.com/{session}/get")) + .send() + .and_then(reqwest::Response::error_for_status) + .and_then(reqwest::Response::bytes) + .expect("Download Fontello font"); + + let mut archive = zip::ZipArchive::new(io::Cursor::new(font)) + .expect("Parse compressed font"); + + let mut font_file = (0..archive.len()) + .find(|i| { + let file = + archive.by_index(*i).expect("Access zip archive by index"); + + file.name().ends_with(&format!("{file_name}.ttf")) + }) + .and_then(|i| archive.by_index(i).ok()) + .expect("Find font file in zipped archive"); + + io::copy( + &mut font_file, + &mut fs::File::create(path.with_extension("ttf")) + .expect("Create font file"), + ) + .expect("Extract font file"); + } + + let relative_path = PathBuf::from( + std::iter::repeat("../") + .take(definition.module.split("::").count()) + .collect::(), + ); + + let mut module = String::new(); + + module.push_str(&format!( + "// Generated automatically by iced_fontello at build time.\n\ + // Do not edit manually. Source: {source}\n\ + // {hash}\n\ + use iced::Font;\n\ + use iced::widget::text;\n\n\ + use crate::widget::Text;\n\n\ + pub const FONT: &[u8] = include_bytes!(\"{path}\");\n\n", + source = relative_path.join(path.with_extension("toml")).display(), + path = relative_path.join(path.with_extension("ttf")).display() + )); + + for (name, glyph) in glyphs { + module.push_str(&format!( + "\ +pub fn {name}<'a>() -> Text<'a> {{ + icon(\"\\u{{{code:X}}}\") +}}\n\n", + code = glyph.code + )); + } + + module.push_str(&format!( + "\ +fn icon(codepoint: &str) -> Text<'_> {{ + text(codepoint).font(Font::with_name(\"{file_name}\")) +}}\n" + )); + + if module != module_contents { + if let Some(directory) = module_target.parent() { + fs::create_dir_all(directory) + .expect("Create parent directory of font module"); + } + + fs::write(module_target, module).expect("Write font module"); + } + + Ok(()) +} + +#[derive(Debug, Clone)] +pub enum Error {} + +#[derive(Debug, Clone, Deserialize)] +struct Definition { + module: String, + glyphs: BTreeMap, +} + +#[derive(Debug, Clone)] +struct Font { + name: String, + glyphs: BTreeMap, +} + +#[derive(Debug, Clone, Deserialize)] +struct Glyph { + uid: Id, + code: u64, + #[serde(rename = "css")] + name: String, +} + +#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] +struct Id(String); + +fn parse_fonts() -> BTreeMap { + #[derive(Deserialize)] + struct ItemSchema { + font: FontSchema, + glyphs: Vec, + } + + #[derive(Deserialize)] + struct FontSchema { + fontname: String, + } + + let items: Vec = + serde_json::from_str(include_str!("../fonts.json")) + .expect("Deserialize fonts"); + + items + .into_iter() + .map(|item| { + ( + item.font.fontname.clone(), + Font { + name: item.font.fontname, + glyphs: item + .glyphs + .into_iter() + .map(|glyph| (glyph.name.clone(), glyph)) + .collect(), + }, + ) + }) + .collect() +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn it_parses_fonts() { + assert!(!parse_fonts().is_empty()); + } +} diff --git a/src/icon.rs b/src/icon.rs index 3fbeb83..d218943 100644 --- a/src/icon.rs +++ b/src/icon.rs @@ -1,8 +1,10 @@ // Generated automatically by iced_fontello at build time. // Do not edit manually. Source: ../fonts/icons.toml // 915ea6b0646871c0f04350f201f27f28881b61f3bd6ef292a415d67a211739c1 -use iced::widget::{text, Text}; use iced::Font; +use iced::widget::text; + +use crate::widget::Text; pub const FONT: &[u8] = include_bytes!("../fonts/icons.ttf"); -- cgit v1.2.3 From 74ce597cf1ba4f2f28436d84e019baf171d15b48 Mon Sep 17 00:00:00 2001 From: pml68 Date: Tue, 29 Apr 2025 00:19:13 +0200 Subject: chore: remove `theme_test`, dependency cleanup --- Cargo.lock | 87 ++++++------ Cargo.toml | 7 +- crates/material_theme/Cargo.toml | 6 +- theme_test/Cargo.toml | 11 -- theme_test/src/main.rs | 276 --------------------------------------- 5 files changed, 48 insertions(+), 339 deletions(-) delete mode 100644 theme_test/Cargo.toml delete mode 100644 theme_test/src/main.rs (limited to 'Cargo.lock') diff --git a/Cargo.lock b/Cargo.lock index 02b475d..96ac115 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -232,14 +232,15 @@ dependencies = [ [[package]] name = "async-executor" -version = "1.13.1" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30ca9a001c1e8ba5149f91a74362376cc6bc5b919d92d988668657bd570bdcec" +checksum = "bb812ffb58524bdd10860d7d974e2f01cc0950c2438a74ee5ec2e2280c6c4ffa" dependencies = [ "async-task", "concurrent-queue", "fastrand", "futures-lite", + "pin-project-lite", "slab", ] @@ -1941,7 +1942,7 @@ dependencies = [ [[package]] name = "iced" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#64d4a365f3eb25f716c0632316d46d82bfe818c6" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#11c915418f2ad45922d3ca9c113e8c2352497067" dependencies = [ "iced_core", "iced_debug", @@ -1976,7 +1977,7 @@ dependencies = [ [[package]] name = "iced_beacon" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#64d4a365f3eb25f716c0632316d46d82bfe818c6" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#11c915418f2ad45922d3ca9c113e8c2352497067" dependencies = [ "bincode", "futures", @@ -2017,7 +2018,7 @@ dependencies = [ [[package]] name = "iced_core" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#64d4a365f3eb25f716c0632316d46d82bfe818c6" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#11c915418f2ad45922d3ca9c113e8c2352497067" dependencies = [ "bitflags 2.9.0", "bytes", @@ -2046,7 +2047,7 @@ dependencies = [ [[package]] name = "iced_debug" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#64d4a365f3eb25f716c0632316d46d82bfe818c6" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#11c915418f2ad45922d3ca9c113e8c2352497067" dependencies = [ "iced_beacon", "iced_core", @@ -2056,7 +2057,7 @@ dependencies = [ [[package]] name = "iced_devtools" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#64d4a365f3eb25f716c0632316d46d82bfe818c6" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#11c915418f2ad45922d3ca9c113e8c2352497067" dependencies = [ "iced_debug", "iced_program", @@ -2094,7 +2095,7 @@ dependencies = [ [[package]] name = "iced_futures" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#64d4a365f3eb25f716c0632316d46d82bfe818c6" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#11c915418f2ad45922d3ca9c113e8c2352497067" dependencies = [ "futures", "iced_core", @@ -2108,7 +2109,7 @@ dependencies = [ [[package]] name = "iced_graphics" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#64d4a365f3eb25f716c0632316d46d82bfe818c6" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#11c915418f2ad45922d3ca9c113e8c2352497067" dependencies = [ "bitflags 2.9.0", "bytemuck", @@ -2129,7 +2130,7 @@ dependencies = [ [[package]] name = "iced_program" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#64d4a365f3eb25f716c0632316d46d82bfe818c6" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#11c915418f2ad45922d3ca9c113e8c2352497067" dependencies = [ "iced_graphics", "iced_runtime", @@ -2138,7 +2139,7 @@ dependencies = [ [[package]] name = "iced_renderer" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#64d4a365f3eb25f716c0632316d46d82bfe818c6" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#11c915418f2ad45922d3ca9c113e8c2352497067" dependencies = [ "iced_graphics", "iced_tiny_skia", @@ -2150,7 +2151,7 @@ dependencies = [ [[package]] name = "iced_runtime" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#64d4a365f3eb25f716c0632316d46d82bfe818c6" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#11c915418f2ad45922d3ca9c113e8c2352497067" dependencies = [ "bytes", "iced_core", @@ -2163,7 +2164,7 @@ dependencies = [ [[package]] name = "iced_tiny_skia" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#64d4a365f3eb25f716c0632316d46d82bfe818c6" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#11c915418f2ad45922d3ca9c113e8c2352497067" dependencies = [ "bytemuck", "cosmic-text", @@ -2180,7 +2181,7 @@ dependencies = [ [[package]] name = "iced_wgpu" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#64d4a365f3eb25f716c0632316d46d82bfe818c6" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#11c915418f2ad45922d3ca9c113e8c2352497067" dependencies = [ "bitflags 2.9.0", "bytemuck", @@ -2201,7 +2202,7 @@ dependencies = [ [[package]] name = "iced_widget" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#64d4a365f3eb25f716c0632316d46d82bfe818c6" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#11c915418f2ad45922d3ca9c113e8c2352497067" dependencies = [ "iced_renderer", "iced_runtime", @@ -2219,7 +2220,7 @@ dependencies = [ [[package]] name = "iced_winit" version = "0.14.0-dev" -source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#64d4a365f3eb25f716c0632316d46d82bfe818c6" +source = "git+https://github.com/pml68/iced?branch=feat%2Frehighlight-on-redraw#11c915418f2ad45922d3ca9c113e8c2352497067" dependencies = [ "iced_debug", "iced_program", @@ -2554,9 +2555,9 @@ dependencies = [ [[package]] name = "kurbo" -version = "0.11.1" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89234b2cc610a7dd927ebde6b41dd1a5d4214cffaef4cf1fb2195d592f92518f" +checksum = "1077d333efea6170d9ccb96d3c3026f300ca0773da4938cc4c811daa6df68b0c" dependencies = [ "arrayvec", "smallvec", @@ -4600,7 +4601,7 @@ version = "0.15.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68c7541fff44b35860c1a7a47a7cadf3e4a304c457b58f9870d9706ece028afc" dependencies = [ - "kurbo 0.11.1", + "kurbo 0.11.2", "siphasher", ] @@ -4737,16 +4738,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "theme_test" -version = "0.0.1" -dependencies = [ - "iced", - "iced_anim", - "iced_dialog", - "material_theme", -] - [[package]] name = "thiserror" version = "1.0.69" @@ -4954,9 +4945,9 @@ dependencies = [ [[package]] name = "toml" -version = "0.8.21" +version = "0.8.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "900f6c86a685850b1bc9f6223b20125115ee3f31e01207d81655bbcc0aea9231" +checksum = "05ae329d1f08c4d17a59bed7ff5b5a769d062e64a62d34a3261b219e62cd5aae" dependencies = [ "serde", "serde_spanned", @@ -4975,9 +4966,9 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.22.25" +version = "0.22.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10558ed0bd2a1562e630926a2d1f0b98c827da99fabd3fe20920a59642504485" +checksum = "310068873db2c5b3e7659d2cc35d21855dbafa50d1ce336397c666e3cb08137e" dependencies = [ "indexmap", "serde", @@ -4989,9 +4980,9 @@ dependencies = [ [[package]] name = "toml_write" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28391a4201ba7eb1984cfeb6862c0b3ea2cfe23332298967c749dddc0d6cd976" +checksum = "bfb942dfe1d8e29a7ee7fcbde5bd2b9a25fb89aa70caea2eba3bee836ff41076" [[package]] name = "tower" @@ -5210,7 +5201,7 @@ dependencies = [ "flate2", "fontdb 0.18.0", "imagesize", - "kurbo 0.11.1", + "kurbo 0.11.2", "log", "pico-args", "roxmltree", @@ -5414,9 +5405,9 @@ dependencies = [ [[package]] name = "wayland-backend" -version = "0.3.8" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7208998eaa3870dad37ec8836979581506e0c5c64c20c9e79e9d2a10d6f47bf" +checksum = "c2bea670be0e24795f39416e5461ccef0185b47df2749ed2b226b8a7557ac871" dependencies = [ "cc", "downcast-rs", @@ -5428,9 +5419,9 @@ dependencies = [ [[package]] name = "wayland-client" -version = "0.31.8" +version = "0.31.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2120de3d33638aaef5b9f4472bff75f07c56379cf76ea320bd3a3d65ecaf73f" +checksum = "5029b0ff4f7be961c326169ee8e247d534d8507dbe390cac6aa3d2cc7c268825" dependencies = [ "bitflags 2.9.0", "rustix 0.38.44", @@ -5451,9 +5442,9 @@ dependencies = [ [[package]] name = "wayland-cursor" -version = "0.31.8" +version = "0.31.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a93029cbb6650748881a00e4922b076092a6a08c11e7fbdb923f064b23968c5d" +checksum = "28d6ec438d7c38bde05a10e80c3e3a1212d85f941be9fc9f80c86e6f5f498252" dependencies = [ "rustix 0.38.44", "wayland-client", @@ -5462,9 +5453,9 @@ dependencies = [ [[package]] name = "wayland-protocols" -version = "0.32.6" +version = "0.32.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0781cf46869b37e36928f7b432273c0995aa8aed9552c556fb18754420541efc" +checksum = "ba8de1f9dda5e589d08848af3ad4cd694bbfd059c3eb3c6d89c7120e8c0efa71" dependencies = [ "bitflags 2.9.0", "wayland-backend", @@ -5474,9 +5465,9 @@ dependencies = [ [[package]] name = "wayland-protocols-plasma" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ccaacc76703fefd6763022ac565b590fcade92202492381c95b2edfdf7d46b3" +checksum = "87e10c27e3290310d7e0d3221bc4e945d9b296b249577af2eb595726b546a3f8" dependencies = [ "bitflags 2.9.0", "wayland-backend", @@ -5487,9 +5478,9 @@ dependencies = [ [[package]] name = "wayland-protocols-wlr" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "248a02e6f595aad796561fa82d25601bd2c8c3b145b1c7453fc8f94c1a58f8b2" +checksum = "9f3334ee752fbe3c228adfda339a9e7a03e0ba65a78806d8d464b69928cf4ef2" dependencies = [ "bitflags 2.9.0", "wayland-backend", diff --git a/Cargo.toml b/Cargo.toml index 9ffaa5d..a653682 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,14 +35,14 @@ thiserror = "2.0.12" dirs-next = "2.0.0" [workspace.dependencies] +iced_widget = "0.14.0-dev" 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.21" [workspace.dependencies.iced] -git = "https://github.com/pml68/iced" -branch = "feat/rehighlight-on-redraw" +version = "0.14.0-dev" default-features = false features = ["wgpu", "tiny-skia", "web-colors", "auto-detect-theme", "advanced", "tokio", "image", "svg", "lazy"] @@ -75,7 +75,7 @@ name = "iced-builder" path = "src/main.rs" [workspace] -members = ["crates/*", "theme_test"] +members = ["crates/*"] default-members = ["crates/material_theme", "."] [lints.rust] @@ -100,5 +100,6 @@ useless_conversion = "deny" clone_on_copy = "deny" [patch.crates-io] +iced = { git = "https://github.com/pml68/iced", branch = "feat/rehighlight-on-redraw" } iced_anim = { git = "https://github.com/pml68/iced_anim" } iced_widget = { git = "https://github.com/pml68/iced", branch = "feat/rehighlight-on-redraw" } diff --git a/crates/material_theme/Cargo.toml b/crates/material_theme/Cargo.toml index 30de38b..0116c1e 100644 --- a/crates/material_theme/Cargo.toml +++ b/crates/material_theme/Cargo.toml @@ -29,7 +29,6 @@ svg = ["iced_widget/svg"] qr_code = ["iced_widget/qr_code"] [dependencies] -iced_widget = "0.14.0-dev" dark-light = "2.0.0" serde.workspace = true @@ -38,6 +37,11 @@ serde.optional = true iced_dialog.workspace = true iced_dialog.optional = true +[dependencies.iced_widget] +version = "0.14.0-dev" +git = "https://github.com/pml68/iced" +branch = "feat/rehighlight-on-redraw" + [dependencies.iced_anim] workspace = true features = ["derive"] diff --git a/theme_test/Cargo.toml b/theme_test/Cargo.toml deleted file mode 100644 index 300a7af..0000000 --- a/theme_test/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "theme_test" -version = "0.0.1" -edition = "2024" - -[dependencies] -iced.workspace = true -iced.features = ["debug"] -iced_anim.workspace = true -iced_dialog.workspace = true -material_theme = { path = "../crates/material_theme", features = ["dialog", "animate"] } diff --git a/theme_test/src/main.rs b/theme_test/src/main.rs deleted file mode 100644 index cba4377..0000000 --- a/theme_test/src/main.rs +++ /dev/null @@ -1,276 +0,0 @@ -use iced::widget::{ - button, center, checkbox, column, container, horizontal_rule, pane_grid, - pick_list, progress_bar, radio, row, slider, text_editor, text_input, - toggler, -}; -use iced::{Element, Length}; -use iced_anim::{Animated, Animation, Event}; -use iced_dialog::dialog; -use material_theme::Theme; -use material_theme::button::{elevated, filled_tonal, outlined, text}; -use material_theme::container::{ - error, error_container, inverse_surface, primary, primary_container, - secondary, secondary_container, surface, surface_container, - surface_container_high, surface_container_highest, surface_container_low, - surface_container_lowest, tertiary, tertiary_container, -}; -use material_theme::text::surface_variant; - -fn main() -> iced::Result { - iced::application(State::default, State::update, State::view) - .theme(|state| state.theme.value().clone()) - .run() -} - -#[allow(dead_code)] -#[derive(Debug, Clone)] -enum Message { - Noop, - OpenDialog, - CloseDialog, - Input(String), - Bool(bool), - Radio(Choice), - Slider(f32), - Edit(text_editor::Action), - Resize(pane_grid::ResizeEvent), - SwitchTheme(Event), -} - -#[derive(Debug)] -pub struct State { - theme: Animated, - show_dialog: bool, - content: String, - is_checked: bool, - selection: Option, - value: f32, - editor_content: text_editor::Content, - panes: pane_grid::State, -} - -impl Default for State { - fn default() -> Self { - Self { - theme: Default::default(), - show_dialog: Default::default(), - content: Default::default(), - is_checked: Default::default(), - selection: Default::default(), - value: Default::default(), - editor_content: text_editor::Content::new(), - panes: pane_grid::State::with_configuration( - pane_grid::Configuration::Split { - axis: pane_grid::Axis::Vertical, - ratio: 0.5, - a: Box::new(pane_grid::Configuration::Pane(Pane::Left)), - b: Box::new(pane_grid::Configuration::Pane(Pane::Right)), - }, - ), - } - } -} - -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum Choice { - A, - B, - C, -} - -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum Pane { - Left, - Right, -} - -impl State { - fn update(&mut self, message: Message) { - match message { - Message::Noop => {} - Message::OpenDialog => { - self.show_dialog = true; - } - Message::CloseDialog => { - self.show_dialog = false; - } - Message::Input(content) => self.content = content, - Message::Bool(is_checked) => self.is_checked = is_checked, - Message::Radio(choice) => self.selection = Some(choice), - Message::Slider(value) => self.value = value, - Message::Edit(action) => self.editor_content.perform(action), - Message::Resize(pane_grid::ResizeEvent { split, ratio }) => { - self.panes.resize(split, ratio); - } - Message::SwitchTheme(event) => { - self.theme.update(event); - } - } - } - fn view(&self) -> Element<'_, Message, Theme> { - let base: pane_grid::PaneGrid<'_, Message, Theme> = - pane_grid(&self.panes, |_pane, state, _is_maximized| { - pane_grid::Content::new(match state { - Pane::Left => container( - row![ - column![ - button("Disabled"), - button("Filled").on_press(Message::Noop), - button("Filled Tonal") - .on_press(Message::Noop) - .style(filled_tonal), - button("Elevated") - .on_press(Message::Noop) - .style(elevated), - button("Outlined") - .on_press(Message::Noop) - .style(outlined), - button("Text") - .on_press(Message::Noop) - .style(text), - button("Text Disabled").style(text), - ] - .spacing(10), - column![ - container("None").padding(8), - container("Primary").padding(8).style(primary), - container("Primary Container") - .padding(8) - .style(primary_container), - container("Secondary") - .padding(8) - .style(secondary), - container("Secondary Container") - .padding(8) - .style(secondary_container), - container("Tertiary") - .padding(8) - .style(tertiary), - container("Tertiary Container") - .padding(8) - .style(tertiary_container), - container("Error").padding(8).style(error), - container("Error Container") - .padding(8) - .style(error_container), - container("Surface").padding(8).style(surface), - container( - iced::widget::text("Surface Variant") - .style(surface_variant) - ) - .padding(8) - .style(surface), - container("Inverse Surface") - .padding(8) - .style(inverse_surface), - container("Surface Container Lowest") - .padding(8) - .style(surface_container_lowest), - container("Surface Container Low") - .padding(8) - .style(surface_container_low), - container("Surface Container") - .padding(8) - .style(surface_container), - container("Surface Container High") - .padding(8) - .style(surface_container_high), - container("Surface Container Highest") - .padding(8) - .style(surface_container_highest), - ] - .spacing(10), - ] - .spacing(10), - ) - .width(Length::Fill) - .height(Length::Fill) - .padding(12), - - Pane::Right => container( - column![ - // Pick List - pick_list( - Theme::ALL, - Some(self.theme.target()), - |theme| Message::SwitchTheme(theme.into()) - ) - .placeholder("Select a theme..."), - horizontal_rule(1), - // Dialog - button("Open Dialog").on_press(Message::OpenDialog), - horizontal_rule(1), - // Text Input - text_input("Type something here...", &self.content) - .on_input(Message::Input), - text_input("Disabled", "Disabled"), - horizontal_rule(1), - // Checkbox - checkbox("Normal", self.is_checked) - .on_toggle(Message::Bool), - checkbox("Error", self.is_checked) - .on_toggle(Message::Bool) - .style(material_theme::checkbox::error), - checkbox("Disabled", self.is_checked), - horizontal_rule(1), - // Radio - radio( - "A", - Choice::A, - self.selection, - Message::Radio, - ), - radio( - "B", - Choice::B, - self.selection, - Message::Radio, - ), - radio( - "C", - Choice::C, - self.selection, - Message::Radio, - ), - horizontal_rule(1), - // Slider - center(iced::widget::text!("{:.1}", self.value)) - .width(Length::Fill) - .height(Length::Shrink), - slider(0.0..=100.0, self.value, Message::Slider) - .step(0.1), - progress_bar(0.0..=100.0, self.value), - horizontal_rule(1), - // Toggler - toggler(self.is_checked) - .on_toggle(Message::Bool) - .size(24.0), - toggler(self.is_checked).size(24.0), - horizontal_rule(1), - // Text Editor - text_editor(&self.editor_content) - .on_action(Message::Edit), - text_editor(&self.editor_content) - .placeholder("Disabled") - ] - .spacing(10), - ) - .width(Length::Fill) - .height(Length::Fill) - .padding(12), - }) - }) - .on_resize(10, Message::Resize); - - let dialog = - dialog(self.show_dialog, base, iced::widget::text("Say Hi!")) - .title("This is a Dialog.") - .push_button(iced_dialog::button("Hi!", Message::CloseDialog)) - .width(280) - .height(186); - - Animation::new(&self.theme, dialog) - .on_update(Message::SwitchTheme) - .into() - } -} -- cgit v1.2.3