From 905f2160e6eb7504f52d9bd62c7bfa42c8ec2902 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 7 Mar 2024 00:14:41 +0100 Subject: Move `Theme` type to `iced_core` --- Cargo.toml | 5 - core/Cargo.toml | 3 +- core/src/color.rs | 6 - core/src/lib.rs | 2 + core/src/theme.rs | 221 +++++++++++++ core/src/theme/palette.rs | 625 +++++++++++++++++++++++++++++++++++ examples/color_palette/Cargo.toml | 2 +- examples/integration/src/controls.rs | 3 +- examples/integration/src/main.rs | 3 +- src/lib.rs | 7 +- src/time.rs | 2 +- style/Cargo.toml | 18 - style/src/lib.rs | 21 -- style/src/theme.rs | 221 ------------- style/src/theme/palette.rs | 625 ----------------------------------- widget/Cargo.toml | 1 - widget/src/button.rs | 11 +- widget/src/checkbox.rs | 8 +- widget/src/combo_box.rs | 3 +- widget/src/container.rs | 3 +- widget/src/lib.rs | 3 +- widget/src/overlay/menu.rs | 3 +- widget/src/pane_grid.rs | 6 +- widget/src/pick_list.rs | 3 +- widget/src/progress_bar.rs | 5 +- widget/src/qr_code.rs | 4 +- widget/src/radio.rs | 5 +- widget/src/rule.rs | 3 +- widget/src/scrollable.rs | 3 +- widget/src/slider.rs | 6 +- widget/src/svg.rs | 4 +- widget/src/text_editor.rs | 3 +- widget/src/text_input.rs | 6 +- widget/src/toggler.rs | 6 +- widget/src/vertical_slider.rs | 3 +- winit/Cargo.toml | 1 - winit/src/application.rs | 3 +- winit/src/lib.rs | 1 - 38 files changed, 888 insertions(+), 970 deletions(-) create mode 100644 core/src/theme.rs create mode 100644 core/src/theme/palette.rs delete mode 100644 style/Cargo.toml delete mode 100644 style/src/lib.rs delete mode 100644 style/src/theme.rs delete mode 100644 style/src/theme/palette.rs diff --git a/Cargo.toml b/Cargo.toml index 7f55ce0e..f446e2af 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,8 +39,6 @@ tokio = ["iced_futures/tokio"] async-std = ["iced_futures/async-std"] # Enables `smol` as the `executor::Default` on native platforms smol = ["iced_futures/smol"] -# Enables advanced color conversion via `palette` -palette = ["iced_core/palette"] # Enables querying system information system = ["iced_winit/system"] # Enables broken "sRGB linear" blending to reproduce color management of the Web @@ -57,7 +55,6 @@ advanced = [] fira-sans = ["iced_renderer/fira-sans"] [dependencies] -iced_core.workspace = true iced_futures.workspace = true iced_renderer.workspace = true iced_widget.workspace = true @@ -90,7 +87,6 @@ members = [ "highlighter", "renderer", "runtime", - "style", "tiny_skia", "wgpu", "widget", @@ -116,7 +112,6 @@ iced_graphics = { version = "0.13.0-dev", path = "graphics" } iced_highlighter = { version = "0.13.0-dev", path = "highlighter" } iced_renderer = { version = "0.13.0-dev", path = "renderer" } iced_runtime = { version = "0.13.0-dev", path = "runtime" } -iced_style = { version = "0.13.0-dev", path = "style" } iced_tiny_skia = { version = "0.13.0-dev", path = "tiny_skia" } iced_wgpu = { version = "0.13.0-dev", path = "wgpu" } iced_widget = { version = "0.13.0-dev", path = "widget" } diff --git a/core/Cargo.toml b/core/Cargo.toml index 2360e822..e71b75ae 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -19,9 +19,8 @@ smol_str.workspace = true thiserror.workspace = true web-time.workspace = true xxhash-rust.workspace = true - palette.workspace = true -palette.optional = true +once_cell.workspace = true [target.'cfg(windows)'.dependencies] raw-window-handle.workspace = true diff --git a/core/src/color.rs b/core/src/color.rs index 6526e220..da40ca15 100644 --- a/core/src/color.rs +++ b/core/src/color.rs @@ -1,4 +1,3 @@ -#[cfg(feature = "palette")] use palette::rgb::{Srgb, Srgba}; /// A color in the `sRGB` color space. @@ -210,7 +209,6 @@ macro_rules! color { }}; } -#[cfg(feature = "palette")] /// Converts from palette's `Rgba` type to a [`Color`]. impl From for Color { fn from(rgba: Srgba) -> Self { @@ -218,7 +216,6 @@ impl From for Color { } } -#[cfg(feature = "palette")] /// Converts from [`Color`] to palette's `Rgba` type. impl From for Srgba { fn from(c: Color) -> Self { @@ -226,7 +223,6 @@ impl From for Srgba { } } -#[cfg(feature = "palette")] /// Converts from palette's `Rgb` type to a [`Color`]. impl From for Color { fn from(rgb: Srgb) -> Self { @@ -234,7 +230,6 @@ impl From for Color { } } -#[cfg(feature = "palette")] /// Converts from [`Color`] to palette's `Rgb` type. impl From for Srgb { fn from(c: Color) -> Self { @@ -242,7 +237,6 @@ impl From for Srgb { } } -#[cfg(feature = "palette")] #[cfg(test)] mod tests { use super::*; diff --git a/core/src/lib.rs b/core/src/lib.rs index 002336ee..d076413e 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -30,6 +30,7 @@ pub mod overlay; pub mod renderer; pub mod svg; pub mod text; +pub mod theme; pub mod time; pub mod touch; pub mod widget; @@ -76,6 +77,7 @@ pub use shadow::Shadow; pub use shell::Shell; pub use size::Size; pub use text::Text; +pub use theme::Theme; pub use transformation::Transformation; pub use vector::Vector; pub use widget::Widget; diff --git a/core/src/theme.rs b/core/src/theme.rs new file mode 100644 index 00000000..21ba2a37 --- /dev/null +++ b/core/src/theme.rs @@ -0,0 +1,221 @@ +//! Use the built-in theme and styles. +pub mod palette; + +pub use palette::Palette; + +use std::fmt; +use std::sync::Arc; + +/// A built-in theme. +#[derive(Debug, Clone, PartialEq, Default)] +pub enum Theme { + /// The built-in light variant. + #[default] + Light, + /// The built-in dark variant. + Dark, + /// The built-in Dracula variant. + Dracula, + /// The built-in Nord variant. + Nord, + /// The built-in Solarized Light variant. + SolarizedLight, + /// The built-in Solarized Dark variant. + SolarizedDark, + /// The built-in Gruvbox Light variant. + GruvboxLight, + /// The built-in Gruvbox Dark variant. + GruvboxDark, + /// The built-in Catppuccin Latte variant. + CatppuccinLatte, + /// The built-in Catppuccin Frappé variant. + CatppuccinFrappe, + /// The built-in Catppuccin Macchiato variant. + CatppuccinMacchiato, + /// The built-in Catppuccin Mocha variant. + CatppuccinMocha, + /// The built-in Tokyo Night variant. + TokyoNight, + /// The built-in Tokyo Night Storm variant. + TokyoNightStorm, + /// The built-in Tokyo Night Light variant. + TokyoNightLight, + /// The built-in Kanagawa Wave variant. + KanagawaWave, + /// The built-in Kanagawa Dragon variant. + KanagawaDragon, + /// The built-in Kanagawa Lotus variant. + KanagawaLotus, + /// The built-in Moonfly variant. + Moonfly, + /// The built-in Nightfly variant. + Nightfly, + /// The built-in Oxocarbon variant. + Oxocarbon, + /// A [`Theme`] that uses a [`Custom`] palette. + Custom(Arc), +} + +impl Theme { + /// A list with all the defined themes. + pub const ALL: &'static [Self] = &[ + Self::Light, + Self::Dark, + Self::Dracula, + Self::Nord, + Self::SolarizedLight, + Self::SolarizedDark, + Self::GruvboxLight, + Self::GruvboxDark, + Self::CatppuccinLatte, + Self::CatppuccinFrappe, + Self::CatppuccinMacchiato, + Self::CatppuccinMocha, + Self::TokyoNight, + Self::TokyoNightStorm, + Self::TokyoNightLight, + Self::KanagawaWave, + Self::KanagawaDragon, + Self::KanagawaLotus, + Self::Moonfly, + Self::Nightfly, + Self::Oxocarbon, + ]; + + /// Creates a new custom [`Theme`] from the given [`Palette`]. + pub fn custom(name: String, palette: Palette) -> Self { + Self::custom_with_fn(name, palette, palette::Extended::generate) + } + + /// Creates a new custom [`Theme`] from the given [`Palette`], with + /// a custom generator of a [`palette::Extended`]. + pub fn custom_with_fn( + name: String, + palette: Palette, + generate: impl FnOnce(Palette) -> palette::Extended, + ) -> Self { + Self::Custom(Arc::new(Custom::with_fn(name, palette, generate))) + } + + /// Returns the [`Palette`] of the [`Theme`]. + pub fn palette(&self) -> Palette { + match self { + Self::Light => Palette::LIGHT, + Self::Dark => Palette::DARK, + Self::Dracula => Palette::DRACULA, + Self::Nord => Palette::NORD, + Self::SolarizedLight => Palette::SOLARIZED_LIGHT, + Self::SolarizedDark => Palette::SOLARIZED_DARK, + Self::GruvboxLight => Palette::GRUVBOX_LIGHT, + Self::GruvboxDark => Palette::GRUVBOX_DARK, + Self::CatppuccinLatte => Palette::CATPPUCCIN_LATTE, + Self::CatppuccinFrappe => Palette::CATPPUCCIN_FRAPPE, + Self::CatppuccinMacchiato => Palette::CATPPUCCIN_MACCHIATO, + Self::CatppuccinMocha => Palette::CATPPUCCIN_MOCHA, + Self::TokyoNight => Palette::TOKYO_NIGHT, + Self::TokyoNightStorm => Palette::TOKYO_NIGHT_STORM, + Self::TokyoNightLight => Palette::TOKYO_NIGHT_LIGHT, + Self::KanagawaWave => Palette::KANAGAWA_WAVE, + Self::KanagawaDragon => Palette::KANAGAWA_DRAGON, + Self::KanagawaLotus => Palette::KANAGAWA_LOTUS, + Self::Moonfly => Palette::MOONFLY, + Self::Nightfly => Palette::NIGHTFLY, + Self::Oxocarbon => Palette::OXOCARBON, + Self::Custom(custom) => custom.palette, + } + } + + /// Returns the [`palette::Extended`] of the [`Theme`]. + pub fn extended_palette(&self) -> &palette::Extended { + match self { + Self::Light => &palette::EXTENDED_LIGHT, + Self::Dark => &palette::EXTENDED_DARK, + Self::Dracula => &palette::EXTENDED_DRACULA, + Self::Nord => &palette::EXTENDED_NORD, + Self::SolarizedLight => &palette::EXTENDED_SOLARIZED_LIGHT, + Self::SolarizedDark => &palette::EXTENDED_SOLARIZED_DARK, + Self::GruvboxLight => &palette::EXTENDED_GRUVBOX_LIGHT, + Self::GruvboxDark => &palette::EXTENDED_GRUVBOX_DARK, + Self::CatppuccinLatte => &palette::EXTENDED_CATPPUCCIN_LATTE, + Self::CatppuccinFrappe => &palette::EXTENDED_CATPPUCCIN_FRAPPE, + Self::CatppuccinMacchiato => { + &palette::EXTENDED_CATPPUCCIN_MACCHIATO + } + Self::CatppuccinMocha => &palette::EXTENDED_CATPPUCCIN_MOCHA, + Self::TokyoNight => &palette::EXTENDED_TOKYO_NIGHT, + Self::TokyoNightStorm => &palette::EXTENDED_TOKYO_NIGHT_STORM, + Self::TokyoNightLight => &palette::EXTENDED_TOKYO_NIGHT_LIGHT, + Self::KanagawaWave => &palette::EXTENDED_KANAGAWA_WAVE, + Self::KanagawaDragon => &palette::EXTENDED_KANAGAWA_DRAGON, + Self::KanagawaLotus => &palette::EXTENDED_KANAGAWA_LOTUS, + Self::Moonfly => &palette::EXTENDED_MOONFLY, + Self::Nightfly => &palette::EXTENDED_NIGHTFLY, + Self::Oxocarbon => &palette::EXTENDED_OXOCARBON, + Self::Custom(custom) => &custom.extended, + } + } +} + +impl fmt::Display for Theme { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::Light => write!(f, "Light"), + Self::Dark => write!(f, "Dark"), + Self::Dracula => write!(f, "Dracula"), + Self::Nord => write!(f, "Nord"), + Self::SolarizedLight => write!(f, "Solarized Light"), + Self::SolarizedDark => write!(f, "Solarized Dark"), + Self::GruvboxLight => write!(f, "Gruvbox Light"), + Self::GruvboxDark => write!(f, "Gruvbox Dark"), + Self::CatppuccinLatte => write!(f, "Catppuccin Latte"), + Self::CatppuccinFrappe => write!(f, "Catppuccin Frappé"), + Self::CatppuccinMacchiato => write!(f, "Catppuccin Macchiato"), + Self::CatppuccinMocha => write!(f, "Catppuccin Mocha"), + Self::TokyoNight => write!(f, "Tokyo Night"), + Self::TokyoNightStorm => write!(f, "Tokyo Night Storm"), + Self::TokyoNightLight => write!(f, "Tokyo Night Light"), + Self::KanagawaWave => write!(f, "Kanagawa Wave"), + Self::KanagawaDragon => write!(f, "Kanagawa Dragon"), + Self::KanagawaLotus => write!(f, "Kanagawa Lotus"), + Self::Moonfly => write!(f, "Moonfly"), + Self::Nightfly => write!(f, "Nightfly"), + Self::Oxocarbon => write!(f, "Oxocarbon"), + Self::Custom(custom) => custom.fmt(f), + } + } +} + +/// A [`Theme`] with a customized [`Palette`]. +#[derive(Debug, Clone, PartialEq)] +pub struct Custom { + name: String, + palette: Palette, + extended: palette::Extended, +} + +impl Custom { + /// Creates a [`Custom`] theme from the given [`Palette`]. + pub fn new(name: String, palette: Palette) -> Self { + Self::with_fn(name, palette, palette::Extended::generate) + } + + /// Creates a [`Custom`] theme from the given [`Palette`] with + /// a custom generator of a [`palette::Extended`]. + pub fn with_fn( + name: String, + palette: Palette, + generate: impl FnOnce(Palette) -> palette::Extended, + ) -> Self { + Self { + name, + palette, + extended: generate(palette), + } + } +} + +impl fmt::Display for Custom { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", self.name) + } +} diff --git a/core/src/theme/palette.rs b/core/src/theme/palette.rs new file mode 100644 index 00000000..985a54a8 --- /dev/null +++ b/core/src/theme/palette.rs @@ -0,0 +1,625 @@ +//! Define the colors of a theme. +use crate::{color, Color}; + +use once_cell::sync::Lazy; +use palette::color_difference::Wcag21RelativeContrast; +use palette::rgb::Rgb; +use palette::{FromColor, Hsl, Mix}; + +/// A color palette. +#[derive(Debug, Clone, Copy, PartialEq)] +pub struct Palette { + /// The background [`Color`] of the [`Palette`]. + pub background: Color, + /// The text [`Color`] of the [`Palette`]. + pub text: Color, + /// The primary [`Color`] of the [`Palette`]. + pub primary: Color, + /// The success [`Color`] of the [`Palette`]. + pub success: Color, + /// The danger [`Color`] of the [`Palette`]. + pub danger: Color, +} + +impl Palette { + /// The built-in light variant of a [`Palette`]. + pub const LIGHT: Self = Self { + background: Color::WHITE, + text: Color::BLACK, + primary: Color::from_rgb( + 0x5E as f32 / 255.0, + 0x7C as f32 / 255.0, + 0xE2 as f32 / 255.0, + ), + success: Color::from_rgb( + 0x12 as f32 / 255.0, + 0x66 as f32 / 255.0, + 0x4F as f32 / 255.0, + ), + danger: Color::from_rgb( + 0xC3 as f32 / 255.0, + 0x42 as f32 / 255.0, + 0x3F as f32 / 255.0, + ), + }; + + /// The built-in dark variant of a [`Palette`]. + pub const DARK: Self = Self { + background: Color::from_rgb( + 0x20 as f32 / 255.0, + 0x22 as f32 / 255.0, + 0x25 as f32 / 255.0, + ), + text: Color::from_rgb(0.90, 0.90, 0.90), + primary: Color::from_rgb( + 0x5E as f32 / 255.0, + 0x7C as f32 / 255.0, + 0xE2 as f32 / 255.0, + ), + success: Color::from_rgb( + 0x12 as f32 / 255.0, + 0x66 as f32 / 255.0, + 0x4F as f32 / 255.0, + ), + danger: Color::from_rgb( + 0xC3 as f32 / 255.0, + 0x42 as f32 / 255.0, + 0x3F as f32 / 255.0, + ), + }; + + /// The built-in [Dracula] variant of a [`Palette`]. + /// + /// [Dracula]: https://draculatheme.com + pub const DRACULA: Self = Self { + background: color!(0x282A36), // BACKGROUND + text: color!(0xf8f8f2), // FOREGROUND + primary: color!(0xbd93f9), // PURPLE + success: color!(0x50fa7b), // GREEN + danger: color!(0xff5555), // RED + }; + + /// The built-in [Nord] variant of a [`Palette`]. + /// + /// [Nord]: https://www.nordtheme.com/docs/colors-and-palettes + pub const NORD: Self = Self { + background: color!(0x2e3440), // nord0 + text: color!(0xeceff4), // nord6 + primary: color!(0x8fbcbb), // nord7 + success: color!(0xa3be8c), // nord14 + danger: color!(0xbf616a), // nord11 + }; + + /// The built-in [Solarized] Light variant of a [`Palette`]. + /// + /// [Solarized]: https://ethanschoonover.com/solarized + pub const SOLARIZED_LIGHT: Self = Self { + background: color!(0xfdf6e3), // base3 + text: color!(0x657b83), // base00 + primary: color!(0x2aa198), // cyan + success: color!(0x859900), // green + danger: color!(0xdc322f), // red + }; + + /// The built-in [Solarized] Dark variant of a [`Palette`]. + /// + /// [Solarized]: https://ethanschoonover.com/solarized + pub const SOLARIZED_DARK: Self = Self { + background: color!(0x002b36), // base03 + text: color!(0x839496), // base0 + primary: color!(0x2aa198), // cyan + success: color!(0x859900), // green + danger: color!(0xdc322f), // red + }; + + /// The built-in [Gruvbox] Light variant of a [`Palette`]. + /// + /// [Gruvbox]: https://github.com/morhetz/gruvbox + pub const GRUVBOX_LIGHT: Self = Self { + background: color!(0xfbf1c7), // light BG_0 + text: color!(0x282828), // light FG0_29 + primary: color!(0x458588), // light BLUE_4 + success: color!(0x98971a), // light GREEN_2 + danger: color!(0xcc241d), // light RED_1 + }; + + /// The built-in [Gruvbox] Dark variant of a [`Palette`]. + /// + /// [Gruvbox]: https://github.com/morhetz/gruvbox + pub const GRUVBOX_DARK: Self = Self { + background: color!(0x282828), // dark BG_0 + text: color!(0xfbf1c7), // dark FG0_29 + primary: color!(0x458588), // dark BLUE_4 + success: color!(0x98971a), // dark GREEN_2 + danger: color!(0xcc241d), // dark RED_1 + }; + + /// The built-in [Catppuccin] Latte variant of a [`Palette`]. + /// + /// [Catppuccin]: https://github.com/catppuccin/catppuccin + pub const CATPPUCCIN_LATTE: Self = Self { + background: color!(0xeff1f5), // Base + text: color!(0x4c4f69), // Text + primary: color!(0x1e66f5), // Blue + success: color!(0x40a02b), // Green + danger: color!(0xd20f39), // Red + }; + + /// The built-in [Catppuccin] Frappé variant of a [`Palette`]. + /// + /// [Catppuccin]: https://github.com/catppuccin/catppuccin + pub const CATPPUCCIN_FRAPPE: Self = Self { + background: color!(0x303446), // Base + text: color!(0xc6d0f5), // Text + primary: color!(0x8caaee), // Blue + success: color!(0xa6d189), // Green + danger: color!(0xe78284), // Red + }; + + /// The built-in [Catppuccin] Macchiato variant of a [`Palette`]. + /// + /// [Catppuccin]: https://github.com/catppuccin/catppuccin + pub const CATPPUCCIN_MACCHIATO: Self = Self { + background: color!(0x24273a), // Base + text: color!(0xcad3f5), // Text + primary: color!(0x8aadf4), // Blue + success: color!(0xa6da95), // Green + danger: color!(0xed8796), // Red + }; + + /// The built-in [Catppuccin] Mocha variant of a [`Palette`]. + /// + /// [Catppuccin]: https://github.com/catppuccin/catppuccin + pub const CATPPUCCIN_MOCHA: Self = Self { + background: color!(0x1e1e2e), // Base + text: color!(0xcdd6f4), // Text + primary: color!(0x89b4fa), // Blue + success: color!(0xa6e3a1), // Green + danger: color!(0xf38ba8), // Red + }; + + /// The built-in [Tokyo Night] variant of a [`Palette`]. + /// + /// [Tokyo Night]: https://github.com/enkia/tokyo-night-vscode-theme + pub const TOKYO_NIGHT: Self = Self { + background: color!(0x1a1b26), // Background (Night) + text: color!(0x9aa5ce), // Text + primary: color!(0x2ac3de), // Blue + success: color!(0x9ece6a), // Green + danger: color!(0xf7768e), // Red + }; + + /// The built-in [Tokyo Night] Storm variant of a [`Palette`]. + /// + /// [Tokyo Night]: https://github.com/enkia/tokyo-night-vscode-theme + pub const TOKYO_NIGHT_STORM: Self = Self { + background: color!(0x24283b), // Background (Storm) + text: color!(0x9aa5ce), // Text + primary: color!(0x2ac3de), // Blue + success: color!(0x9ece6a), // Green + danger: color!(0xf7768e), // Red + }; + + /// The built-in [Tokyo Night] Light variant of a [`Palette`]. + /// + /// [Tokyo Night]: https://github.com/enkia/tokyo-night-vscode-theme + pub const TOKYO_NIGHT_LIGHT: Self = Self { + background: color!(0xd5d6db), // Background + text: color!(0x565a6e), // Text + primary: color!(0x166775), // Blue + success: color!(0x485e30), // Green + danger: color!(0x8c4351), // Red + }; + + /// The built-in [Kanagawa] Wave variant of a [`Palette`]. + /// + /// [Kanagawa]: https://github.com/rebelot/kanagawa.nvim + pub const KANAGAWA_WAVE: Self = Self { + background: color!(0x363646), // Sumi Ink 3 + text: color!(0xCD7BA), // Fuji White + primary: color!(0x2D4F67), // Wave Blue 2 + success: color!(0x76946A), // Autumn Green + danger: color!(0xC34043), // Autumn Red + }; + + /// The built-in [Kanagawa] Dragon variant of a [`Palette`]. + /// + /// [Kanagawa]: https://github.com/rebelot/kanagawa.nvim + pub const KANAGAWA_DRAGON: Self = Self { + background: color!(0x181616), // Dragon Black 3 + text: color!(0xc5c9c5), // Dragon White + primary: color!(0x223249), // Wave Blue 1 + success: color!(0x8a9a7b), // Dragon Green 2 + danger: color!(0xc4746e), // Dragon Red + }; + + /// The built-in [Kanagawa] Lotus variant of a [`Palette`]. + /// + /// [Kanagawa]: https://github.com/rebelot/kanagawa.nvim + pub const KANAGAWA_LOTUS: Self = Self { + background: color!(0xf2ecbc), // Lotus White 3 + text: color!(0x545464), // Lotus Ink 1 + primary: color!(0xc9cbd1), // Lotus Violet 3 + success: color!(0x6f894e), // Lotus Green + danger: color!(0xc84053), // Lotus Red + }; + + /// The built-in [Moonfly] variant of a [`Palette`]. + /// + /// [Moonfly]: https://github.com/bluz71/vim-moonfly-colors + pub const MOONFLY: Self = Self { + background: color!(0x080808), // Background + text: color!(0xbdbdbd), // Foreground + primary: color!(0x80a0ff), // Blue (normal) + success: color!(0x8cc85f), // Green (normal) + danger: color!(0xff5454), // Red (normal) + }; + + /// The built-in [Nightfly] variant of a [`Palette`]. + /// + /// [Nightfly]: https://github.com/bluz71/vim-nightfly-colors + pub const NIGHTFLY: Self = Self { + background: color!(0x011627), // Background + text: color!(0xbdc1c6), // Foreground + primary: color!(0x82aaff), // Blue (normal) + success: color!(0xa1cd5e), // Green (normal) + danger: color!(0xfc514e), // Red (normal) + }; + + /// The built-in [Oxocarbon] variant of a [`Palette`]. + /// + /// [Oxocarbon]: https://github.com/nyoom-engineering/oxocarbon.nvim + pub const OXOCARBON: Self = Self { + background: color!(0x232323), + text: color!(0xd0d0d0), + primary: color!(0x00b4ff), + success: color!(0x00c15a), + danger: color!(0xf62d0f), + }; +} + +/// An extended set of colors generated from a [`Palette`]. +#[derive(Debug, Clone, Copy, PartialEq)] +pub struct Extended { + /// The set of background colors. + pub background: Background, + /// The set of primary colors. + pub primary: Primary, + /// The set of secondary colors. + pub secondary: Secondary, + /// The set of success colors. + pub success: Success, + /// The set of danger colors. + pub danger: Danger, + /// Whether the palette is dark or not. + pub is_dark: bool, +} + +/// The built-in light variant of an [`Extended`] palette. +pub static EXTENDED_LIGHT: Lazy = + Lazy::new(|| Extended::generate(Palette::LIGHT)); + +/// The built-in dark variant of an [`Extended`] palette. +pub static EXTENDED_DARK: Lazy = + Lazy::new(|| Extended::generate(Palette::DARK)); + +/// The built-in Dracula variant of an [`Extended`] palette. +pub static EXTENDED_DRACULA: Lazy = + Lazy::new(|| Extended::generate(Palette::DRACULA)); + +/// The built-in Nord variant of an [`Extended`] palette. +pub static EXTENDED_NORD: Lazy = + Lazy::new(|| Extended::generate(Palette::NORD)); + +/// The built-in Solarized Light variant of an [`Extended`] palette. +pub static EXTENDED_SOLARIZED_LIGHT: Lazy = + Lazy::new(|| Extended::generate(Palette::SOLARIZED_LIGHT)); + +/// The built-in Solarized Dark variant of an [`Extended`] palette. +pub static EXTENDED_SOLARIZED_DARK: Lazy = + Lazy::new(|| Extended::generate(Palette::SOLARIZED_DARK)); + +/// The built-in Gruvbox Light variant of an [`Extended`] palette. +pub static EXTENDED_GRUVBOX_LIGHT: Lazy = + Lazy::new(|| Extended::generate(Palette::GRUVBOX_LIGHT)); + +/// The built-in Gruvbox Dark variant of an [`Extended`] palette. +pub static EXTENDED_GRUVBOX_DARK: Lazy = + Lazy::new(|| Extended::generate(Palette::GRUVBOX_DARK)); + +/// The built-in Catppuccin Latte variant of an [`Extended`] palette. +pub static EXTENDED_CATPPUCCIN_LATTE: Lazy = + Lazy::new(|| Extended::generate(Palette::CATPPUCCIN_LATTE)); + +/// The built-in Catppuccin Frappé variant of an [`Extended`] palette. +pub static EXTENDED_CATPPUCCIN_FRAPPE: Lazy = + Lazy::new(|| Extended::generate(Palette::CATPPUCCIN_FRAPPE)); + +/// The built-in Catppuccin Macchiato variant of an [`Extended`] palette. +pub static EXTENDED_CATPPUCCIN_MACCHIATO: Lazy = + Lazy::new(|| Extended::generate(Palette::CATPPUCCIN_MACCHIATO)); + +/// The built-in Catppuccin Mocha variant of an [`Extended`] palette. +pub static EXTENDED_CATPPUCCIN_MOCHA: Lazy = + Lazy::new(|| Extended::generate(Palette::CATPPUCCIN_MOCHA)); + +/// The built-in Tokyo Night variant of an [`Extended`] palette. +pub static EXTENDED_TOKYO_NIGHT: Lazy = + Lazy::new(|| Extended::generate(Palette::TOKYO_NIGHT)); + +/// The built-in Tokyo Night Storm variant of an [`Extended`] palette. +pub static EXTENDED_TOKYO_NIGHT_STORM: Lazy = + Lazy::new(|| Extended::generate(Palette::TOKYO_NIGHT_STORM)); + +/// The built-in Tokyo Night variant of an [`Extended`] palette. +pub static EXTENDED_TOKYO_NIGHT_LIGHT: Lazy = + Lazy::new(|| Extended::generate(Palette::TOKYO_NIGHT_LIGHT)); + +/// The built-in Kanagawa Wave variant of an [`Extended`] palette. +pub static EXTENDED_KANAGAWA_WAVE: Lazy = + Lazy::new(|| Extended::generate(Palette::KANAGAWA_WAVE)); + +/// The built-in Kanagawa Dragon variant of an [`Extended`] palette. +pub static EXTENDED_KANAGAWA_DRAGON: Lazy = + Lazy::new(|| Extended::generate(Palette::KANAGAWA_DRAGON)); + +/// The built-in Kanagawa Lotus variant of an [`Extended`] palette. +pub static EXTENDED_KANAGAWA_LOTUS: Lazy = + Lazy::new(|| Extended::generate(Palette::KANAGAWA_LOTUS)); + +/// The built-in Moonfly variant of an [`Extended`] palette. +pub static EXTENDED_MOONFLY: Lazy = + Lazy::new(|| Extended::generate(Palette::MOONFLY)); + +/// The built-in Nightfly variant of an [`Extended`] palette. +pub static EXTENDED_NIGHTFLY: Lazy = + Lazy::new(|| Extended::generate(Palette::NIGHTFLY)); + +/// The built-in Oxocarbon variant of an [`Extended`] palette. +pub static EXTENDED_OXOCARBON: Lazy = + Lazy::new(|| Extended::generate(Palette::OXOCARBON)); + +impl Extended { + /// Generates an [`Extended`] palette from a simple [`Palette`]. + pub fn generate(palette: Palette) -> Self { + Self { + background: Background::new(palette.background, palette.text), + primary: Primary::generate( + palette.primary, + palette.background, + palette.text, + ), + secondary: Secondary::generate(palette.background, palette.text), + success: Success::generate( + palette.success, + palette.background, + palette.text, + ), + danger: Danger::generate( + palette.danger, + palette.background, + palette.text, + ), + is_dark: is_dark(palette.background), + } + } +} + +/// A pair of background and text colors. +#[derive(Debug, Clone, Copy, PartialEq)] +pub struct Pair { + /// The background color. + pub color: Color, + + /// The text color. + /// + /// It's guaranteed to be readable on top of the background [`color`]. + /// + /// [`color`]: Self::color + pub text: Color, +} + +impl Pair { + /// Creates a new [`Pair`] from a background [`Color`] and some text [`Color`]. + pub fn new(color: Color, text: Color) -> Self { + Self { + color, + text: readable(color, text), + } + } +} + +/// A set of background colors. +#[derive(Debug, Clone, Copy, PartialEq)] +pub struct Background { + /// The base background color. + pub base: Pair, + /// A weaker version of the base background color. + pub weak: Pair, + /// A stronger version of the base background color. + pub strong: Pair, +} + +impl Background { + /// Generates a set of [`Background`] colors from the base and text colors. + pub fn new(base: Color, text: Color) -> Self { + let weak = mix(base, text, 0.15); + let strong = mix(base, text, 0.40); + + Self { + base: Pair::new(base, text), + weak: Pair::new(weak, text), + strong: Pair::new(strong, text), + } + } +} + +/// A set of primary colors. +#[derive(Debug, Clone, Copy, PartialEq)] +pub struct Primary { + /// The base primary color. + pub base: Pair, + /// A weaker version of the base primary color. + pub weak: Pair, + /// A stronger version of the base primary color. + pub strong: Pair, +} + +impl Primary { + /// Generates a set of [`Primary`] colors from the base, background, and text colors. + pub fn generate(base: Color, background: Color, text: Color) -> Self { + let weak = mix(base, background, 0.4); + let strong = deviate(base, 0.1); + + Self { + base: Pair::new(base, text), + weak: Pair::new(weak, text), + strong: Pair::new(strong, text), + } + } +} + +/// A set of secondary colors. +#[derive(Debug, Clone, Copy, PartialEq)] +pub struct Secondary { + /// The base secondary color. + pub base: Pair, + /// A weaker version of the base secondary color. + pub weak: Pair, + /// A stronger version of the base secondary color. + pub strong: Pair, +} + +impl Secondary { + /// Generates a set of [`Secondary`] colors from the base and text colors. + pub fn generate(base: Color, text: Color) -> Self { + let base = mix(base, text, 0.2); + let weak = mix(base, text, 0.1); + let strong = mix(base, text, 0.3); + + Self { + base: Pair::new(base, text), + weak: Pair::new(weak, text), + strong: Pair::new(strong, text), + } + } +} + +/// A set of success colors. +#[derive(Debug, Clone, Copy, PartialEq)] +pub struct Success { + /// The base success color. + pub base: Pair, + /// A weaker version of the base success color. + pub weak: Pair, + /// A stronger version of the base success color. + pub strong: Pair, +} + +impl Success { + /// Generates a set of [`Success`] colors from the base, background, and text colors. + pub fn generate(base: Color, background: Color, text: Color) -> Self { + let weak = mix(base, background, 0.4); + let strong = deviate(base, 0.1); + + Self { + base: Pair::new(base, text), + weak: Pair::new(weak, text), + strong: Pair::new(strong, text), + } + } +} + +/// A set of danger colors. +#[derive(Debug, Clone, Copy, PartialEq)] +pub struct Danger { + /// The base danger color. + pub base: Pair, + /// A weaker version of the base danger color. + pub weak: Pair, + /// A stronger version of the base danger color. + pub strong: Pair, +} + +impl Danger { + /// Generates a set of [`Danger`] colors from the base, background, and text colors. + pub fn generate(base: Color, background: Color, text: Color) -> Self { + let weak = mix(base, background, 0.4); + let strong = deviate(base, 0.1); + + Self { + base: Pair::new(base, text), + weak: Pair::new(weak, text), + strong: Pair::new(strong, text), + } + } +} + +fn darken(color: Color, amount: f32) -> Color { + let mut hsl = to_hsl(color); + + hsl.lightness = if hsl.lightness - amount < 0.0 { + 0.0 + } else { + hsl.lightness - amount + }; + + from_hsl(hsl) +} + +fn lighten(color: Color, amount: f32) -> Color { + let mut hsl = to_hsl(color); + + hsl.lightness = if hsl.lightness + amount > 1.0 { + 1.0 + } else { + hsl.lightness + amount + }; + + from_hsl(hsl) +} + +fn deviate(color: Color, amount: f32) -> Color { + if is_dark(color) { + lighten(color, amount) + } else { + darken(color, amount) + } +} + +fn mix(a: Color, b: Color, factor: f32) -> Color { + let a_lin = Rgb::from(a).into_linear(); + let b_lin = Rgb::from(b).into_linear(); + + let mixed = a_lin.mix(b_lin, factor); + Rgb::from_linear(mixed).into() +} + +fn readable(background: Color, text: Color) -> Color { + if is_readable(background, text) { + text + } else if is_dark(background) { + Color::WHITE + } else { + Color::BLACK + } +} + +fn is_dark(color: Color) -> bool { + to_hsl(color).lightness < 0.6 +} + +fn is_readable(a: Color, b: Color) -> bool { + let a_srgb = Rgb::from(a); + let b_srgb = Rgb::from(b); + + a_srgb.has_enhanced_contrast_text(b_srgb) +} + +fn to_hsl(color: Color) -> Hsl { + Hsl::from_color(Rgb::from(color)) +} + +fn from_hsl(hsl: Hsl) -> Color { + Rgb::from_color(hsl).into() +} diff --git a/examples/color_palette/Cargo.toml b/examples/color_palette/Cargo.toml index 2da6c6ed..bf9bff19 100644 --- a/examples/color_palette/Cargo.toml +++ b/examples/color_palette/Cargo.toml @@ -7,6 +7,6 @@ publish = false [dependencies] iced.workspace = true -iced.features = ["canvas", "palette"] +iced.features = ["canvas"] palette.workspace = true diff --git a/examples/integration/src/controls.rs b/examples/integration/src/controls.rs index 473a7138..28050f8a 100644 --- a/examples/integration/src/controls.rs +++ b/examples/integration/src/controls.rs @@ -1,9 +1,8 @@ use iced_wgpu::Renderer; use iced_widget::{column, container, row, slider, text, text_input}; use iced_winit::core::alignment; -use iced_winit::core::{Color, Element, Length}; +use iced_winit::core::{Color, Element, Length, Theme}; use iced_winit::runtime::{Command, Program}; -use iced_winit::style::Theme; pub struct Controls { background_color: Color, diff --git a/examples/integration/src/main.rs b/examples/integration/src/main.rs index 0e2e53ac..f53b5bf1 100644 --- a/examples/integration/src/main.rs +++ b/examples/integration/src/main.rs @@ -10,11 +10,10 @@ use iced_winit::conversion; use iced_winit::core::mouse; use iced_winit::core::renderer; use iced_winit::core::window; -use iced_winit::core::{Color, Font, Pixels, Size}; +use iced_winit::core::{Color, Font, Pixels, Size, Theme}; use iced_winit::futures; use iced_winit::runtime::program; use iced_winit::runtime::Debug; -use iced_winit::style::Theme; use iced_winit::winit; use iced_winit::Clipboard; diff --git a/src/lib.rs b/src/lib.rs index 236c64d3..c596f2a6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -162,7 +162,6 @@ #![cfg_attr(docsrs, feature(doc_cfg))] use iced_widget::graphics; use iced_widget::renderer; -use iced_widget::style; use iced_winit as shell; use iced_winit::core; use iced_winit::runtime; @@ -186,15 +185,14 @@ pub mod advanced; #[cfg(feature = "multi-window")] pub mod multi_window; -pub use style::theme; - pub use crate::core::alignment; pub use crate::core::border; pub use crate::core::color; pub use crate::core::gradient; +pub use crate::core::theme; pub use crate::core::{ Alignment, Background, Border, Color, ContentFit, Degrees, Gradient, - Length, Padding, Pixels, Point, Radians, Rectangle, Shadow, Size, + Length, Padding, Pixels, Point, Radians, Rectangle, Shadow, Size, Theme, Transformation, Vector, }; @@ -314,7 +312,6 @@ pub use renderer::Renderer; pub use sandbox::Sandbox; pub use settings::Settings; pub use subscription::Subscription; -pub use theme::Theme; /// A generic widget. /// diff --git a/src/time.rs b/src/time.rs index e255d751..26d31c0a 100644 --- a/src/time.rs +++ b/src/time.rs @@ -1,5 +1,5 @@ //! Listen and react to time. -pub use iced_core::time::{Duration, Instant}; +pub use crate::core::time::{Duration, Instant}; #[allow(unused_imports)] #[cfg_attr( diff --git a/style/Cargo.toml b/style/Cargo.toml deleted file mode 100644 index 3f00e787..00000000 --- a/style/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -name = "iced_style" -description = "The default set of styles of Iced" -version.workspace = true -edition.workspace = true -authors.workspace = true -license.workspace = true -repository.workspace = true -homepage.workspace = true -categories.workspace = true -keywords.workspace = true - -[dependencies] -iced_core.workspace = true -iced_core.features = ["palette"] - -palette.workspace = true -once_cell.workspace = true diff --git a/style/src/lib.rs b/style/src/lib.rs deleted file mode 100644 index bc0e37e9..00000000 --- a/style/src/lib.rs +++ /dev/null @@ -1,21 +0,0 @@ -//! The styling library of Iced. -//! -//! It contains a set of styles and stylesheets for most of the built-in -//! widgets. -//! -//! ![The foundations of the Iced ecosystem](https://github.com/iced-rs/iced/blob/0525d76ff94e828b7b21634fa94a747022001c83/docs/graphs/foundations.png?raw=true) -#![doc( - html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg" -)] -#![forbid(unsafe_code, rust_2018_idioms)] -#![deny( - unused_results, - // missing_docs, - unused_results, - rustdoc::broken_intra_doc_links -)] -pub use iced_core as core; - -pub mod theme; - -pub use theme::Theme; diff --git a/style/src/theme.rs b/style/src/theme.rs deleted file mode 100644 index 21ba2a37..00000000 --- a/style/src/theme.rs +++ /dev/null @@ -1,221 +0,0 @@ -//! Use the built-in theme and styles. -pub mod palette; - -pub use palette::Palette; - -use std::fmt; -use std::sync::Arc; - -/// A built-in theme. -#[derive(Debug, Clone, PartialEq, Default)] -pub enum Theme { - /// The built-in light variant. - #[default] - Light, - /// The built-in dark variant. - Dark, - /// The built-in Dracula variant. - Dracula, - /// The built-in Nord variant. - Nord, - /// The built-in Solarized Light variant. - SolarizedLight, - /// The built-in Solarized Dark variant. - SolarizedDark, - /// The built-in Gruvbox Light variant. - GruvboxLight, - /// The built-in Gruvbox Dark variant. - GruvboxDark, - /// The built-in Catppuccin Latte variant. - CatppuccinLatte, - /// The built-in Catppuccin Frappé variant. - CatppuccinFrappe, - /// The built-in Catppuccin Macchiato variant. - CatppuccinMacchiato, - /// The built-in Catppuccin Mocha variant. - CatppuccinMocha, - /// The built-in Tokyo Night variant. - TokyoNight, - /// The built-in Tokyo Night Storm variant. - TokyoNightStorm, - /// The built-in Tokyo Night Light variant. - TokyoNightLight, - /// The built-in Kanagawa Wave variant. - KanagawaWave, - /// The built-in Kanagawa Dragon variant. - KanagawaDragon, - /// The built-in Kanagawa Lotus variant. - KanagawaLotus, - /// The built-in Moonfly variant. - Moonfly, - /// The built-in Nightfly variant. - Nightfly, - /// The built-in Oxocarbon variant. - Oxocarbon, - /// A [`Theme`] that uses a [`Custom`] palette. - Custom(Arc), -} - -impl Theme { - /// A list with all the defined themes. - pub const ALL: &'static [Self] = &[ - Self::Light, - Self::Dark, - Self::Dracula, - Self::Nord, - Self::SolarizedLight, - Self::SolarizedDark, - Self::GruvboxLight, - Self::GruvboxDark, - Self::CatppuccinLatte, - Self::CatppuccinFrappe, - Self::CatppuccinMacchiato, - Self::CatppuccinMocha, - Self::TokyoNight, - Self::TokyoNightStorm, - Self::TokyoNightLight, - Self::KanagawaWave, - Self::KanagawaDragon, - Self::KanagawaLotus, - Self::Moonfly, - Self::Nightfly, - Self::Oxocarbon, - ]; - - /// Creates a new custom [`Theme`] from the given [`Palette`]. - pub fn custom(name: String, palette: Palette) -> Self { - Self::custom_with_fn(name, palette, palette::Extended::generate) - } - - /// Creates a new custom [`Theme`] from the given [`Palette`], with - /// a custom generator of a [`palette::Extended`]. - pub fn custom_with_fn( - name: String, - palette: Palette, - generate: impl FnOnce(Palette) -> palette::Extended, - ) -> Self { - Self::Custom(Arc::new(Custom::with_fn(name, palette, generate))) - } - - /// Returns the [`Palette`] of the [`Theme`]. - pub fn palette(&self) -> Palette { - match self { - Self::Light => Palette::LIGHT, - Self::Dark => Palette::DARK, - Self::Dracula => Palette::DRACULA, - Self::Nord => Palette::NORD, - Self::SolarizedLight => Palette::SOLARIZED_LIGHT, - Self::SolarizedDark => Palette::SOLARIZED_DARK, - Self::GruvboxLight => Palette::GRUVBOX_LIGHT, - Self::GruvboxDark => Palette::GRUVBOX_DARK, - Self::CatppuccinLatte => Palette::CATPPUCCIN_LATTE, - Self::CatppuccinFrappe => Palette::CATPPUCCIN_FRAPPE, - Self::CatppuccinMacchiato => Palette::CATPPUCCIN_MACCHIATO, - Self::CatppuccinMocha => Palette::CATPPUCCIN_MOCHA, - Self::TokyoNight => Palette::TOKYO_NIGHT, - Self::TokyoNightStorm => Palette::TOKYO_NIGHT_STORM, - Self::TokyoNightLight => Palette::TOKYO_NIGHT_LIGHT, - Self::KanagawaWave => Palette::KANAGAWA_WAVE, - Self::KanagawaDragon => Palette::KANAGAWA_DRAGON, - Self::KanagawaLotus => Palette::KANAGAWA_LOTUS, - Self::Moonfly => Palette::MOONFLY, - Self::Nightfly => Palette::NIGHTFLY, - Self::Oxocarbon => Palette::OXOCARBON, - Self::Custom(custom) => custom.palette, - } - } - - /// Returns the [`palette::Extended`] of the [`Theme`]. - pub fn extended_palette(&self) -> &palette::Extended { - match self { - Self::Light => &palette::EXTENDED_LIGHT, - Self::Dark => &palette::EXTENDED_DARK, - Self::Dracula => &palette::EXTENDED_DRACULA, - Self::Nord => &palette::EXTENDED_NORD, - Self::SolarizedLight => &palette::EXTENDED_SOLARIZED_LIGHT, - Self::SolarizedDark => &palette::EXTENDED_SOLARIZED_DARK, - Self::GruvboxLight => &palette::EXTENDED_GRUVBOX_LIGHT, - Self::GruvboxDark => &palette::EXTENDED_GRUVBOX_DARK, - Self::CatppuccinLatte => &palette::EXTENDED_CATPPUCCIN_LATTE, - Self::CatppuccinFrappe => &palette::EXTENDED_CATPPUCCIN_FRAPPE, - Self::CatppuccinMacchiato => { - &palette::EXTENDED_CATPPUCCIN_MACCHIATO - } - Self::CatppuccinMocha => &palette::EXTENDED_CATPPUCCIN_MOCHA, - Self::TokyoNight => &palette::EXTENDED_TOKYO_NIGHT, - Self::TokyoNightStorm => &palette::EXTENDED_TOKYO_NIGHT_STORM, - Self::TokyoNightLight => &palette::EXTENDED_TOKYO_NIGHT_LIGHT, - Self::KanagawaWave => &palette::EXTENDED_KANAGAWA_WAVE, - Self::KanagawaDragon => &palette::EXTENDED_KANAGAWA_DRAGON, - Self::KanagawaLotus => &palette::EXTENDED_KANAGAWA_LOTUS, - Self::Moonfly => &palette::EXTENDED_MOONFLY, - Self::Nightfly => &palette::EXTENDED_NIGHTFLY, - Self::Oxocarbon => &palette::EXTENDED_OXOCARBON, - Self::Custom(custom) => &custom.extended, - } - } -} - -impl fmt::Display for Theme { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - Self::Light => write!(f, "Light"), - Self::Dark => write!(f, "Dark"), - Self::Dracula => write!(f, "Dracula"), - Self::Nord => write!(f, "Nord"), - Self::SolarizedLight => write!(f, "Solarized Light"), - Self::SolarizedDark => write!(f, "Solarized Dark"), - Self::GruvboxLight => write!(f, "Gruvbox Light"), - Self::GruvboxDark => write!(f, "Gruvbox Dark"), - Self::CatppuccinLatte => write!(f, "Catppuccin Latte"), - Self::CatppuccinFrappe => write!(f, "Catppuccin Frappé"), - Self::CatppuccinMacchiato => write!(f, "Catppuccin Macchiato"), - Self::CatppuccinMocha => write!(f, "Catppuccin Mocha"), - Self::TokyoNight => write!(f, "Tokyo Night"), - Self::TokyoNightStorm => write!(f, "Tokyo Night Storm"), - Self::TokyoNightLight => write!(f, "Tokyo Night Light"), - Self::KanagawaWave => write!(f, "Kanagawa Wave"), - Self::KanagawaDragon => write!(f, "Kanagawa Dragon"), - Self::KanagawaLotus => write!(f, "Kanagawa Lotus"), - Self::Moonfly => write!(f, "Moonfly"), - Self::Nightfly => write!(f, "Nightfly"), - Self::Oxocarbon => write!(f, "Oxocarbon"), - Self::Custom(custom) => custom.fmt(f), - } - } -} - -/// A [`Theme`] with a customized [`Palette`]. -#[derive(Debug, Clone, PartialEq)] -pub struct Custom { - name: String, - palette: Palette, - extended: palette::Extended, -} - -impl Custom { - /// Creates a [`Custom`] theme from the given [`Palette`]. - pub fn new(name: String, palette: Palette) -> Self { - Self::with_fn(name, palette, palette::Extended::generate) - } - - /// Creates a [`Custom`] theme from the given [`Palette`] with - /// a custom generator of a [`palette::Extended`]. - pub fn with_fn( - name: String, - palette: Palette, - generate: impl FnOnce(Palette) -> palette::Extended, - ) -> Self { - Self { - name, - palette, - extended: generate(palette), - } - } -} - -impl fmt::Display for Custom { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", self.name) - } -} diff --git a/style/src/theme/palette.rs b/style/src/theme/palette.rs deleted file mode 100644 index 15a964cd..00000000 --- a/style/src/theme/palette.rs +++ /dev/null @@ -1,625 +0,0 @@ -//! Define the colors of a theme. -use crate::core::{color, Color}; - -use once_cell::sync::Lazy; -use palette::color_difference::Wcag21RelativeContrast; -use palette::rgb::Rgb; -use palette::{FromColor, Hsl, Mix}; - -/// A color palette. -#[derive(Debug, Clone, Copy, PartialEq)] -pub struct Palette { - /// The background [`Color`] of the [`Palette`]. - pub background: Color, - /// The text [`Color`] of the [`Palette`]. - pub text: Color, - /// The primary [`Color`] of the [`Palette`]. - pub primary: Color, - /// The success [`Color`] of the [`Palette`]. - pub success: Color, - /// The danger [`Color`] of the [`Palette`]. - pub danger: Color, -} - -impl Palette { - /// The built-in light variant of a [`Palette`]. - pub const LIGHT: Self = Self { - background: Color::WHITE, - text: Color::BLACK, - primary: Color::from_rgb( - 0x5E as f32 / 255.0, - 0x7C as f32 / 255.0, - 0xE2 as f32 / 255.0, - ), - success: Color::from_rgb( - 0x12 as f32 / 255.0, - 0x66 as f32 / 255.0, - 0x4F as f32 / 255.0, - ), - danger: Color::from_rgb( - 0xC3 as f32 / 255.0, - 0x42 as f32 / 255.0, - 0x3F as f32 / 255.0, - ), - }; - - /// The built-in dark variant of a [`Palette`]. - pub const DARK: Self = Self { - background: Color::from_rgb( - 0x20 as f32 / 255.0, - 0x22 as f32 / 255.0, - 0x25 as f32 / 255.0, - ), - text: Color::from_rgb(0.90, 0.90, 0.90), - primary: Color::from_rgb( - 0x5E as f32 / 255.0, - 0x7C as f32 / 255.0, - 0xE2 as f32 / 255.0, - ), - success: Color::from_rgb( - 0x12 as f32 / 255.0, - 0x66 as f32 / 255.0, - 0x4F as f32 / 255.0, - ), - danger: Color::from_rgb( - 0xC3 as f32 / 255.0, - 0x42 as f32 / 255.0, - 0x3F as f32 / 255.0, - ), - }; - - /// The built-in [Dracula] variant of a [`Palette`]. - /// - /// [Dracula]: https://draculatheme.com - pub const DRACULA: Self = Self { - background: color!(0x282A36), // BACKGROUND - text: color!(0xf8f8f2), // FOREGROUND - primary: color!(0xbd93f9), // PURPLE - success: color!(0x50fa7b), // GREEN - danger: color!(0xff5555), // RED - }; - - /// The built-in [Nord] variant of a [`Palette`]. - /// - /// [Nord]: https://www.nordtheme.com/docs/colors-and-palettes - pub const NORD: Self = Self { - background: color!(0x2e3440), // nord0 - text: color!(0xeceff4), // nord6 - primary: color!(0x8fbcbb), // nord7 - success: color!(0xa3be8c), // nord14 - danger: color!(0xbf616a), // nord11 - }; - - /// The built-in [Solarized] Light variant of a [`Palette`]. - /// - /// [Solarized]: https://ethanschoonover.com/solarized - pub const SOLARIZED_LIGHT: Self = Self { - background: color!(0xfdf6e3), // base3 - text: color!(0x657b83), // base00 - primary: color!(0x2aa198), // cyan - success: color!(0x859900), // green - danger: color!(0xdc322f), // red - }; - - /// The built-in [Solarized] Dark variant of a [`Palette`]. - /// - /// [Solarized]: https://ethanschoonover.com/solarized - pub const SOLARIZED_DARK: Self = Self { - background: color!(0x002b36), // base03 - text: color!(0x839496), // base0 - primary: color!(0x2aa198), // cyan - success: color!(0x859900), // green - danger: color!(0xdc322f), // red - }; - - /// The built-in [Gruvbox] Light variant of a [`Palette`]. - /// - /// [Gruvbox]: https://github.com/morhetz/gruvbox - pub const GRUVBOX_LIGHT: Self = Self { - background: color!(0xfbf1c7), // light BG_0 - text: color!(0x282828), // light FG0_29 - primary: color!(0x458588), // light BLUE_4 - success: color!(0x98971a), // light GREEN_2 - danger: color!(0xcc241d), // light RED_1 - }; - - /// The built-in [Gruvbox] Dark variant of a [`Palette`]. - /// - /// [Gruvbox]: https://github.com/morhetz/gruvbox - pub const GRUVBOX_DARK: Self = Self { - background: color!(0x282828), // dark BG_0 - text: color!(0xfbf1c7), // dark FG0_29 - primary: color!(0x458588), // dark BLUE_4 - success: color!(0x98971a), // dark GREEN_2 - danger: color!(0xcc241d), // dark RED_1 - }; - - /// The built-in [Catppuccin] Latte variant of a [`Palette`]. - /// - /// [Catppuccin]: https://github.com/catppuccin/catppuccin - pub const CATPPUCCIN_LATTE: Self = Self { - background: color!(0xeff1f5), // Base - text: color!(0x4c4f69), // Text - primary: color!(0x1e66f5), // Blue - success: color!(0x40a02b), // Green - danger: color!(0xd20f39), // Red - }; - - /// The built-in [Catppuccin] Frappé variant of a [`Palette`]. - /// - /// [Catppuccin]: https://github.com/catppuccin/catppuccin - pub const CATPPUCCIN_FRAPPE: Self = Self { - background: color!(0x303446), // Base - text: color!(0xc6d0f5), // Text - primary: color!(0x8caaee), // Blue - success: color!(0xa6d189), // Green - danger: color!(0xe78284), // Red - }; - - /// The built-in [Catppuccin] Macchiato variant of a [`Palette`]. - /// - /// [Catppuccin]: https://github.com/catppuccin/catppuccin - pub const CATPPUCCIN_MACCHIATO: Self = Self { - background: color!(0x24273a), // Base - text: color!(0xcad3f5), // Text - primary: color!(0x8aadf4), // Blue - success: color!(0xa6da95), // Green - danger: color!(0xed8796), // Red - }; - - /// The built-in [Catppuccin] Mocha variant of a [`Palette`]. - /// - /// [Catppuccin]: https://github.com/catppuccin/catppuccin - pub const CATPPUCCIN_MOCHA: Self = Self { - background: color!(0x1e1e2e), // Base - text: color!(0xcdd6f4), // Text - primary: color!(0x89b4fa), // Blue - success: color!(0xa6e3a1), // Green - danger: color!(0xf38ba8), // Red - }; - - /// The built-in [Tokyo Night] variant of a [`Palette`]. - /// - /// [Tokyo Night]: https://github.com/enkia/tokyo-night-vscode-theme - pub const TOKYO_NIGHT: Self = Self { - background: color!(0x1a1b26), // Background (Night) - text: color!(0x9aa5ce), // Text - primary: color!(0x2ac3de), // Blue - success: color!(0x9ece6a), // Green - danger: color!(0xf7768e), // Red - }; - - /// The built-in [Tokyo Night] Storm variant of a [`Palette`]. - /// - /// [Tokyo Night]: https://github.com/enkia/tokyo-night-vscode-theme - pub const TOKYO_NIGHT_STORM: Self = Self { - background: color!(0x24283b), // Background (Storm) - text: color!(0x9aa5ce), // Text - primary: color!(0x2ac3de), // Blue - success: color!(0x9ece6a), // Green - danger: color!(0xf7768e), // Red - }; - - /// The built-in [Tokyo Night] Light variant of a [`Palette`]. - /// - /// [Tokyo Night]: https://github.com/enkia/tokyo-night-vscode-theme - pub const TOKYO_NIGHT_LIGHT: Self = Self { - background: color!(0xd5d6db), // Background - text: color!(0x565a6e), // Text - primary: color!(0x166775), // Blue - success: color!(0x485e30), // Green - danger: color!(0x8c4351), // Red - }; - - /// The built-in [Kanagawa] Wave variant of a [`Palette`]. - /// - /// [Kanagawa]: https://github.com/rebelot/kanagawa.nvim - pub const KANAGAWA_WAVE: Self = Self { - background: color!(0x363646), // Sumi Ink 3 - text: color!(0xCD7BA), // Fuji White - primary: color!(0x2D4F67), // Wave Blue 2 - success: color!(0x76946A), // Autumn Green - danger: color!(0xC34043), // Autumn Red - }; - - /// The built-in [Kanagawa] Dragon variant of a [`Palette`]. - /// - /// [Kanagawa]: https://github.com/rebelot/kanagawa.nvim - pub const KANAGAWA_DRAGON: Self = Self { - background: color!(0x181616), // Dragon Black 3 - text: color!(0xc5c9c5), // Dragon White - primary: color!(0x223249), // Wave Blue 1 - success: color!(0x8a9a7b), // Dragon Green 2 - danger: color!(0xc4746e), // Dragon Red - }; - - /// The built-in [Kanagawa] Lotus variant of a [`Palette`]. - /// - /// [Kanagawa]: https://github.com/rebelot/kanagawa.nvim - pub const KANAGAWA_LOTUS: Self = Self { - background: color!(0xf2ecbc), // Lotus White 3 - text: color!(0x545464), // Lotus Ink 1 - primary: color!(0xc9cbd1), // Lotus Violet 3 - success: color!(0x6f894e), // Lotus Green - danger: color!(0xc84053), // Lotus Red - }; - - /// The built-in [Moonfly] variant of a [`Palette`]. - /// - /// [Moonfly]: https://github.com/bluz71/vim-moonfly-colors - pub const MOONFLY: Self = Self { - background: color!(0x080808), // Background - text: color!(0xbdbdbd), // Foreground - primary: color!(0x80a0ff), // Blue (normal) - success: color!(0x8cc85f), // Green (normal) - danger: color!(0xff5454), // Red (normal) - }; - - /// The built-in [Nightfly] variant of a [`Palette`]. - /// - /// [Nightfly]: https://github.com/bluz71/vim-nightfly-colors - pub const NIGHTFLY: Self = Self { - background: color!(0x011627), // Background - text: color!(0xbdc1c6), // Foreground - primary: color!(0x82aaff), // Blue (normal) - success: color!(0xa1cd5e), // Green (normal) - danger: color!(0xfc514e), // Red (normal) - }; - - /// The built-in [Oxocarbon] variant of a [`Palette`]. - /// - /// [Oxocarbon]: https://github.com/nyoom-engineering/oxocarbon.nvim - pub const OXOCARBON: Self = Self { - background: color!(0x232323), - text: color!(0xd0d0d0), - primary: color!(0x00b4ff), - success: color!(0x00c15a), - danger: color!(0xf62d0f), - }; -} - -/// An extended set of colors generated from a [`Palette`]. -#[derive(Debug, Clone, Copy, PartialEq)] -pub struct Extended { - /// The set of background colors. - pub background: Background, - /// The set of primary colors. - pub primary: Primary, - /// The set of secondary colors. - pub secondary: Secondary, - /// The set of success colors. - pub success: Success, - /// The set of danger colors. - pub danger: Danger, - /// Whether the palette is dark or not. - pub is_dark: bool, -} - -/// The built-in light variant of an [`Extended`] palette. -pub static EXTENDED_LIGHT: Lazy = - Lazy::new(|| Extended::generate(Palette::LIGHT)); - -/// The built-in dark variant of an [`Extended`] palette. -pub static EXTENDED_DARK: Lazy = - Lazy::new(|| Extended::generate(Palette::DARK)); - -/// The built-in Dracula variant of an [`Extended`] palette. -pub static EXTENDED_DRACULA: Lazy = - Lazy::new(|| Extended::generate(Palette::DRACULA)); - -/// The built-in Nord variant of an [`Extended`] palette. -pub static EXTENDED_NORD: Lazy = - Lazy::new(|| Extended::generate(Palette::NORD)); - -/// The built-in Solarized Light variant of an [`Extended`] palette. -pub static EXTENDED_SOLARIZED_LIGHT: Lazy = - Lazy::new(|| Extended::generate(Palette::SOLARIZED_LIGHT)); - -/// The built-in Solarized Dark variant of an [`Extended`] palette. -pub static EXTENDED_SOLARIZED_DARK: Lazy = - Lazy::new(|| Extended::generate(Palette::SOLARIZED_DARK)); - -/// The built-in Gruvbox Light variant of an [`Extended`] palette. -pub static EXTENDED_GRUVBOX_LIGHT: Lazy = - Lazy::new(|| Extended::generate(Palette::GRUVBOX_LIGHT)); - -/// The built-in Gruvbox Dark variant of an [`Extended`] palette. -pub static EXTENDED_GRUVBOX_DARK: Lazy = - Lazy::new(|| Extended::generate(Palette::GRUVBOX_DARK)); - -/// The built-in Catppuccin Latte variant of an [`Extended`] palette. -pub static EXTENDED_CATPPUCCIN_LATTE: Lazy = - Lazy::new(|| Extended::generate(Palette::CATPPUCCIN_LATTE)); - -/// The built-in Catppuccin Frappé variant of an [`Extended`] palette. -pub static EXTENDED_CATPPUCCIN_FRAPPE: Lazy = - Lazy::new(|| Extended::generate(Palette::CATPPUCCIN_FRAPPE)); - -/// The built-in Catppuccin Macchiato variant of an [`Extended`] palette. -pub static EXTENDED_CATPPUCCIN_MACCHIATO: Lazy = - Lazy::new(|| Extended::generate(Palette::CATPPUCCIN_MACCHIATO)); - -/// The built-in Catppuccin Mocha variant of an [`Extended`] palette. -pub static EXTENDED_CATPPUCCIN_MOCHA: Lazy = - Lazy::new(|| Extended::generate(Palette::CATPPUCCIN_MOCHA)); - -/// The built-in Tokyo Night variant of an [`Extended`] palette. -pub static EXTENDED_TOKYO_NIGHT: Lazy = - Lazy::new(|| Extended::generate(Palette::TOKYO_NIGHT)); - -/// The built-in Tokyo Night Storm variant of an [`Extended`] palette. -pub static EXTENDED_TOKYO_NIGHT_STORM: Lazy = - Lazy::new(|| Extended::generate(Palette::TOKYO_NIGHT_STORM)); - -/// The built-in Tokyo Night variant of an [`Extended`] palette. -pub static EXTENDED_TOKYO_NIGHT_LIGHT: Lazy = - Lazy::new(|| Extended::generate(Palette::TOKYO_NIGHT_LIGHT)); - -/// The built-in Kanagawa Wave variant of an [`Extended`] palette. -pub static EXTENDED_KANAGAWA_WAVE: Lazy = - Lazy::new(|| Extended::generate(Palette::KANAGAWA_WAVE)); - -/// The built-in Kanagawa Dragon variant of an [`Extended`] palette. -pub static EXTENDED_KANAGAWA_DRAGON: Lazy = - Lazy::new(|| Extended::generate(Palette::KANAGAWA_DRAGON)); - -/// The built-in Kanagawa Lotus variant of an [`Extended`] palette. -pub static EXTENDED_KANAGAWA_LOTUS: Lazy = - Lazy::new(|| Extended::generate(Palette::KANAGAWA_LOTUS)); - -/// The built-in Moonfly variant of an [`Extended`] palette. -pub static EXTENDED_MOONFLY: Lazy = - Lazy::new(|| Extended::generate(Palette::MOONFLY)); - -/// The built-in Nightfly variant of an [`Extended`] palette. -pub static EXTENDED_NIGHTFLY: Lazy = - Lazy::new(|| Extended::generate(Palette::NIGHTFLY)); - -/// The built-in Oxocarbon variant of an [`Extended`] palette. -pub static EXTENDED_OXOCARBON: Lazy = - Lazy::new(|| Extended::generate(Palette::OXOCARBON)); - -impl Extended { - /// Generates an [`Extended`] palette from a simple [`Palette`]. - pub fn generate(palette: Palette) -> Self { - Self { - background: Background::new(palette.background, palette.text), - primary: Primary::generate( - palette.primary, - palette.background, - palette.text, - ), - secondary: Secondary::generate(palette.background, palette.text), - success: Success::generate( - palette.success, - palette.background, - palette.text, - ), - danger: Danger::generate( - palette.danger, - palette.background, - palette.text, - ), - is_dark: is_dark(palette.background), - } - } -} - -/// A pair of background and text colors. -#[derive(Debug, Clone, Copy, PartialEq)] -pub struct Pair { - /// The background color. - pub color: Color, - - /// The text color. - /// - /// It's guaranteed to be readable on top of the background [`color`]. - /// - /// [`color`]: Self::color - pub text: Color, -} - -impl Pair { - /// Creates a new [`Pair`] from a background [`Color`] and some text [`Color`]. - pub fn new(color: Color, text: Color) -> Self { - Self { - color, - text: readable(color, text), - } - } -} - -/// A set of background colors. -#[derive(Debug, Clone, Copy, PartialEq)] -pub struct Background { - /// The base background color. - pub base: Pair, - /// A weaker version of the base background color. - pub weak: Pair, - /// A stronger version of the base background color. - pub strong: Pair, -} - -impl Background { - /// Generates a set of [`Background`] colors from the base and text colors. - pub fn new(base: Color, text: Color) -> Self { - let weak = mix(base, text, 0.15); - let strong = mix(base, text, 0.40); - - Self { - base: Pair::new(base, text), - weak: Pair::new(weak, text), - strong: Pair::new(strong, text), - } - } -} - -/// A set of primary colors. -#[derive(Debug, Clone, Copy, PartialEq)] -pub struct Primary { - /// The base primary color. - pub base: Pair, - /// A weaker version of the base primary color. - pub weak: Pair, - /// A stronger version of the base primary color. - pub strong: Pair, -} - -impl Primary { - /// Generates a set of [`Primary`] colors from the base, background, and text colors. - pub fn generate(base: Color, background: Color, text: Color) -> Self { - let weak = mix(base, background, 0.4); - let strong = deviate(base, 0.1); - - Self { - base: Pair::new(base, text), - weak: Pair::new(weak, text), - strong: Pair::new(strong, text), - } - } -} - -/// A set of secondary colors. -#[derive(Debug, Clone, Copy, PartialEq)] -pub struct Secondary { - /// The base secondary color. - pub base: Pair, - /// A weaker version of the base secondary color. - pub weak: Pair, - /// A stronger version of the base secondary color. - pub strong: Pair, -} - -impl Secondary { - /// Generates a set of [`Secondary`] colors from the base and text colors. - pub fn generate(base: Color, text: Color) -> Self { - let base = mix(base, text, 0.2); - let weak = mix(base, text, 0.1); - let strong = mix(base, text, 0.3); - - Self { - base: Pair::new(base, text), - weak: Pair::new(weak, text), - strong: Pair::new(strong, text), - } - } -} - -/// A set of success colors. -#[derive(Debug, Clone, Copy, PartialEq)] -pub struct Success { - /// The base success color. - pub base: Pair, - /// A weaker version of the base success color. - pub weak: Pair, - /// A stronger version of the base success color. - pub strong: Pair, -} - -impl Success { - /// Generates a set of [`Success`] colors from the base, background, and text colors. - pub fn generate(base: Color, background: Color, text: Color) -> Self { - let weak = mix(base, background, 0.4); - let strong = deviate(base, 0.1); - - Self { - base: Pair::new(base, text), - weak: Pair::new(weak, text), - strong: Pair::new(strong, text), - } - } -} - -/// A set of danger colors. -#[derive(Debug, Clone, Copy, PartialEq)] -pub struct Danger { - /// The base danger color. - pub base: Pair, - /// A weaker version of the base danger color. - pub weak: Pair, - /// A stronger version of the base danger color. - pub strong: Pair, -} - -impl Danger { - /// Generates a set of [`Danger`] colors from the base, background, and text colors. - pub fn generate(base: Color, background: Color, text: Color) -> Self { - let weak = mix(base, background, 0.4); - let strong = deviate(base, 0.1); - - Self { - base: Pair::new(base, text), - weak: Pair::new(weak, text), - strong: Pair::new(strong, text), - } - } -} - -fn darken(color: Color, amount: f32) -> Color { - let mut hsl = to_hsl(color); - - hsl.lightness = if hsl.lightness - amount < 0.0 { - 0.0 - } else { - hsl.lightness - amount - }; - - from_hsl(hsl) -} - -fn lighten(color: Color, amount: f32) -> Color { - let mut hsl = to_hsl(color); - - hsl.lightness = if hsl.lightness + amount > 1.0 { - 1.0 - } else { - hsl.lightness + amount - }; - - from_hsl(hsl) -} - -fn deviate(color: Color, amount: f32) -> Color { - if is_dark(color) { - lighten(color, amount) - } else { - darken(color, amount) - } -} - -fn mix(a: Color, b: Color, factor: f32) -> Color { - let a_lin = Rgb::from(a).into_linear(); - let b_lin = Rgb::from(b).into_linear(); - - let mixed = a_lin.mix(b_lin, factor); - Rgb::from_linear(mixed).into() -} - -fn readable(background: Color, text: Color) -> Color { - if is_readable(background, text) { - text - } else if is_dark(background) { - Color::WHITE - } else { - Color::BLACK - } -} - -fn is_dark(color: Color) -> bool { - to_hsl(color).lightness < 0.6 -} - -fn is_readable(a: Color, b: Color) -> bool { - let a_srgb = Rgb::from(a); - let b_srgb = Rgb::from(b); - - a_srgb.has_enhanced_contrast_text(b_srgb) -} - -fn to_hsl(color: Color) -> Hsl { - Hsl::from_color(Rgb::from(color)) -} - -fn from_hsl(hsl: Hsl) -> Color { - Rgb::from_color(hsl).into() -} diff --git a/widget/Cargo.toml b/widget/Cargo.toml index e8e363c4..3c9ffddb 100644 --- a/widget/Cargo.toml +++ b/widget/Cargo.toml @@ -25,7 +25,6 @@ wgpu = ["iced_renderer/wgpu"] [dependencies] iced_renderer.workspace = true iced_runtime.workspace = true -iced_style.workspace = true num-traits.workspace = true thiserror.workspace = true diff --git a/widget/src/button.rs b/widget/src/button.rs index b5786baa..d0d3cb4a 100644 --- a/widget/src/button.rs +++ b/widget/src/button.rs @@ -6,21 +6,19 @@ use crate::core::layout; use crate::core::mouse; use crate::core::overlay; use crate::core::renderer; +use crate::core::theme::palette; use crate::core::touch; use crate::core::widget::tree::{self, Tree}; use crate::core::widget::Operation; use crate::core::{ Background, Border, Clipboard, Color, Element, Layout, Length, Padding, - Rectangle, Shadow, Shell, Size, Vector, Widget, + Rectangle, Shadow, Shell, Size, Theme, Vector, Widget, }; -use crate::style::theme::palette; -use crate::style::Theme; /// A generic widget that produces a message when pressed. /// /// ```no_run -/// # type Button<'a, Message> = -/// # iced_widget::Button<'a, Message, iced_widget::style::Theme, iced_widget::renderer::Renderer>; +/// # type Button<'a, Message> = iced_widget::Button<'a, Message>; /// # /// #[derive(Clone)] /// enum Message { @@ -34,8 +32,7 @@ use crate::style::Theme; /// be disabled: /// /// ``` -/// # type Button<'a, Message> = -/// # iced_widget::Button<'a, Message, iced_widget::style::Theme, iced_widget::renderer::Renderer>; +/// # type Button<'a, Message> = iced_widget::Button<'a, Message>; /// # /// #[derive(Clone)] /// enum Message { diff --git a/widget/src/checkbox.rs b/widget/src/checkbox.rs index e4fc2232..a297627b 100644 --- a/widget/src/checkbox.rs +++ b/widget/src/checkbox.rs @@ -5,23 +5,21 @@ use crate::core::layout; use crate::core::mouse; use crate::core::renderer; use crate::core::text; +use crate::core::theme::palette; use crate::core::touch; use crate::core::widget; use crate::core::widget::tree::{self, Tree}; use crate::core::{ Background, Border, Clipboard, Color, Element, Layout, Length, Pixels, - Rectangle, Shell, Size, Widget, + Rectangle, Shell, Size, Theme, Widget, }; -use crate::style::theme::palette; -use crate::style::Theme; /// A box that can be checked. /// /// # Example /// /// ```no_run -/// # type Checkbox<'a, Message> = -/// # iced_widget::Checkbox<'a, Message, iced_widget::style::Theme, iced_widget::renderer::Renderer>; +/// # type Checkbox<'a, Message> = iced_widget::Checkbox<'a, Message>; /// # /// pub enum Message { /// CheckboxToggled(bool), diff --git a/widget/src/combo_box.rs b/widget/src/combo_box.rs index 1140f1c6..62c19137 100644 --- a/widget/src/combo_box.rs +++ b/widget/src/combo_box.rs @@ -10,10 +10,9 @@ use crate::core::text; use crate::core::time::Instant; use crate::core::widget::{self, Widget}; use crate::core::{ - Clipboard, Element, Length, Padding, Rectangle, Shell, Size, Vector, + Clipboard, Element, Length, Padding, Rectangle, Shell, Size, Theme, Vector, }; use crate::overlay::menu; -use crate::style::Theme; use crate::text::LineHeight; use crate::text_input::{self, TextInput}; diff --git a/widget/src/container.rs b/widget/src/container.rs index 97b481a2..99d877fe 100644 --- a/widget/src/container.rs +++ b/widget/src/container.rs @@ -9,10 +9,9 @@ use crate::core::widget::tree::{self, Tree}; use crate::core::widget::{self, Operation}; use crate::core::{ Background, Border, Clipboard, Color, Element, Layout, Length, Padding, - Pixels, Point, Rectangle, Shadow, Shell, Size, Vector, Widget, + Pixels, Point, Rectangle, Shadow, Shell, Size, Theme, Vector, Widget, }; use crate::runtime::Command; -use crate::style::Theme; /// An element decorating some content. /// diff --git a/widget/src/lib.rs b/widget/src/lib.rs index cefafdbe..72596efc 100644 --- a/widget/src/lib.rs +++ b/widget/src/lib.rs @@ -14,7 +14,6 @@ pub use iced_renderer as renderer; pub use iced_renderer::graphics; pub use iced_runtime as runtime; pub use iced_runtime::core; -pub use iced_style as style; mod column; mod mouse_area; @@ -135,5 +134,5 @@ pub mod qr_code; #[doc(no_inline)] pub use qr_code::QRCode; +pub use crate::core::theme::{self, Theme}; pub use renderer::Renderer; -pub use style::theme::{self, Theme}; diff --git a/widget/src/overlay/menu.rs b/widget/src/overlay/menu.rs index e0887e59..2b9e0d03 100644 --- a/widget/src/overlay/menu.rs +++ b/widget/src/overlay/menu.rs @@ -11,11 +11,10 @@ use crate::core::touch; use crate::core::widget::Tree; use crate::core::{ Background, Border, Clipboard, Color, Length, Padding, Pixels, Point, - Rectangle, Size, Vector, + Rectangle, Size, Theme, Vector, }; use crate::core::{Element, Shell, Widget}; use crate::scrollable::{self, Scrollable}; -use crate::style::Theme; /// A list of selectable options. #[allow(missing_debug_implementations)] diff --git a/widget/src/pane_grid.rs b/widget/src/pane_grid.rs index ae9cd825..5403b2f5 100644 --- a/widget/src/pane_grid.rs +++ b/widget/src/pane_grid.rs @@ -40,9 +40,8 @@ use crate::core::widget; use crate::core::widget::tree::{self, Tree}; use crate::core::{ Background, Border, Clipboard, Color, Element, Layout, Length, Pixels, - Point, Rectangle, Shell, Size, Vector, Widget, + Point, Rectangle, Shell, Size, Theme, Vector, Widget, }; -use crate::style::Theme; const DRAG_DEADBAND_DISTANCE: f32 = 10.0; const THICKNESS_RATIO: f32 = 25.0; @@ -71,8 +70,7 @@ const THICKNESS_RATIO: f32 = 25.0; /// ```no_run /// # use iced_widget::{pane_grid, text}; /// # -/// # type PaneGrid<'a, Message> = -/// # iced_widget::PaneGrid<'a, Message, iced_widget::style::Theme, iced_widget::renderer::Renderer>; +/// # type PaneGrid<'a, Message> = iced_widget::PaneGrid<'a, Message>; /// # /// enum PaneState { /// SomePane, diff --git a/widget/src/pick_list.rs b/widget/src/pick_list.rs index 49daa89c..649daafe 100644 --- a/widget/src/pick_list.rs +++ b/widget/src/pick_list.rs @@ -11,10 +11,9 @@ use crate::core::touch; use crate::core::widget::tree::{self, Tree}; use crate::core::{ Background, Border, Clipboard, Color, Element, Layout, Length, Padding, - Pixels, Point, Rectangle, Shell, Size, Vector, Widget, + Pixels, Point, Rectangle, Shell, Size, Theme, Vector, Widget, }; use crate::overlay::menu::{self, Menu}; -use crate::style::Theme; use std::borrow::Borrow; diff --git a/widget/src/progress_bar.rs b/widget/src/progress_bar.rs index 62d319f4..b667b506 100644 --- a/widget/src/progress_bar.rs +++ b/widget/src/progress_bar.rs @@ -4,9 +4,8 @@ use crate::core::mouse; use crate::core::renderer; use crate::core::widget::Tree; use crate::core::{ - Background, Border, Element, Layout, Length, Rectangle, Size, Widget, + Background, Border, Element, Layout, Length, Rectangle, Size, Theme, Widget, }; -use crate::style::Theme; use std::ops::RangeInclusive; @@ -14,7 +13,7 @@ use std::ops::RangeInclusive; /// /// # Example /// ```no_run -/// # type ProgressBar = iced_widget::ProgressBar; +/// # type ProgressBar = iced_widget::ProgressBar; /// # /// let value = 50.0; /// diff --git a/widget/src/qr_code.rs b/widget/src/qr_code.rs index b94e95f6..66513775 100644 --- a/widget/src/qr_code.rs +++ b/widget/src/qr_code.rs @@ -5,10 +5,10 @@ use crate::core::mouse; use crate::core::renderer::{self, Renderer as _}; use crate::core::widget::tree::{self, Tree}; use crate::core::{ - Color, Element, Layout, Length, Point, Rectangle, Size, Vector, Widget, + Color, Element, Layout, Length, Point, Rectangle, Size, Theme, Vector, + Widget, }; use crate::graphics::geometry::Renderer as _; -use crate::style::Theme; use crate::Renderer; use std::cell::RefCell; diff --git a/widget/src/radio.rs b/widget/src/radio.rs index 83d17f01..556d8ac9 100644 --- a/widget/src/radio.rs +++ b/widget/src/radio.rs @@ -10,16 +10,15 @@ use crate::core::widget; use crate::core::widget::tree::{self, Tree}; use crate::core::{ Background, Border, Clipboard, Color, Element, Layout, Length, Pixels, - Rectangle, Shell, Size, Widget, + Rectangle, Shell, Size, Theme, Widget, }; -use crate::style::Theme; /// A circular button representing a choice. /// /// # Example /// ```no_run /// # type Radio = -/// # iced_widget::Radio; +/// # iced_widget::Radio; /// # /// # use iced_widget::column; /// #[derive(Debug, Clone, Copy, PartialEq, Eq)] diff --git a/widget/src/rule.rs b/widget/src/rule.rs index 53a077aa..19ad43f6 100644 --- a/widget/src/rule.rs +++ b/widget/src/rule.rs @@ -5,9 +5,8 @@ use crate::core::mouse; use crate::core::renderer; use crate::core::widget::Tree; use crate::core::{ - Color, Element, Layout, Length, Pixels, Rectangle, Size, Widget, + Color, Element, Layout, Length, Pixels, Rectangle, Size, Theme, Widget, }; -use crate::style::Theme; /// Display a horizontal or vertical rule for dividing content. #[allow(missing_debug_implementations)] diff --git a/widget/src/scrollable.rs b/widget/src/scrollable.rs index 19a80ee2..861f1bfb 100644 --- a/widget/src/scrollable.rs +++ b/widget/src/scrollable.rs @@ -13,10 +13,9 @@ use crate::core::widget::operation::{self, Operation}; use crate::core::widget::tree::{self, Tree}; use crate::core::{ Background, Border, Clipboard, Color, Element, Layout, Length, Pixels, - Point, Rectangle, Shell, Size, Vector, Widget, + Point, Rectangle, Shell, Size, Theme, Vector, Widget, }; use crate::runtime::Command; -use crate::style::Theme; pub use operation::scrollable::{AbsoluteOffset, RelativeOffset}; diff --git a/widget/src/slider.rs b/widget/src/slider.rs index c48fe143..463a4f04 100644 --- a/widget/src/slider.rs +++ b/widget/src/slider.rs @@ -12,9 +12,8 @@ use crate::core::touch; use crate::core::widget::tree::{self, Tree}; use crate::core::{ Border, Clipboard, Color, Element, Layout, Length, Pixels, Point, - Rectangle, Shell, Size, Widget, + Rectangle, Shell, Size, Theme, Widget, }; -use crate::style::Theme; use std::ops::RangeInclusive; @@ -28,8 +27,7 @@ use std::ops::RangeInclusive; /// /// # Example /// ```no_run -/// # type Slider<'a, T, Message> = -/// # iced_widget::Slider<'a, Message, T, iced_widget::style::Theme>; +/// # type Slider<'a, T, Message> = iced_widget::Slider<'a, Message, T>; /// # /// #[derive(Clone)] /// pub enum Message { diff --git a/widget/src/svg.rs b/widget/src/svg.rs index c80fa6b1..34fd9a7b 100644 --- a/widget/src/svg.rs +++ b/widget/src/svg.rs @@ -5,9 +5,9 @@ use crate::core::renderer; use crate::core::svg; use crate::core::widget::Tree; use crate::core::{ - Color, ContentFit, Element, Layout, Length, Rectangle, Size, Vector, Widget, + Color, ContentFit, Element, Layout, Length, Rectangle, Size, Theme, Vector, + Widget, }; -use crate::style::Theme; use std::path::PathBuf; diff --git a/widget/src/text_editor.rs b/widget/src/text_editor.rs index 73b006fa..fabcb744 100644 --- a/widget/src/text_editor.rs +++ b/widget/src/text_editor.rs @@ -12,9 +12,8 @@ use crate::core::text::{self, LineHeight}; use crate::core::widget::{self, Widget}; use crate::core::{ Background, Border, Color, Element, Length, Padding, Pixels, Rectangle, - Shell, Size, Vector, + Shell, Size, Theme, Vector, }; -use crate::style::Theme; use std::cell::RefCell; use std::fmt; diff --git a/widget/src/text_input.rs b/widget/src/text_input.rs index bae84db7..6bad0afe 100644 --- a/widget/src/text_input.rs +++ b/widget/src/text_input.rs @@ -28,17 +28,15 @@ use crate::core::widget::tree::{self, Tree}; use crate::core::window; use crate::core::{ Background, Border, Color, Element, Layout, Length, Padding, Pixels, Point, - Rectangle, Shell, Size, Vector, Widget, + Rectangle, Shell, Size, Theme, Vector, Widget, }; use crate::runtime::Command; -use crate::style::Theme; /// A field that can be filled with text. /// /// # Example /// ```no_run -/// # pub type TextInput<'a, Message> = -/// # iced_widget::TextInput<'a, Message, iced_widget::style::Theme, iced_widget::renderer::Renderer>; +/// # pub type TextInput<'a, Message> = iced_widget::TextInput<'a, Message>; /// # /// #[derive(Debug, Clone)] /// enum Message { diff --git a/widget/src/toggler.rs b/widget/src/toggler.rs index cecd7b6c..adc82f73 100644 --- a/widget/src/toggler.rs +++ b/widget/src/toggler.rs @@ -10,17 +10,15 @@ use crate::core::widget; use crate::core::widget::tree::{self, Tree}; use crate::core::{ Border, Clipboard, Color, Element, Event, Layout, Length, Pixels, - Rectangle, Shell, Size, Widget, + Rectangle, Shell, Size, Theme, Widget, }; -use crate::style::Theme; /// A toggler widget. /// /// # Example /// /// ```no_run -/// # type Toggler<'a, Message> = -/// # iced_widget::Toggler<'a, Message, iced_widget::style::Theme, iced_widget::renderer::Renderer>; +/// # type Toggler<'a, Message> = iced_widget::Toggler<'a, Message>; /// # /// pub enum Message { /// TogglerToggled(bool), diff --git a/widget/src/vertical_slider.rs b/widget/src/vertical_slider.rs index 47c400c7..721a59fb 100644 --- a/widget/src/vertical_slider.rs +++ b/widget/src/vertical_slider.rs @@ -31,8 +31,7 @@ use crate::core::{ /// /// # Example /// ```no_run -/// # type VerticalSlider<'a, T, Message> = -/// # iced_widget::VerticalSlider<'a, T, Message, iced_widget::style::Theme>; +/// # type VerticalSlider<'a, T, Message> = iced_widget::VerticalSlider<'a, T, Message>; /// # /// #[derive(Clone)] /// pub enum Message { diff --git a/winit/Cargo.toml b/winit/Cargo.toml index 87e600ae..9d65cc1b 100644 --- a/winit/Cargo.toml +++ b/winit/Cargo.toml @@ -24,7 +24,6 @@ multi-window = ["iced_runtime/multi-window"] [dependencies] iced_graphics.workspace = true iced_runtime.workspace = true -iced_style.workspace = true log.workspace = true thiserror.workspace = true diff --git a/winit/src/application.rs b/winit/src/application.rs index fbca6ee4..d2a61580 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -10,7 +10,7 @@ use crate::core::renderer; use crate::core::time::Instant; use crate::core::widget::operation; use crate::core::window; -use crate::core::{Color, Event, Point, Size}; +use crate::core::{Color, Event, Point, Size, Theme}; use crate::futures::futures; use crate::futures::{Executor, Runtime, Subscription}; use crate::graphics::compositor::{self, Compositor}; @@ -18,7 +18,6 @@ use crate::runtime::clipboard; use crate::runtime::program::Program; use crate::runtime::user_interface::{self, UserInterface}; use crate::runtime::{Command, Debug}; -use crate::style::Theme; use crate::{Clipboard, Error, Proxy, Settings}; use futures::channel::mpsc; diff --git a/winit/src/lib.rs b/winit/src/lib.rs index 3b1b0d3a..64912b3f 100644 --- a/winit/src/lib.rs +++ b/winit/src/lib.rs @@ -30,7 +30,6 @@ pub use iced_graphics as graphics; pub use iced_runtime as runtime; pub use iced_runtime::core; pub use iced_runtime::futures; -pub use iced_style as style; pub use winit; #[cfg(feature = "multi-window")] -- cgit