From b079297b5edcd2f7197b9930bdedb25cdc3f083d Mon Sep 17 00:00:00 2001 From: Yeastplume Date: Wed, 13 Mar 2024 13:56:28 +0000 Subject: [PATCH] update header crates for iced-rs 0.12.1 --- Cargo.lock | 13 - Cargo.toml | 1 - crates/core/Cargo.toml | 4 - crates/core/src/lib.rs | 12 +- crates/core/src/style/header.rs | 58 + crates/{widgets => core}/src/style/mod.rs | 0 crates/core/src/style/table_row.rs | 134 +++ crates/core/src/theme/button.rs | 282 +++-- crates/core/src/theme/card.rs | 38 +- crates/core/src/theme/checkbox.rs | 65 +- crates/core/src/theme/container.rs | 171 +-- crates/core/src/theme/header.rs | 36 - crates/core/src/theme/mod.rs | 1060 ++++++++--------- crates/core/src/theme/modal.rs | 30 +- crates/core/src/theme/picklist.rs | 126 +- crates/core/src/theme/scrollable.rs | 90 +- crates/core/src/theme/table_row.rs | 112 -- crates/core/src/theme/text_input.rs | 166 +-- crates/{widgets => core}/src/widget/header.rs | 18 +- crates/core/src/widget/header/state.rs | 11 + crates/{widgets => core}/src/widget/mod.rs | 0 .../{widgets => core}/src/widget/table_row.rs | 0 crates/widgets/Cargo.toml | 21 - crates/widgets/src/lib.rs | 9 - crates/widgets/src/style/header.rs | 25 - crates/widgets/src/style/table_row.rs | 24 - crates/widgets/src/widget/header/state.rs | 11 - 27 files changed, 1244 insertions(+), 1273 deletions(-) create mode 100644 crates/core/src/style/header.rs rename crates/{widgets => core}/src/style/mod.rs (100%) create mode 100644 crates/core/src/style/table_row.rs delete mode 100644 crates/core/src/theme/header.rs delete mode 100644 crates/core/src/theme/table_row.rs rename crates/{widgets => core}/src/widget/header.rs (95%) create mode 100644 crates/core/src/widget/header/state.rs rename crates/{widgets => core}/src/widget/mod.rs (100%) rename crates/{widgets => core}/src/widget/table_row.rs (100%) delete mode 100644 crates/widgets/Cargo.toml delete mode 100644 crates/widgets/src/lib.rs delete mode 100644 crates/widgets/src/style/header.rs delete mode 100644 crates/widgets/src/style/table_row.rs delete mode 100644 crates/widgets/src/widget/header/state.rs diff --git a/Cargo.lock b/Cargo.lock index 008615e..dfc47a7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2798,7 +2798,6 @@ dependencies = [ "futures 0.3.30", "fuzzy-matcher", "grin-gui-core", - "grin-gui-widgets", "iced 0.10.0", "iced_aw 0.6.0", "iced_core 0.10.0", @@ -2848,7 +2847,6 @@ dependencies = [ "flate2", "futures 0.3.30", "glob", - "grin-gui-widgets", "grin_chain", "grin_config", "grin_core", @@ -2892,17 +2890,6 @@ dependencies = [ "zstd", ] -[[package]] -name = "grin-gui-widgets" -version = "0.1.0-alpha.6" -dependencies = [ - "iced 0.12.1", - "iced_core 0.12.3", - "iced_graphics 0.12.1", - "iced_style 0.12.1", - "iced_wgpu 0.12.1", -] - [[package]] name = "grin_api" version = "5.3.0-alpha.1" diff --git a/Cargo.toml b/Cargo.toml index 5934778..266bf25 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,6 @@ debug = ["iced/debug"] [dependencies] grin-gui-core = { version = "0.1.0-alpha.6", path = "crates/core", features = ["wgpu"]} -grin-gui-widgets = { version = "0.1.0-alpha.6", path = "crates/widgets" } iced = { version = "0.10", features = ["canvas", "tokio"] } iced_futures = { version = "0.7", features = ["async-std"] } diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index ffe7f68..4e79570 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -35,8 +35,6 @@ grin_servers = { git = "https://github.com/mimblewimble/grin", branch = "master" grin_keychain = { git = "https://github.com/mimblewimble/grin", branch = "master"} grin_chain = { git = "https://github.com/mimblewimble/grin", branch = "master"} - - ### Wallet grin_wallet = { git = "https://github.com/mimblewimble/grin-wallet", branch = "contracts" } grin_wallet_config = { git = "https://github.com/mimblewimble/grin-wallet", branch = "contracts" } @@ -46,7 +44,6 @@ grin_wallet_api = { git = "https://github.com/mimblewimble/grin-wallet", branch grin_wallet_impls = { git = "https://github.com/mimblewimble/grin-wallet", branch = "contracts" } grin_wallet_libwallet = { git = "https://github.com/mimblewimble/grin-wallet", branch = "contracts" } - ############ Local testing ################ ### Node # grin_config = { path = "../../../grin/config" } @@ -65,7 +62,6 @@ grin_wallet_libwallet = { git = "https://github.com/mimblewimble/grin-wallet", b #grin_wallet_impls = { path = "../../../grin-wallet/impls"} #grin_wallet_libwallet = { path = "../../../grin-wallet/libwallet"} -grin-gui-widgets = { path = "../widgets" } regex = "1.4.3" fancy-regex = "0.5.0" # Regex with backtracking async-std = { version = "1.9.0", features = ["unstable"] } diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index bbddbc0..fc743ad 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -4,15 +4,17 @@ pub mod backup; pub mod config; -pub mod wallet; -pub mod logger; -pub mod node; pub mod error; pub mod fs; -pub mod theme; +pub mod logger; pub mod network; +pub mod node; +pub mod style; +pub mod theme; #[cfg(feature = "wgpu")] pub mod utility; +pub mod wallet; +pub mod widget; #[macro_use] extern crate lazy_static; @@ -21,5 +23,5 @@ extern crate lazy_static; extern crate log; // Re-exports -pub use grin_util::logger::{LoggingConfig, LogEntry}; pub use grin_core::consensus::GRIN_BASE; +pub use grin_util::logger::{LogEntry, LoggingConfig}; diff --git a/crates/core/src/style/header.rs b/crates/core/src/style/header.rs new file mode 100644 index 0000000..2ca4500 --- /dev/null +++ b/crates/core/src/style/header.rs @@ -0,0 +1,58 @@ +use iced::Theme; +use iced_core::{Background, Color}; + +/// The appearance of a header. +#[derive(Debug, Clone, Copy)] +pub struct Appearance { + pub text_color: Option, + pub background: Option, + pub border_radius: f32, + pub border_width: f32, + pub border_color: Color, + pub offset_left: f32, + pub offset_right: f32, +} + +/// A set of rules that dictate the style of a header. +pub trait StyleSheet { + type Style: std::default::Default + Copy; + + /// Produces the style of a header. + fn appearance(&self, style: &Self::Style) -> Appearance; + + /// Produces the a hovered appearance for header. + fn hovered(&self, style: &Self::Style) -> Appearance; +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] +pub enum HeaderStyle { + #[default] + Default, +} + +impl StyleSheet for Theme { + type Style = HeaderStyle; + + fn appearance(&self, style: &Self::Style) -> Appearance { + match style { + HeaderStyle::Default => Appearance { + //text_color: Some(self.palette.bright.surface), + text_color: None, + background: Some(Background::Color(self.palette().primary)), + border_radius: 0.0, + border_width: 0.0, + border_color: Color::TRANSPARENT, + offset_right: 0.0, + offset_left: 0.0, + }, + } + } + + fn hovered(&self, style: &Self::Style) -> Appearance { + let appearance = self.appearance(style); + Appearance { + background: None, + ..appearance + } + } +} diff --git a/crates/widgets/src/style/mod.rs b/crates/core/src/style/mod.rs similarity index 100% rename from crates/widgets/src/style/mod.rs rename to crates/core/src/style/mod.rs diff --git a/crates/core/src/style/table_row.rs b/crates/core/src/style/table_row.rs new file mode 100644 index 0000000..9acec48 --- /dev/null +++ b/crates/core/src/style/table_row.rs @@ -0,0 +1,134 @@ +use iced::Theme; +use iced::{Background, Color}; + +/// The appearance of a table row. +#[derive(Debug, Clone, Copy, Default)] +pub struct Appearance { + pub text_color: Option, + pub background: Option, + pub border_radius: f32, + pub border_width: f32, + pub border_color: Color, + pub offset_left: f32, + pub offset_right: f32, +} + +/// A set of rules that dictate the style of a table row. +pub trait StyleSheet { + type Style: std::default::Default + Copy; + + /// Produces the default appearance of a table row. + fn appearance(&self, style: &Self::Style) -> Appearance; + + /// Produces the hovered appearance table row. + fn hovered(&self, style: &Self::Style) -> Appearance; +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] +pub enum TableRowStyle { + #[default] + Default, + TableRowAlternate, + TableRowHighlife, + TableRowLowlife, + TableRowSelected, +} + +impl StyleSheet for Theme { + type Style = TableRowStyle; + + fn appearance(&self, style: &Self::Style) -> Appearance { + match style { + TableRowStyle::Default => Appearance { + text_color: Some(self.palette().primary), + background: Some(Background::Color(self.palette().primary)), + border_radius: 0.0, + border_width: 0.0, + border_color: Color::TRANSPARENT, + // offset_left: 10.0, + // offset_right: 25.0, + offset_left: 0.0, + offset_right: 0.0, + }, + TableRowStyle::TableRowAlternate => Appearance { + background: Some(Background::Color(Color { + a: 0.50, + ..self.palette().primary + })), + ..Appearance::default() + }, + TableRowStyle::TableRowHighlife => Appearance { + text_color: Some(self.palette().primary), + background: Some(Background::Color(Color { + a: 0.30, + ..self.palette().primary + })), + border_radius: 0.0, + border_width: 0.0, + border_color: Color::TRANSPARENT, + offset_left: 0.0, + offset_right: 0.0, + }, + TableRowStyle::TableRowLowlife => Appearance { + text_color: Some(self.palette().primary), + background: Some(Background::Color(Color::TRANSPARENT)), + border_radius: 0.0, + border_width: 0.0, + border_color: Color::TRANSPARENT, + offset_left: 0.0, + offset_right: 0.0, + }, + TableRowStyle::TableRowSelected => Appearance { + text_color: Some(self.palette().primary), + background: Some(Background::Color(self.palette().primary)), + border_radius: 0.0, + border_width: 0.0, + border_color: Color::TRANSPARENT, + offset_left: 0.0, + offset_right: 0.0, + }, + } + } + + fn hovered(&self, style: &Self::Style) -> Appearance { + let appearance = self.appearance(style); + + match style { + TableRowStyle::Default => Appearance { + background: Some(Background::Color(Color { + a: 0.60, + ..self.palette().primary + })), + ..appearance + }, + TableRowStyle::TableRowAlternate => Appearance { + background: Some(Background::Color(Color { + a: 0.25, + ..self.palette().primary + })), + ..appearance + }, + TableRowStyle::TableRowHighlife => Appearance { + background: Some(Background::Color(Color { + a: 0.60, + ..self.palette().primary + })), + ..appearance + }, + TableRowStyle::TableRowLowlife => Appearance { + background: Some(Background::Color(Color { + a: 0.60, + ..self.palette().primary + })), + ..appearance + }, + TableRowStyle::TableRowSelected => Appearance { + background: Some(Background::Color(Color { + a: 0.60, + ..self.palette().primary + })), + ..appearance + }, + } + } +} diff --git a/crates/core/src/theme/button.rs b/crates/core/src/theme/button.rs index ce665f2..96cbb1e 100644 --- a/crates/core/src/theme/button.rs +++ b/crates/core/src/theme/button.rs @@ -1,144 +1,164 @@ use iced::widget::button; -use iced::{Color, Background}; +use iced::{Background, Color}; +use iced_core::Border; use super::Theme; #[derive(Debug, Clone, Copy, Default)] pub enum ButtonStyle { - #[default] - Default, - Bordered, - ColumnHeader, - Primary, - Selected, - SelectedColumn, - NormalText, + #[default] + Default, + Bordered, + ColumnHeader, + Primary, + Selected, + SelectedColumn, + NormalText, } impl button::StyleSheet for Theme { - type Style = ButtonStyle; + type Style = ButtonStyle; - fn active(&self, style: &Self::Style) -> button::Appearance { - match style { - ButtonStyle::Default => button::Appearance::default(), - ButtonStyle::Bordered => button::Appearance { - border_color: Color { - a: 0.5, - ..self.palette.normal.primary - }, - border_width: 1.0, - border_radius: 2.0.into(), - text_color: self.palette.bright.primary, - ..button::Appearance::default() - }, - ButtonStyle::Primary => button::Appearance { - text_color: self.palette.bright.primary, - border_radius: 2.0.into(), - ..Default::default() - }, - ButtonStyle::Selected => button::Appearance { - background: Some(Background::Color(self.palette.normal.primary)), - text_color: self.palette.bright.primary, - border_radius: 2.0.into(), - ..button::Appearance::default() - }, - ButtonStyle::NormalText => button::Appearance { - text_color: self.palette.normal.surface, - border_radius: 2.0.into(), - ..button::Appearance::default() - }, - ButtonStyle::SelectedColumn => button::Appearance { - background: Some(Background::Color(self.palette.base.background)), - text_color: Color { - ..self.palette.bright.primary - }, - border_radius: 2.0.into(), - ..button::Appearance::default() - }, - ButtonStyle::ColumnHeader => button::Appearance { - background: Some(Background::Color(self.palette.base.background)), - text_color: Color { - ..self.palette.bright.surface - }, - border_radius: 2.0.into(), - ..button::Appearance::default() - }, - } - } + fn active(&self, style: &Self::Style) -> button::Appearance { + match style { + ButtonStyle::Default => button::Appearance::default(), + ButtonStyle::Bordered => button::Appearance { + border: Border { + color: self.palette.normal.primary, + width: 1.0, + radius: 2.0.into(), + }, + text_color: self.palette.bright.primary, + ..button::Appearance::default() + }, + ButtonStyle::Primary => button::Appearance { + text_color: self.palette.bright.primary, + border: Border { + color: self.palette.normal.primary, + width: 1.0, + radius: 2.0.into(), + }, + ..Default::default() + }, + ButtonStyle::Selected => button::Appearance { + background: Some(Background::Color(self.palette.normal.primary)), + text_color: self.palette.bright.primary, + border: Border { + color: self.palette.normal.primary, + width: 1.0, + radius: 2.0.into(), + }, + ..button::Appearance::default() + }, + ButtonStyle::NormalText => button::Appearance { + text_color: self.palette.normal.surface, + border: Border { + color: self.palette.normal.primary, + width: 1.0, + radius: 2.0.into(), + }, + ..button::Appearance::default() + }, + ButtonStyle::SelectedColumn => button::Appearance { + background: Some(Background::Color(self.palette.base.background)), + text_color: Color { + ..self.palette.bright.primary + }, + border: Border { + color: self.palette.normal.primary, + width: 1.0, + radius: 2.0.into(), + }, + ..button::Appearance::default() + }, + ButtonStyle::ColumnHeader => button::Appearance { + background: Some(Background::Color(self.palette.base.background)), + border: Border { + color: self.palette.normal.primary, + width: 1.0, + radius: 2.0.into(), + }, + text_color: Color { + ..self.palette.bright.surface + }, + ..button::Appearance::default() + }, + } + } - fn hovered(&self, style: &Self::Style) -> button::Appearance { - match style { - ButtonStyle::Default => button::Appearance::default(), - ButtonStyle::Bordered => button::Appearance { - background: Some(Background::Color(Color { - a: 0.25, - ..self.palette.normal.primary - })), - text_color: self.palette.bright.primary, - ..self.active(style) - }, - ButtonStyle::Primary => button::Appearance { - background: Some(Background::Color(Color { - a: 0.25, - ..self.palette.normal.primary - })), - text_color: self.palette.bright.primary, - ..self.active(style) - }, - ButtonStyle::Selected => button::Appearance { - background: Some(Background::Color(self.palette.normal.primary)), - text_color: self.palette.bright.primary, - ..self.active(style) - }, - ButtonStyle::NormalText => button::Appearance { - background: Some(Background::Color(Color::TRANSPARENT)), - text_color: self.palette.bright.primary, - ..self.active(style) - }, - ButtonStyle::SelectedColumn => button::Appearance { - background: Some(Background::Color(Color { - a: 0.25, - ..self.palette.normal.primary - })), - text_color: self.palette.bright.primary, - ..self.active(style) - }, - ButtonStyle::ColumnHeader => button::Appearance { - background: Some(Background::Color(Color { - a: 0.15, - ..self.palette.normal.primary - })), - text_color: self.palette.bright.primary, - ..self.active(style) - }, - } - } + fn hovered(&self, style: &Self::Style) -> button::Appearance { + match style { + ButtonStyle::Default => button::Appearance::default(), + ButtonStyle::Bordered => button::Appearance { + background: Some(Background::Color(Color { + a: 0.25, + ..self.palette.normal.primary + })), + text_color: self.palette.bright.primary, + ..self.active(style) + }, + ButtonStyle::Primary => button::Appearance { + background: Some(Background::Color(Color { + a: 0.25, + ..self.palette.normal.primary + })), + text_color: self.palette.bright.primary, + ..self.active(style) + }, + ButtonStyle::Selected => button::Appearance { + background: Some(Background::Color(self.palette.normal.primary)), + text_color: self.palette.bright.primary, + ..self.active(style) + }, + ButtonStyle::NormalText => button::Appearance { + background: Some(Background::Color(Color::TRANSPARENT)), + text_color: self.palette.bright.primary, + ..self.active(style) + }, + ButtonStyle::SelectedColumn => button::Appearance { + background: Some(Background::Color(Color { + a: 0.25, + ..self.palette.normal.primary + })), + text_color: self.palette.bright.primary, + ..self.active(style) + }, + ButtonStyle::ColumnHeader => button::Appearance { + background: Some(Background::Color(Color { + a: 0.15, + ..self.palette.normal.primary + })), + text_color: self.palette.bright.primary, + ..self.active(style) + }, + } + } - fn disabled(&self, style: &Self::Style) -> button::Appearance { - match style { - ButtonStyle::Default => button::Appearance::default(), - ButtonStyle::Bordered => button::Appearance { - background: Some(Background::Color(Color { - a: 0.05, - ..self.palette.normal.primary - })), - text_color: Color { - a: 0.50, - ..self.palette.normal.primary - }, - ..self.active(style) - }, - ButtonStyle::Primary => button::Appearance { - text_color: Color { - a: 0.25, - ..self.palette.normal.surface - }, - ..self.active(style) - }, - ButtonStyle::Selected => button::Appearance { - ..self.active(style) - }, - _ => self.disabled(style), - } - } + fn disabled(&self, style: &Self::Style) -> button::Appearance { + match style { + ButtonStyle::Default => button::Appearance::default(), + ButtonStyle::Bordered => button::Appearance { + background: Some(Background::Color(Color { + a: 0.05, + ..self.palette.normal.primary + })), + text_color: Color { + a: 0.50, + ..self.palette.normal.primary + }, + ..self.active(style) + }, + ButtonStyle::Primary => button::Appearance { + text_color: Color { + a: 0.25, + ..self.palette.normal.surface + }, + ..self.active(style) + }, + ButtonStyle::Selected => button::Appearance { + ..self.active(style) + }, + _ => self.disabled(style), + } + } } diff --git a/crates/core/src/theme/card.rs b/crates/core/src/theme/card.rs index 616ab12..19274cd 100644 --- a/crates/core/src/theme/card.rs +++ b/crates/core/src/theme/card.rs @@ -6,27 +6,27 @@ use super::Theme; #[derive(Debug, Clone, Copy, Default)] pub enum CardStyle { - #[default] - Default, - Normal, + #[default] + Default, + Normal, } impl card::StyleSheet for Theme { - type Style = CardStyle; + type Style = CardStyle; - fn active(&self, style: Self::Style) -> Appearance { - match style { - CardStyle::Default => iced_aw::style::card::Appearance::default(), - CardStyle::Normal => Appearance { - background: Background::Color(self.palette.base.background), - head_background: Background::Color(self.palette.normal.primary), - head_text_color: self.palette.bright.surface, - border_color: self.palette.normal.primary, - body_text_color: self.palette.normal.surface, - border_radius: 3.0, - border_width: 0.5, - ..card::Appearance::default() - }, - } - } + fn active(&self, style: &Self::Style) -> Appearance { + match style { + CardStyle::Default => iced_aw::style::card::Appearance::default(), + CardStyle::Normal => Appearance { + background: Background::Color(self.palette.base.background), + head_background: Background::Color(self.palette.normal.primary), + head_text_color: self.palette.bright.surface, + border_color: self.palette.normal.primary, + body_text_color: self.palette.normal.surface, + border_radius: 3.0, + border_width: 0.5, + ..card::Appearance::default() + }, + } + } } diff --git a/crates/core/src/theme/checkbox.rs b/crates/core/src/theme/checkbox.rs index 17726b7..9beb83d 100644 --- a/crates/core/src/theme/checkbox.rs +++ b/crates/core/src/theme/checkbox.rs @@ -1,42 +1,47 @@ use super::Theme; use iced::widget::checkbox; use iced::Background; +use iced_core::Border; #[derive(Debug, Clone, Copy, Default)] pub enum CheckboxStyle { - #[default] - Default, - Normal, + #[default] + Default, + Normal, } impl checkbox::StyleSheet for Theme { - type Style = CheckboxStyle; + type Style = CheckboxStyle; - fn active(&self, style: &Self::Style, is_checked: bool) -> checkbox::Appearance { - match style { - CheckboxStyle::Normal => checkbox::Appearance { - background: Background::Color(self.palette.base.background), - icon_color: self.palette.bright.primary, - border_radius: 2.0.into(), - border_width: 1.0, - border_color: self.palette.normal.primary, - text_color: Some(self.palette.normal.surface), - }, - _ => todo!("default"), - } - } + fn active(&self, style: &Self::Style, is_checked: bool) -> checkbox::Appearance { + match style { + CheckboxStyle::Normal => checkbox::Appearance { + background: Background::Color(self.palette.base.background), + icon_color: self.palette.bright.primary, + border: Border { + color: self.palette.normal.primary, + width: 1.0, + radius: 2.0.into(), + }, + text_color: Some(self.palette.normal.surface), + }, + _ => todo!("default"), + } + } - fn hovered(&self, style: &Self::Style, is_checked: bool) -> checkbox::Appearance { - match style { - CheckboxStyle::Normal => checkbox::Appearance { - background: Background::Color(self.palette.base.foreground), - icon_color: self.palette.bright.primary, - border_radius: 2.0.into(), - border_width: 2.0, - border_color: self.palette.bright.primary, - text_color: Some(self.palette.normal.surface), - }, - _ => todo!("default"), - } - } + fn hovered(&self, style: &Self::Style, is_checked: bool) -> checkbox::Appearance { + match style { + CheckboxStyle::Normal => checkbox::Appearance { + background: Background::Color(self.palette.base.foreground), + icon_color: self.palette.bright.primary, + border: Border { + color: self.palette.normal.primary, + width: 1.0, + radius: 2.0.into(), + }, + text_color: Some(self.palette.normal.surface), + }, + _ => todo!("default"), + } + } } diff --git a/crates/core/src/theme/container.rs b/crates/core/src/theme/container.rs index fc7918e..a3c3ee6 100644 --- a/crates/core/src/theme/container.rs +++ b/crates/core/src/theme/container.rs @@ -1,90 +1,101 @@ +use super::Theme; use iced::widget::container; use iced::{Background, Color}; -use super::Theme; +use iced_core::{Border, Shadow, Vector}; #[derive(Debug, Clone, Copy, Default)] pub enum ContainerStyle { - #[default] - Default, - BrightForeground, - BrightBackground, - ErrorForeground, - NormalBackground, - HoverableForeground, - HoverableBrightForeground, - SuccessBackground, - Segmented, - PanelBordered, - PanelForeground, + #[default] + Default, + BrightForeground, + BrightBackground, + ErrorForeground, + NormalBackground, + HoverableForeground, + HoverableBrightForeground, + SuccessBackground, + Segmented, + PanelBordered, + PanelForeground, } impl container::StyleSheet for Theme { - type Style = ContainerStyle; + type Style = ContainerStyle; - fn appearance(&self, style: &Self::Style) -> container::Appearance { - match style { - ContainerStyle::Default => container::Appearance::default(), - ContainerStyle::BrightBackground => container::Appearance { - background: Some(Background::Color(self.palette.base.background)), - text_color: Some(self.palette.bright.surface), - ..container::Appearance::default() - }, - ContainerStyle::BrightForeground => container::Appearance { - background: Some(Background::Color(self.palette.base.foreground)), - text_color: Some(self.palette.bright.surface), - ..container::Appearance::default() - }, - ContainerStyle::ErrorForeground => container::Appearance { - background: Some(Background::Color(self.palette.base.foreground)), - text_color: Some(self.palette.normal.surface), - ..container::Appearance::default() - }, - ContainerStyle::NormalBackground => container::Appearance { - background: Some(Background::Color(self.palette.base.background)), - text_color: Some(self.palette.normal.surface), - ..container::Appearance::default() - }, - ContainerStyle::Segmented => container::Appearance { - border_radius: 2.0.into(), - border_width: 1.0, - border_color: Color { - a: 0.5, - ..self.palette.normal.primary - }, - ..container::Appearance::default() - }, - ContainerStyle::HoverableForeground => container::Appearance { - background: None, - text_color: Some(self.palette.normal.surface), - ..container::Appearance::default() - }, - ContainerStyle::HoverableBrightForeground => container::Appearance { - background: None, - text_color: Some(self.palette.bright.primary), - ..container::Appearance::default() - }, - ContainerStyle::SuccessBackground => container::Appearance { - background: Some(Background::Color(self.palette.base.foreground)), - text_color: Some(self.palette.normal.surface), - ..container::Appearance::default() - }, - ContainerStyle::PanelForeground => container::Appearance { - background: Some(Background::Color(self.palette.base.foreground)), - text_color: Some(self.palette.bright.primary), - border_radius: 2.0.into(), - border_width: 0.0, - border_color: Color::TRANSPARENT, - }, - ContainerStyle::PanelBordered => container::Appearance { - background: Some(Background::Color(Color::TRANSPARENT)), - text_color: Some(self.palette.bright.primary), - border_radius: 2.0.into(), - border_width: 1.0, - border_color: Color { - a: 0.5, - ..self.palette.normal.primary - }, - }, - } - } + fn appearance(&self, style: &Self::Style) -> container::Appearance { + match style { + ContainerStyle::Default => container::Appearance::default(), + ContainerStyle::BrightBackground => container::Appearance { + background: Some(Background::Color(self.palette.base.background)), + text_color: Some(self.palette.bright.surface), + ..container::Appearance::default() + }, + ContainerStyle::BrightForeground => container::Appearance { + background: Some(Background::Color(self.palette.base.foreground)), + text_color: Some(self.palette.bright.surface), + ..container::Appearance::default() + }, + ContainerStyle::ErrorForeground => container::Appearance { + background: Some(Background::Color(self.palette.base.foreground)), + text_color: Some(self.palette.normal.surface), + ..container::Appearance::default() + }, + ContainerStyle::NormalBackground => container::Appearance { + background: Some(Background::Color(self.palette.base.background)), + text_color: Some(self.palette.normal.surface), + ..container::Appearance::default() + }, + ContainerStyle::Segmented => container::Appearance { + border: Border { + color: self.palette.normal.primary, + width: 1.0, + radius: 2.0.into(), + }, + ..container::Appearance::default() + }, + ContainerStyle::HoverableForeground => container::Appearance { + background: None, + text_color: Some(self.palette.normal.surface), + ..container::Appearance::default() + }, + ContainerStyle::HoverableBrightForeground => container::Appearance { + background: None, + text_color: Some(self.palette.bright.primary), + ..container::Appearance::default() + }, + ContainerStyle::SuccessBackground => container::Appearance { + background: Some(Background::Color(self.palette.base.foreground)), + text_color: Some(self.palette.normal.surface), + ..container::Appearance::default() + }, + ContainerStyle::PanelForeground => container::Appearance { + background: Some(Background::Color(self.palette.base.foreground)), + text_color: Some(self.palette.bright.primary), + border: Border { + color: self.palette.normal.primary, + width: 1.0, + radius: 2.0.into(), + }, + shadow: Shadow { + offset: Vector::new(0.0, 1.0), + blur_radius: 1.0, + color: Color::TRANSPARENT, + }, + }, + ContainerStyle::PanelBordered => container::Appearance { + background: Some(Background::Color(Color::TRANSPARENT)), + text_color: Some(self.palette.bright.primary), + border: Border { + color: self.palette.normal.primary, + width: 1.0, + radius: 2.0.into(), + }, + shadow: Shadow { + offset: Vector::new(0.0, 1.0), + blur_radius: 1.0, + color: Color::TRANSPARENT, + }, + }, + } + } } diff --git a/crates/core/src/theme/header.rs b/crates/core/src/theme/header.rs deleted file mode 100644 index 03ece76..0000000 --- a/crates/core/src/theme/header.rs +++ /dev/null @@ -1,36 +0,0 @@ -use super::Theme; -use grin_gui_widgets::style::header::{Appearance, StyleSheet}; -use iced::{Color, Background}; - -#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] -pub enum HeaderStyle { - #[default] - Default, -} - -impl StyleSheet for Theme { - type Style = HeaderStyle; - - fn appearance(&self, style: &Self::Style) -> Appearance { - match style { - HeaderStyle::Default => Appearance { - //text_color: Some(self.palette.bright.surface), - text_color: None, - background: Some(Background::Color(self.palette.base.foreground)), - border_radius: 0.0, - border_width: 0.0, - border_color: Color::TRANSPARENT, - offset_right: 0.0, - offset_left: 0.0, - }, - } - } - - fn hovered(&self, style: &Self::Style) -> Appearance { - let appearance = self.appearance(style); - Appearance { - background: None, - ..appearance - } - } -} diff --git a/crates/core/src/theme/mod.rs b/crates/core/src/theme/mod.rs index 9340434..bfc4956 100644 --- a/crates/core/src/theme/mod.rs +++ b/crates/core/src/theme/mod.rs @@ -8,7 +8,7 @@ use iced_renderer::Renderer as IRenderer; #[cfg(feature = "opengl")] use iced_glow::Renderer as IRenderer; -// TODO +// TODO // finish carryover from original stylesheet here: https://github.com/ajour/ajour/blob/master/src/gui/style.rs pub mod application; pub mod button; @@ -16,13 +16,11 @@ pub mod card; pub mod checkbox; pub mod container; pub mod modal; -pub mod header; pub mod picklist; pub mod radio; pub mod scrollable; pub mod text; pub mod text_input; -pub mod table_row; pub use button::ButtonStyle; pub use card::CardStyle; @@ -33,23 +31,20 @@ pub use picklist::PickListStyle; pub use radio::RadioStyle; pub use scrollable::ScrollableStyle; pub use text_input::TextInputStyle; -pub use table_row::TableRowStyle; -pub use header::HeaderStyle; pub async fn load_user_themes() -> Vec { - log::debug!("loading user themes"); + log::debug!("loading user themes"); - fs::load_user_themes().await + fs::load_user_themes().await } #[derive(Debug, Clone, Default, Deserialize, Serialize)] pub struct Theme { - - pub name: String, - pub palette: ColorPalette, + pub name: String, + pub palette: ColorPalette, } -pub type Renderer = IRenderer; +pub type Renderer = IRenderer; pub type Element<'a, Message> = iced::Element<'a, Message, Renderer>; pub type Container<'a, Message> = iced::widget::Container<'a, Message, Renderer>; pub type Column<'a, Message> = iced::widget::Column<'a, Message, Renderer>; @@ -58,575 +53,574 @@ pub type Text<'a> = iced::widget::Text<'a, Renderer>; pub type TextInput<'a, Message> = iced::widget::TextInput<'a, Message, Renderer>; pub type Button<'a, Message> = iced::widget::Button<'a, Message, Renderer>; pub type Scrollable<'a, Message> = iced::widget::Scrollable<'a, Message, Renderer>; -pub type PickList<'a, T, Message> = iced::widget::PickList<'a, T, Message, Renderer>; +pub type PickList<'a, T, Message> = iced::widget::PickList<'a, T, Message, Theme, Renderer>; pub type Radio = iced::widget::Radio; -pub type Card<'a, Message> = iced_aw::native::Card<'a, Message, Renderer>; +pub type Card<'a, Message> = iced_aw::native::Card<'a, Message, Theme, Renderer>; pub type Modal<'a, Content, Message> = iced_aw::modal::Modal<'a, Content, Message>; -pub type Header<'a, Message> = grin_gui_widgets::widget::header::Header<'a, Message, Renderer>; -pub type TableRow<'a, Message> = grin_gui_widgets::widget::table_row::TableRow<'a, Message, Renderer>; - +pub type Header<'a, Message> = crate::widget::header::Header<'a, Message, Theme, Renderer>; +pub type TableRow<'a, Message> = crate::widget::table_row::TableRow<'a, Message, Theme, Renderer>; #[derive(Debug, Clone, Copy, Default, Deserialize, Serialize)] pub struct BaseColors { - #[serde(with = "serde_color")] - pub background: iced::Color, - #[serde(with = "serde_color")] - pub foreground: iced::Color, + #[serde(with = "serde_color")] + pub background: iced::Color, + #[serde(with = "serde_color")] + pub foreground: iced::Color, } #[derive(Debug, Clone, Copy, Default, Deserialize, Serialize)] pub struct NormalColors { - #[serde(with = "serde_color")] - pub primary: iced::Color, - #[serde(with = "serde_color")] - pub secondary: iced::Color, - #[serde(with = "serde_color")] - pub surface: iced::Color, - #[serde(with = "serde_color")] - pub error: iced::Color, + #[serde(with = "serde_color")] + pub primary: iced::Color, + #[serde(with = "serde_color")] + pub secondary: iced::Color, + #[serde(with = "serde_color")] + pub surface: iced::Color, + #[serde(with = "serde_color")] + pub error: iced::Color, } #[derive(Debug, Clone, Copy, Default, Deserialize, Serialize)] pub struct BrightColors { - #[serde(with = "serde_color")] - pub primary: iced::Color, - #[serde(with = "serde_color")] - pub secondary: iced::Color, - #[serde(with = "serde_color")] - pub surface: iced::Color, - #[serde(with = "serde_color")] - pub error: iced::Color, + #[serde(with = "serde_color")] + pub primary: iced::Color, + #[serde(with = "serde_color")] + pub secondary: iced::Color, + #[serde(with = "serde_color")] + pub surface: iced::Color, + #[serde(with = "serde_color")] + pub error: iced::Color, } #[derive(Debug, Clone, Copy, Default, Deserialize, Serialize)] pub struct ColorPalette { - pub base: BaseColors, - pub normal: NormalColors, - pub bright: BrightColors, + pub base: BaseColors, + pub normal: NormalColors, + pub bright: BrightColors, } impl Theme { - pub fn all() -> Vec<(String, Theme)> { - vec![ - ("Alliance".to_string(), Theme::alliance()), - ("Ayu".to_string(), Theme::ayu()), - ("Dark".to_string(), Theme::dark()), - ("Dracula".to_string(), Theme::dracula()), - ("Ferra".to_string(), Theme::ferra()), - ("Forest Night".to_string(), Theme::forest_night()), - ("Gruvbox".to_string(), Theme::gruvbox()), - ("Horde".to_string(), Theme::horde()), - ("Light".to_string(), Theme::light()), - ("Nord".to_string(), Theme::nord()), - ("One Dark".to_string(), Theme::one_dark()), - ("Outrun".to_string(), Theme::outrun()), - ("Solarized Dark".to_string(), Theme::solarized_dark()), - ("Solarized Light".to_string(), Theme::solarized_light()), - ("Sort".to_string(), Theme::sort()), - ] - } - - pub fn dark() -> Theme { - Theme { - name: "Dark".to_string(), - palette: ColorPalette { - base: BaseColors { - background: hex_to_color("#111111").unwrap(), - foreground: hex_to_color("#1C1C1C").unwrap(), - }, - normal: NormalColors { - primary: hex_to_color("#3f2b56").unwrap(), - secondary: hex_to_color("#4a3c1c").unwrap(), - surface: hex_to_color("#828282").unwrap(), - error: hex_to_color("#992B2B").unwrap(), - }, - bright: BrightColors { - primary: hex_to_color("#BA84FC").unwrap(), - secondary: hex_to_color("#ffd03c").unwrap(), - surface: hex_to_color("#E0E0E0").unwrap(), - error: hex_to_color("#C13047").unwrap(), - }, - }, - } - } - - pub fn light() -> Theme { - Theme { - name: "Light".to_string(), - palette: ColorPalette { - base: BaseColors { - background: hex_to_color("#ffffff").unwrap(), - foreground: hex_to_color("#F5F5F5").unwrap(), - }, - normal: NormalColors { - primary: hex_to_color("#DFDBFF").unwrap(), - secondary: hex_to_color("#F9D659").unwrap(), - surface: hex_to_color("#828282").unwrap(), - error: hex_to_color("#992B2B").unwrap(), - }, - bright: BrightColors { - primary: hex_to_color("#9580ff").unwrap(), - secondary: hex_to_color("#EAA326").unwrap(), - surface: hex_to_color("#000000").unwrap(), - error: hex_to_color("#C13047").unwrap(), - }, - }, - } - } - - pub fn alliance() -> Theme { - Theme { - name: "Alliance".to_string(), - palette: ColorPalette { - base: BaseColors { - background: hex_to_color("#011930").unwrap(), - foreground: hex_to_color("#022242").unwrap(), - }, - normal: NormalColors { - primary: hex_to_color("#3e3523").unwrap(), - secondary: hex_to_color("#3e3523").unwrap(), - surface: hex_to_color("#7F8387").unwrap(), - error: hex_to_color("#5b3a5e").unwrap(), - }, - bright: BrightColors { - primary: hex_to_color("#ac8a1b").unwrap(), - secondary: hex_to_color("#ac8a1b").unwrap(), - surface: hex_to_color("#B4B9BF").unwrap(), - error: hex_to_color("#953e43").unwrap(), - }, - }, - } - } - - pub fn horde() -> Theme { - Theme { - name: "Horde".to_string(), - palette: ColorPalette { - base: BaseColors { - background: hex_to_color("#161313").unwrap(), - foreground: hex_to_color("#211C1C").unwrap(), - }, - normal: NormalColors { - primary: hex_to_color("#331E1F").unwrap(), - secondary: hex_to_color("#542A18").unwrap(), - surface: hex_to_color("#5E5B5A").unwrap(), - error: hex_to_color("#44282a").unwrap(), - }, - bright: BrightColors { - primary: hex_to_color("#953e43").unwrap(), - secondary: hex_to_color("#e27342").unwrap(), - surface: hex_to_color("#9B9897").unwrap(), - error: hex_to_color("#953e43").unwrap(), - }, - }, - } - } - - pub fn ayu() -> Theme { - Theme { - name: "Ayu".to_string(), - palette: ColorPalette { - base: BaseColors { - background: hex_to_color("#1f2430").unwrap(), - foreground: hex_to_color("#232834").unwrap(), - }, - normal: NormalColors { - primary: hex_to_color("#987a47").unwrap(), - secondary: hex_to_color("#315e6b").unwrap(), - surface: hex_to_color("#60697a").unwrap(), - error: hex_to_color("#712a34").unwrap(), - }, - bright: BrightColors { - primary: hex_to_color("#ffcc66").unwrap(), - secondary: hex_to_color("#5ccfe6").unwrap(), - surface: hex_to_color("#cbccc6").unwrap(), - error: hex_to_color("#ff3333").unwrap(), - }, - }, - } - } - - pub fn dracula() -> Theme { - Theme { - name: "Dracula".to_string(), - palette: ColorPalette { - base: BaseColors { - background: hex_to_color("#282a36").unwrap(), - foreground: hex_to_color("#353746").unwrap(), - }, - normal: NormalColors { - primary: hex_to_color("#483e61").unwrap(), - secondary: hex_to_color("#386e50").unwrap(), - surface: hex_to_color("#a2a4a3").unwrap(), - error: hex_to_color("#A13034").unwrap(), - }, - bright: BrightColors { - primary: hex_to_color("#bd94f9").unwrap(), - secondary: hex_to_color("#49eb7a").unwrap(), - surface: hex_to_color("#f4f8f3").unwrap(), - error: hex_to_color("#ff7ac6").unwrap(), - }, - }, - } - } - - pub fn forest_night() -> Theme { - Theme { - name: "Forest Night".to_string(), - palette: ColorPalette { - base: BaseColors { - background: hex_to_color("#323d43").unwrap(), - foreground: hex_to_color("#3c474d").unwrap(), - }, - normal: NormalColors { - primary: hex_to_color("#505a60").unwrap(), - secondary: hex_to_color("#465258").unwrap(), - surface: hex_to_color("#999f93").unwrap(), - error: hex_to_color("#74484c").unwrap(), - }, - bright: BrightColors { - primary: hex_to_color("#a7c080").unwrap(), - secondary: hex_to_color("#83b6af").unwrap(), - surface: hex_to_color("#d8caac").unwrap(), - error: hex_to_color("#e68183").unwrap(), - }, - }, - } - } - - pub fn gruvbox() -> Theme { - Theme { - name: "Gruvbox".to_string(), - palette: ColorPalette { - base: BaseColors { - background: hex_to_color("#282828").unwrap(), - foreground: hex_to_color("#3c3836").unwrap(), - }, - normal: NormalColors { - primary: hex_to_color("#63612f").unwrap(), - secondary: hex_to_color("#695133").unwrap(), - surface: hex_to_color("#928374").unwrap(), - error: hex_to_color("#81302e").unwrap(), - }, - bright: BrightColors { - primary: hex_to_color("#98971a").unwrap(), - secondary: hex_to_color("#d79921").unwrap(), - surface: hex_to_color("#ebdbb2").unwrap(), - error: hex_to_color("#cc241d").unwrap(), - }, - }, - } - } - - pub fn nord() -> Theme { - Theme { - name: "Nord".to_string(), - palette: ColorPalette { - base: BaseColors { - background: hex_to_color("#2e3440").unwrap(), - foreground: hex_to_color("#3b4252").unwrap(), - }, - normal: NormalColors { - primary: hex_to_color("#485b60").unwrap(), - secondary: hex_to_color("#425066").unwrap(), - surface: hex_to_color("#9196a1").unwrap(), - error: hex_to_color("#894f5a").unwrap(), - }, - bright: BrightColors { - primary: hex_to_color("#8fbcbb").unwrap(), - secondary: hex_to_color("#5e81ac").unwrap(), - surface: hex_to_color("#eceff4").unwrap(), - error: hex_to_color("#bf616a").unwrap(), - }, - }, - } - } - - pub fn outrun() -> Theme { - Theme { - name: "Outrun".to_string(), - palette: ColorPalette { - base: BaseColors { - background: hex_to_color("#0d0821").unwrap(), - foreground: hex_to_color("#110A2B").unwrap(), - }, - normal: NormalColors { - primary: hex_to_color("#330442").unwrap(), - secondary: hex_to_color("#6e3e2e").unwrap(), - surface: hex_to_color("#484e81").unwrap(), - error: hex_to_color("#671a30").unwrap(), - }, - bright: BrightColors { - primary: hex_to_color("#ff00ff").unwrap(), - secondary: hex_to_color("#ff963a").unwrap(), - surface: hex_to_color("#757dc8").unwrap(), - error: hex_to_color("#db2c3e").unwrap(), - }, - }, - } - } - - pub fn solarized_dark() -> Theme { - Theme { - name: "Solarized Dark".to_string(), - palette: ColorPalette { - base: BaseColors { - background: hex_to_color("#012b36").unwrap(), - foreground: hex_to_color("#093642").unwrap(), - }, - normal: NormalColors { - primary: hex_to_color("#1A615B").unwrap(), - secondary: hex_to_color("#523F09").unwrap(), - surface: hex_to_color("#63797e").unwrap(), - error: hex_to_color("#b80f15").unwrap(), - }, - bright: BrightColors { - primary: hex_to_color("#2aa096").unwrap(), - secondary: hex_to_color("#a37f12").unwrap(), - surface: hex_to_color("#93a1a1").unwrap(), - error: hex_to_color("#EE2F36").unwrap(), - }, - }, - } - } - - pub fn solarized_light() -> Theme { - Theme { - name: "Solarized Light".to_string(), - palette: ColorPalette { - base: BaseColors { - background: hex_to_color("#fdf6e3").unwrap(), - foreground: hex_to_color("#eee8d5").unwrap(), - }, - normal: NormalColors { - primary: hex_to_color("#BCCCC3").unwrap(), - secondary: hex_to_color("#ccbd9e").unwrap(), - surface: hex_to_color("#95a3a2").unwrap(), - error: hex_to_color("#b80f15").unwrap(), - }, - bright: BrightColors { - primary: hex_to_color("#2aa096").unwrap(), - secondary: hex_to_color("#a37f12").unwrap(), - surface: hex_to_color("#4C5D63").unwrap(), - error: hex_to_color("#EE2F36").unwrap(), - }, - }, - } - } - - pub fn sort() -> Theme { - Theme { - name: "Sort".to_string(), - palette: ColorPalette { - base: BaseColors { - background: hex_to_color("#000000").unwrap(), - foreground: hex_to_color("#101010").unwrap(), - }, - normal: NormalColors { - primary: hex_to_color("#525252").unwrap(), - secondary: hex_to_color("#525252").unwrap(), - surface: hex_to_color("#525252").unwrap(), - error: hex_to_color("#525252").unwrap(), - }, - bright: BrightColors { - primary: hex_to_color("#A3A3A3").unwrap(), - secondary: hex_to_color("#A3A3A3").unwrap(), - surface: hex_to_color("#A3A3A3").unwrap(), - error: hex_to_color("#A3A3A3").unwrap(), - }, - }, - } - } - - pub fn ferra() -> Theme { - Theme { - name: "Ferra".to_string(), - palette: ColorPalette { - base: BaseColors { - background: hex_to_color("#211f22").unwrap(), - foreground: hex_to_color("#2b292d").unwrap(), - }, - normal: NormalColors { - primary: hex_to_color("#664A50").unwrap(), - secondary: hex_to_color("#855859").unwrap(), - surface: hex_to_color("#816961").unwrap(), - error: hex_to_color("#713f47").unwrap(), - }, - bright: BrightColors { - primary: hex_to_color("#b4838d").unwrap(), - secondary: hex_to_color("#e5989b").unwrap(), - surface: hex_to_color("#fecdb2").unwrap(), - error: hex_to_color("#e06b75").unwrap(), - }, - }, - } - } - - pub fn one_dark() -> Theme { - Theme { - name: "One Dark".to_string(), - palette: ColorPalette { - base: BaseColors { - background: hex_to_color("#282c34").unwrap(), - foreground: hex_to_color("#2c323c").unwrap(), - }, - normal: NormalColors { - primary: hex_to_color("#385c7c").unwrap(), - secondary: hex_to_color("#654473").unwrap(), - surface: hex_to_color("#5b626e").unwrap(), - error: hex_to_color("#713f47").unwrap(), - }, - bright: BrightColors { - primary: hex_to_color("#61afef").unwrap(), - secondary: hex_to_color("#c679dd").unwrap(), - surface: hex_to_color("#a6adba").unwrap(), - error: hex_to_color("#e06b75").unwrap(), - }, - }, - } - } + pub fn all() -> Vec<(String, Theme)> { + vec![ + ("Alliance".to_string(), Theme::alliance()), + ("Ayu".to_string(), Theme::ayu()), + ("Dark".to_string(), Theme::dark()), + ("Dracula".to_string(), Theme::dracula()), + ("Ferra".to_string(), Theme::ferra()), + ("Forest Night".to_string(), Theme::forest_night()), + ("Gruvbox".to_string(), Theme::gruvbox()), + ("Horde".to_string(), Theme::horde()), + ("Light".to_string(), Theme::light()), + ("Nord".to_string(), Theme::nord()), + ("One Dark".to_string(), Theme::one_dark()), + ("Outrun".to_string(), Theme::outrun()), + ("Solarized Dark".to_string(), Theme::solarized_dark()), + ("Solarized Light".to_string(), Theme::solarized_light()), + ("Sort".to_string(), Theme::sort()), + ] + } + + pub fn dark() -> Theme { + Theme { + name: "Dark".to_string(), + palette: ColorPalette { + base: BaseColors { + background: hex_to_color("#111111").unwrap(), + foreground: hex_to_color("#1C1C1C").unwrap(), + }, + normal: NormalColors { + primary: hex_to_color("#3f2b56").unwrap(), + secondary: hex_to_color("#4a3c1c").unwrap(), + surface: hex_to_color("#828282").unwrap(), + error: hex_to_color("#992B2B").unwrap(), + }, + bright: BrightColors { + primary: hex_to_color("#BA84FC").unwrap(), + secondary: hex_to_color("#ffd03c").unwrap(), + surface: hex_to_color("#E0E0E0").unwrap(), + error: hex_to_color("#C13047").unwrap(), + }, + }, + } + } + + pub fn light() -> Theme { + Theme { + name: "Light".to_string(), + palette: ColorPalette { + base: BaseColors { + background: hex_to_color("#ffffff").unwrap(), + foreground: hex_to_color("#F5F5F5").unwrap(), + }, + normal: NormalColors { + primary: hex_to_color("#DFDBFF").unwrap(), + secondary: hex_to_color("#F9D659").unwrap(), + surface: hex_to_color("#828282").unwrap(), + error: hex_to_color("#992B2B").unwrap(), + }, + bright: BrightColors { + primary: hex_to_color("#9580ff").unwrap(), + secondary: hex_to_color("#EAA326").unwrap(), + surface: hex_to_color("#000000").unwrap(), + error: hex_to_color("#C13047").unwrap(), + }, + }, + } + } + + pub fn alliance() -> Theme { + Theme { + name: "Alliance".to_string(), + palette: ColorPalette { + base: BaseColors { + background: hex_to_color("#011930").unwrap(), + foreground: hex_to_color("#022242").unwrap(), + }, + normal: NormalColors { + primary: hex_to_color("#3e3523").unwrap(), + secondary: hex_to_color("#3e3523").unwrap(), + surface: hex_to_color("#7F8387").unwrap(), + error: hex_to_color("#5b3a5e").unwrap(), + }, + bright: BrightColors { + primary: hex_to_color("#ac8a1b").unwrap(), + secondary: hex_to_color("#ac8a1b").unwrap(), + surface: hex_to_color("#B4B9BF").unwrap(), + error: hex_to_color("#953e43").unwrap(), + }, + }, + } + } + + pub fn horde() -> Theme { + Theme { + name: "Horde".to_string(), + palette: ColorPalette { + base: BaseColors { + background: hex_to_color("#161313").unwrap(), + foreground: hex_to_color("#211C1C").unwrap(), + }, + normal: NormalColors { + primary: hex_to_color("#331E1F").unwrap(), + secondary: hex_to_color("#542A18").unwrap(), + surface: hex_to_color("#5E5B5A").unwrap(), + error: hex_to_color("#44282a").unwrap(), + }, + bright: BrightColors { + primary: hex_to_color("#953e43").unwrap(), + secondary: hex_to_color("#e27342").unwrap(), + surface: hex_to_color("#9B9897").unwrap(), + error: hex_to_color("#953e43").unwrap(), + }, + }, + } + } + + pub fn ayu() -> Theme { + Theme { + name: "Ayu".to_string(), + palette: ColorPalette { + base: BaseColors { + background: hex_to_color("#1f2430").unwrap(), + foreground: hex_to_color("#232834").unwrap(), + }, + normal: NormalColors { + primary: hex_to_color("#987a47").unwrap(), + secondary: hex_to_color("#315e6b").unwrap(), + surface: hex_to_color("#60697a").unwrap(), + error: hex_to_color("#712a34").unwrap(), + }, + bright: BrightColors { + primary: hex_to_color("#ffcc66").unwrap(), + secondary: hex_to_color("#5ccfe6").unwrap(), + surface: hex_to_color("#cbccc6").unwrap(), + error: hex_to_color("#ff3333").unwrap(), + }, + }, + } + } + + pub fn dracula() -> Theme { + Theme { + name: "Dracula".to_string(), + palette: ColorPalette { + base: BaseColors { + background: hex_to_color("#282a36").unwrap(), + foreground: hex_to_color("#353746").unwrap(), + }, + normal: NormalColors { + primary: hex_to_color("#483e61").unwrap(), + secondary: hex_to_color("#386e50").unwrap(), + surface: hex_to_color("#a2a4a3").unwrap(), + error: hex_to_color("#A13034").unwrap(), + }, + bright: BrightColors { + primary: hex_to_color("#bd94f9").unwrap(), + secondary: hex_to_color("#49eb7a").unwrap(), + surface: hex_to_color("#f4f8f3").unwrap(), + error: hex_to_color("#ff7ac6").unwrap(), + }, + }, + } + } + + pub fn forest_night() -> Theme { + Theme { + name: "Forest Night".to_string(), + palette: ColorPalette { + base: BaseColors { + background: hex_to_color("#323d43").unwrap(), + foreground: hex_to_color("#3c474d").unwrap(), + }, + normal: NormalColors { + primary: hex_to_color("#505a60").unwrap(), + secondary: hex_to_color("#465258").unwrap(), + surface: hex_to_color("#999f93").unwrap(), + error: hex_to_color("#74484c").unwrap(), + }, + bright: BrightColors { + primary: hex_to_color("#a7c080").unwrap(), + secondary: hex_to_color("#83b6af").unwrap(), + surface: hex_to_color("#d8caac").unwrap(), + error: hex_to_color("#e68183").unwrap(), + }, + }, + } + } + + pub fn gruvbox() -> Theme { + Theme { + name: "Gruvbox".to_string(), + palette: ColorPalette { + base: BaseColors { + background: hex_to_color("#282828").unwrap(), + foreground: hex_to_color("#3c3836").unwrap(), + }, + normal: NormalColors { + primary: hex_to_color("#63612f").unwrap(), + secondary: hex_to_color("#695133").unwrap(), + surface: hex_to_color("#928374").unwrap(), + error: hex_to_color("#81302e").unwrap(), + }, + bright: BrightColors { + primary: hex_to_color("#98971a").unwrap(), + secondary: hex_to_color("#d79921").unwrap(), + surface: hex_to_color("#ebdbb2").unwrap(), + error: hex_to_color("#cc241d").unwrap(), + }, + }, + } + } + + pub fn nord() -> Theme { + Theme { + name: "Nord".to_string(), + palette: ColorPalette { + base: BaseColors { + background: hex_to_color("#2e3440").unwrap(), + foreground: hex_to_color("#3b4252").unwrap(), + }, + normal: NormalColors { + primary: hex_to_color("#485b60").unwrap(), + secondary: hex_to_color("#425066").unwrap(), + surface: hex_to_color("#9196a1").unwrap(), + error: hex_to_color("#894f5a").unwrap(), + }, + bright: BrightColors { + primary: hex_to_color("#8fbcbb").unwrap(), + secondary: hex_to_color("#5e81ac").unwrap(), + surface: hex_to_color("#eceff4").unwrap(), + error: hex_to_color("#bf616a").unwrap(), + }, + }, + } + } + + pub fn outrun() -> Theme { + Theme { + name: "Outrun".to_string(), + palette: ColorPalette { + base: BaseColors { + background: hex_to_color("#0d0821").unwrap(), + foreground: hex_to_color("#110A2B").unwrap(), + }, + normal: NormalColors { + primary: hex_to_color("#330442").unwrap(), + secondary: hex_to_color("#6e3e2e").unwrap(), + surface: hex_to_color("#484e81").unwrap(), + error: hex_to_color("#671a30").unwrap(), + }, + bright: BrightColors { + primary: hex_to_color("#ff00ff").unwrap(), + secondary: hex_to_color("#ff963a").unwrap(), + surface: hex_to_color("#757dc8").unwrap(), + error: hex_to_color("#db2c3e").unwrap(), + }, + }, + } + } + + pub fn solarized_dark() -> Theme { + Theme { + name: "Solarized Dark".to_string(), + palette: ColorPalette { + base: BaseColors { + background: hex_to_color("#012b36").unwrap(), + foreground: hex_to_color("#093642").unwrap(), + }, + normal: NormalColors { + primary: hex_to_color("#1A615B").unwrap(), + secondary: hex_to_color("#523F09").unwrap(), + surface: hex_to_color("#63797e").unwrap(), + error: hex_to_color("#b80f15").unwrap(), + }, + bright: BrightColors { + primary: hex_to_color("#2aa096").unwrap(), + secondary: hex_to_color("#a37f12").unwrap(), + surface: hex_to_color("#93a1a1").unwrap(), + error: hex_to_color("#EE2F36").unwrap(), + }, + }, + } + } + + pub fn solarized_light() -> Theme { + Theme { + name: "Solarized Light".to_string(), + palette: ColorPalette { + base: BaseColors { + background: hex_to_color("#fdf6e3").unwrap(), + foreground: hex_to_color("#eee8d5").unwrap(), + }, + normal: NormalColors { + primary: hex_to_color("#BCCCC3").unwrap(), + secondary: hex_to_color("#ccbd9e").unwrap(), + surface: hex_to_color("#95a3a2").unwrap(), + error: hex_to_color("#b80f15").unwrap(), + }, + bright: BrightColors { + primary: hex_to_color("#2aa096").unwrap(), + secondary: hex_to_color("#a37f12").unwrap(), + surface: hex_to_color("#4C5D63").unwrap(), + error: hex_to_color("#EE2F36").unwrap(), + }, + }, + } + } + + pub fn sort() -> Theme { + Theme { + name: "Sort".to_string(), + palette: ColorPalette { + base: BaseColors { + background: hex_to_color("#000000").unwrap(), + foreground: hex_to_color("#101010").unwrap(), + }, + normal: NormalColors { + primary: hex_to_color("#525252").unwrap(), + secondary: hex_to_color("#525252").unwrap(), + surface: hex_to_color("#525252").unwrap(), + error: hex_to_color("#525252").unwrap(), + }, + bright: BrightColors { + primary: hex_to_color("#A3A3A3").unwrap(), + secondary: hex_to_color("#A3A3A3").unwrap(), + surface: hex_to_color("#A3A3A3").unwrap(), + error: hex_to_color("#A3A3A3").unwrap(), + }, + }, + } + } + + pub fn ferra() -> Theme { + Theme { + name: "Ferra".to_string(), + palette: ColorPalette { + base: BaseColors { + background: hex_to_color("#211f22").unwrap(), + foreground: hex_to_color("#2b292d").unwrap(), + }, + normal: NormalColors { + primary: hex_to_color("#664A50").unwrap(), + secondary: hex_to_color("#855859").unwrap(), + surface: hex_to_color("#816961").unwrap(), + error: hex_to_color("#713f47").unwrap(), + }, + bright: BrightColors { + primary: hex_to_color("#b4838d").unwrap(), + secondary: hex_to_color("#e5989b").unwrap(), + surface: hex_to_color("#fecdb2").unwrap(), + error: hex_to_color("#e06b75").unwrap(), + }, + }, + } + } + + pub fn one_dark() -> Theme { + Theme { + name: "One Dark".to_string(), + palette: ColorPalette { + base: BaseColors { + background: hex_to_color("#282c34").unwrap(), + foreground: hex_to_color("#2c323c").unwrap(), + }, + normal: NormalColors { + primary: hex_to_color("#385c7c").unwrap(), + secondary: hex_to_color("#654473").unwrap(), + surface: hex_to_color("#5b626e").unwrap(), + error: hex_to_color("#713f47").unwrap(), + }, + bright: BrightColors { + primary: hex_to_color("#61afef").unwrap(), + secondary: hex_to_color("#c679dd").unwrap(), + surface: hex_to_color("#a6adba").unwrap(), + error: hex_to_color("#e06b75").unwrap(), + }, + }, + } + } } fn hex_to_color(hex: &str) -> Option { - if hex.len() == 7 { - let hash = &hex[0..1]; - let r = u8::from_str_radix(&hex[1..3], 16); - let g = u8::from_str_radix(&hex[3..5], 16); - let b = u8::from_str_radix(&hex[5..7], 16); - - return match (hash, r, g, b) { - ("#", Ok(r), Ok(g), Ok(b)) => Some(iced::Color { - r: r as f32 / 255.0, - g: g as f32 / 255.0, - b: b as f32 / 255.0, - a: 1.0, - }), - _ => None, - }; - } - - None + if hex.len() == 7 { + let hash = &hex[0..1]; + let r = u8::from_str_radix(&hex[1..3], 16); + let g = u8::from_str_radix(&hex[3..5], 16); + let b = u8::from_str_radix(&hex[5..7], 16); + + return match (hash, r, g, b) { + ("#", Ok(r), Ok(g), Ok(b)) => Some(iced::Color { + r: r as f32 / 255.0, + g: g as f32 / 255.0, + b: b as f32 / 255.0, + a: 1.0, + }), + _ => None, + }; + } + + None } fn color_to_hex(color: &iced::Color) -> String { - let mut color_str = String::from("#"); + let mut color_str = String::from("#"); - let iced::Color { r, g, b, .. } = color; - color_str.push_str(&format!("{:02X}", (r * 255.0) as u8)); - color_str.push_str(&format!("{:02X}", (g * 255.0) as u8)); - color_str.push_str(&format!("{:02X}", (b * 255.0) as u8)); + let iced::Color { r, g, b, .. } = color; + color_str.push_str(&format!("{:02X}", (r * 255.0) as u8)); + color_str.push_str(&format!("{:02X}", (g * 255.0) as u8)); + color_str.push_str(&format!("{:02X}", (b * 255.0) as u8)); - color_str + color_str } impl PartialEq for Theme { - fn eq(&self, other: &Self) -> bool { - self.name == other.name - } + fn eq(&self, other: &Self) -> bool { + self.name == other.name + } } impl PartialOrd for Theme { - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.name.cmp(&other.name)) - } + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.name.cmp(&other.name)) + } } impl Eq for Theme {} impl Ord for Theme { - fn cmp(&self, other: &Self) -> Ordering { - self.name.cmp(&other.name) - } + fn cmp(&self, other: &Self) -> Ordering { + self.name.cmp(&other.name) + } } // Newtype on iced::Color so we can impl Deserialzer for it struct Color(iced::Color); mod serde_color { - use super::{color_to_hex, hex_to_color, Color}; - use serde::de::{self, Error, Unexpected, Visitor}; - use serde::ser; - use std::fmt; - - pub(crate) fn deserialize<'de, D>(deserializer: D) -> Result - where - D: de::Deserializer<'de>, - { - struct ColorVisitor; - - impl<'de> Visitor<'de> for ColorVisitor { - type Value = Color; - - fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - formatter.write_str("a hex string in the format of '#09ACDF'") - } - - #[allow(clippy::unnecessary_unwrap)] - fn visit_str(self, s: &str) -> Result - where - E: Error, - { - if let Some(color) = hex_to_color(s) { - return Ok(Color(color)); - } - - Err(de::Error::invalid_value(Unexpected::Str(s), &self)) - } - } - - deserializer.deserialize_any(ColorVisitor).map(|c| c.0) - } - - pub(crate) fn serialize(color: &iced::Color, serializer: S) -> Result - where - S: ser::Serializer, - { - serializer.serialize_str(&color_to_hex(color)) - } + use super::{color_to_hex, hex_to_color, Color}; + use serde::de::{self, Error, Unexpected, Visitor}; + use serde::ser; + use std::fmt; + + pub(crate) fn deserialize<'de, D>(deserializer: D) -> Result + where + D: de::Deserializer<'de>, + { + struct ColorVisitor; + + impl<'de> Visitor<'de> for ColorVisitor { + type Value = Color; + + fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + formatter.write_str("a hex string in the format of '#09ACDF'") + } + + #[allow(clippy::unnecessary_unwrap)] + fn visit_str(self, s: &str) -> Result + where + E: Error, + { + if let Some(color) = hex_to_color(s) { + return Ok(Color(color)); + } + + Err(de::Error::invalid_value(Unexpected::Str(s), &self)) + } + } + + deserializer.deserialize_any(ColorVisitor).map(|c| c.0) + } + + pub(crate) fn serialize(color: &iced::Color, serializer: S) -> Result + where + S: ser::Serializer, + { + serializer.serialize_str(&color_to_hex(color)) + } } #[cfg(test)] mod tests { - use super::{serde_color::deserialize, Theme}; - use serde::de::value::{Error, StrDeserializer}; - use serde::de::IntoDeserializer; - - #[test] - fn test_hex_color_deser() { - let colors = [ - "AABBCC", "AABBCG", "#AABBCG", "#AABB091", "#AABBCC", "#AABB09", - ]; - - for (idx, color_str) in colors.iter().enumerate() { - let deserializer: StrDeserializer = color_str.into_deserializer(); - - let color = deserialize(deserializer); - - if idx < 4 { - assert!(color.is_err()); - } else { - assert!(color.is_ok()); - } - } - } - - #[test] - fn test_hex_color_ser() { - let color = super::NormalColors { - primary: iced::Color::from_rgb(1.0, 1.0, 1.0), - secondary: iced::Color::from_rgb(0.5, 0.6, 0.75789), - surface: iced::Color::from_rgb(0.1, 0.2, 0.3), - error: iced::Color::from_rgb(0.0, 0.0, 0.0), - }; - - let ser = serde_yaml::to_string(&color).unwrap(); - - dbg!(&ser); - } - - #[test] - fn test_theme_yml_deser() { - let theme_str = "--- + use super::{serde_color::deserialize, Theme}; + use serde::de::value::{Error, StrDeserializer}; + use serde::de::IntoDeserializer; + + #[test] + fn test_hex_color_deser() { + let colors = [ + "AABBCC", "AABBCG", "#AABBCG", "#AABB091", "#AABBCC", "#AABB09", + ]; + + for (idx, color_str) in colors.iter().enumerate() { + let deserializer: StrDeserializer = color_str.into_deserializer(); + + let color = deserialize(deserializer); + + if idx < 4 { + assert!(color.is_err()); + } else { + assert!(color.is_ok()); + } + } + } + + #[test] + fn test_hex_color_ser() { + let color = super::NormalColors { + primary: iced::Color::from_rgb(1.0, 1.0, 1.0), + secondary: iced::Color::from_rgb(0.5, 0.6, 0.75789), + surface: iced::Color::from_rgb(0.1, 0.2, 0.3), + error: iced::Color::from_rgb(0.0, 0.0, 0.0), + }; + + let ser = serde_yaml::to_string(&color).unwrap(); + + dbg!(&ser); + } + + #[test] + fn test_theme_yml_deser() { + let theme_str = "--- name: Test palette: base: @@ -644,6 +638,6 @@ mod tests { error: '#484793' "; - serde_yaml::from_str::(theme_str).unwrap(); - } + serde_yaml::from_str::(theme_str).unwrap(); + } } diff --git a/crates/core/src/theme/modal.rs b/crates/core/src/theme/modal.rs index 863fe47..da36042 100644 --- a/crates/core/src/theme/modal.rs +++ b/crates/core/src/theme/modal.rs @@ -4,23 +4,23 @@ use iced_aw::style::modal::Appearance; #[derive(Clone, Copy, Debug, Default)] pub enum ModalStyle { - #[default] - Default, - Normal, + #[default] + Default, + Normal, } impl iced_aw::modal::StyleSheet for Theme { - type Style = ModalStyle; + type Style = ModalStyle; - fn active(&self, style: Self::Style) -> Appearance { - match style { - ModalStyle::Normal => Appearance { - background: Background::Color(Color { - a: 0.9, - ..self.palette.base.foreground - }), - }, - _ => Appearance::default() - } - } + fn active(&self, style: &Self::Style) -> Appearance { + match style { + ModalStyle::Normal => Appearance { + background: Background::Color(Color { + a: 0.9, + ..self.palette.base.foreground + }), + }, + _ => Appearance::default(), + } + } } diff --git a/crates/core/src/theme/picklist.rs b/crates/core/src/theme/picklist.rs index 4e78e75..b2d2aac 100644 --- a/crates/core/src/theme/picklist.rs +++ b/crates/core/src/theme/picklist.rs @@ -1,78 +1,76 @@ - - -use iced_style::{pick_list, menu}; -use iced::{Background, Color}; use super::Theme; +use iced::{Background, Color}; +use iced_core::{Border, Shadow}; +use iced_style::{menu, pick_list}; #[derive(Debug, Clone, Copy, Default)] pub enum PickListStyle { - #[default] - Default, - Primary, + #[default] + Default, + Primary, } impl pick_list::StyleSheet for Theme { - type Style = PickListStyle; + type Style = PickListStyle; - fn active(&self, style: &Self::Style) -> pick_list::Appearance { - match style { - PickListStyle::Primary => pick_list::Appearance { - text_color: self.palette.bright.surface, - background: self.palette.base.background.into(), - border_width: 1.0, - border_color: Color { - a: 0.5, - ..self.palette.normal.primary - }, - border_radius: 2.0.into(), - handle_color: Color { - a: 0.5, - ..self.palette.normal.primary - }, - placeholder_color: Color { - a: 0.5, - ..self.palette.normal.primary - }, - }, - _ => todo!("default") - } - } + fn active(&self, style: &Self::Style) -> pick_list::Appearance { + match style { + PickListStyle::Primary => pick_list::Appearance { + text_color: self.palette.bright.surface, + background: self.palette.base.background.into(), + border: Border { + color: self.palette.normal.primary, + width: 1.0, + radius: 2.0.into(), + }, + handle_color: Color { + a: 0.5, + ..self.palette.normal.primary + }, + placeholder_color: Color { + a: 0.5, + ..self.palette.normal.primary + }, + }, + _ => todo!("default"), + } + } - fn hovered(&self, style: &Self::Style) -> pick_list::Appearance { - match style { - PickListStyle::Primary => { - let active = self.active(style); + fn hovered(&self, style: &Self::Style) -> pick_list::Appearance { + match style { + PickListStyle::Primary => { + let active = self.active(style); - pick_list::Appearance { - text_color: self.palette.bright.primary, - ..active - } - }, - _ => todo!("default") - } - } + pick_list::Appearance { + text_color: self.palette.bright.primary, + ..active + } + } + _ => todo!("default"), + } + } } - impl menu::StyleSheet for Theme { - type Style = PickListStyle; - - fn appearance(&self, style: &Self::Style) -> menu::Appearance { - match style { - PickListStyle::Primary => menu::Appearance { - text_color: self.palette.bright.surface, - background: Background::Color(self.palette.base.foreground), - border_width: 1.0, - border_radius: 2.0.into(), - border_color: self.palette.base.background, - selected_background: Background::Color(Color { - a: 0.15, - ..self.palette.normal.primary - }), - selected_text_color: self.palette.bright.primary, - }, - _ => todo!("default") + type Style = PickListStyle; - } - } -} \ No newline at end of file + fn appearance(&self, style: &Self::Style) -> menu::Appearance { + match style { + PickListStyle::Primary => menu::Appearance { + text_color: self.palette.bright.surface, + background: Background::Color(self.palette.base.foreground), + border: Border { + color: self.palette.normal.primary, + width: 1.0, + radius: 2.0.into(), + }, + selected_background: Background::Color(Color { + a: 0.15, + ..self.palette.normal.primary + }), + selected_text_color: self.palette.bright.primary, + }, + _ => todo!("default"), + } + } +} diff --git a/crates/core/src/theme/scrollable.rs b/crates/core/src/theme/scrollable.rs index d613a51..3fd545e 100644 --- a/crates/core/src/theme/scrollable.rs +++ b/crates/core/src/theme/scrollable.rs @@ -1,61 +1,47 @@ +use super::Theme; use iced::widget::scrollable; use iced::{Background, Color}; -use super::Theme; +use iced_style::scrollable::Appearance; #[derive(Debug, Clone, Copy, Default)] pub enum ScrollableStyle { - #[default] - Default, - Primary, + #[default] + Default, + Primary, } impl scrollable::StyleSheet for Theme { - type Style = ScrollableStyle; - - fn active(&self, style: &Self::Style) -> scrollable::Scrollbar { - match style { - ScrollableStyle::Default => scrollable::Scrollbar { - background: Some(Background::Color(Color::TRANSPARENT)), - border_radius: 0.0.into(), - border_width: 0.0, - border_color: Color::TRANSPARENT, - scroller: scrollable::Scroller { - color: Color::TRANSPARENT, - border_radius: 2.0.into(), - border_width: 0.0, - border_color: Color::TRANSPARENT, - }, - }, - - ScrollableStyle::Primary => scrollable::Scrollbar { - background: Some(Background::Color(self.palette.base.background)), - border_radius: 0.0.into(), - border_width: 0.0, - border_color: Color::TRANSPARENT, - scroller: scrollable::Scroller { - color: self.palette.base.foreground, - border_radius: 2.0.into(), - border_width: 0.0, - border_color: Color::TRANSPARENT, - }, - }, - } - } - - fn hovered(&self, style: &Self::Style, _is_mouse_over_scrollbar: bool) -> scrollable::Scrollbar { - let active = self.active(style); - scrollable::Scrollbar { - scroller: scrollable::Scroller { ..active.scroller }, - ..active - } - } - - fn dragging(&self, style: &Self::Style) -> scrollable::Scrollbar { - let hovered = self.hovered(style, true); - scrollable::Scrollbar { - scroller: scrollable::Scroller { ..hovered.scroller }, - ..hovered - } - } -} + type Style = ScrollableStyle; + + fn active(&self, style: &Self::Style) -> Appearance { + let mut appearance = self.active(style); + + match style { + ScrollableStyle::Default => { + appearance.background = Some(Background::Color(Color::TRANSPARENT)); + appearance.border_radius = 0.0.into(); + appearance.border_width = 0.0.into(); + appearance.border_color = Color::TRANSPARENT; + } + ScrollableStyle::Primary => { + appearance.background = Some(Background::Color(self.palette.base.background)); + appearance.border_radius = 0.0.into(); + appearance.border_width = 0.0.into(); + appearance.border_color = Color::TRANSPARENT; + } + } + + appearance + } + + fn hovered(&self, style: &Self::Style, _is_mouse_over_scrollbar: bool) -> Appearance { + let active = self.active(style); + active + } + + fn dragging(&self, style: &Self::Style) -> Appearance { + let hovered = self.hovered(style, true); + hovered + } +} diff --git a/crates/core/src/theme/table_row.rs b/crates/core/src/theme/table_row.rs deleted file mode 100644 index 8d53c08..0000000 --- a/crates/core/src/theme/table_row.rs +++ /dev/null @@ -1,112 +0,0 @@ -use grin_gui_widgets::style::table_row::{StyleSheet, Appearance}; -use iced::{Background, Color}; -use super::Theme; - -#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] -pub enum TableRowStyle { - #[default] - Default, - TableRowAlternate, - TableRowHighlife, - TableRowLowlife, - TableRowSelected, -} - -impl StyleSheet for Theme { - type Style = TableRowStyle; - - fn appearance(&self, style: &Self::Style) -> Appearance { - match style { - TableRowStyle::Default => Appearance { - text_color: Some(self.palette.normal.primary), - background: Some(Background::Color(self.palette.base.foreground)), - border_radius: 0.0, - border_width: 0.0, - border_color: Color::TRANSPARENT, - // offset_left: 10.0, - // offset_right: 25.0, - offset_left: 0.0, - offset_right: 0.0, - }, - TableRowStyle::TableRowAlternate => Appearance { - background: Some(Background::Color(Color { - a: 0.50, - ..self.palette.base.foreground - })), - ..Appearance::default() - }, - TableRowStyle::TableRowHighlife => Appearance { - text_color: Some(self.palette.normal.primary), - background: Some(Background::Color(Color { - a: 0.30, - ..self.palette.base.foreground - })), - border_radius: 0.0, - border_width: 0.0, - border_color: Color::TRANSPARENT, - offset_left: 0.0, - offset_right: 0.0, - }, - TableRowStyle::TableRowLowlife => Appearance { - text_color: Some(self.palette.normal.primary), - background: Some(Background::Color(Color::TRANSPARENT)), - border_radius: 0.0, - border_width: 0.0, - border_color: Color::TRANSPARENT, - offset_left: 0.0, - offset_right: 0.0, - }, - TableRowStyle::TableRowSelected => Appearance { - text_color: Some(self.palette.normal.primary), - background: Some(Background::Color(self.palette.normal.primary)), - border_radius: 0.0, - border_width: 0.0, - border_color: Color::TRANSPARENT, - offset_left: 0.0, - offset_right: 0.0, - }, - } - } - - fn hovered(&self, style: &Self::Style) -> Appearance { - let appearance = self.appearance(style); - - match style { - TableRowStyle::Default => Appearance { - background: Some(Background::Color(Color { - a: 0.60, - ..self.palette.normal.primary - })), - ..appearance - }, - TableRowStyle::TableRowAlternate => Appearance { - background: Some(Background::Color(Color { - a: 0.25, - ..self.palette.normal.primary - })), - ..appearance - }, - TableRowStyle::TableRowHighlife => Appearance { - background: Some(Background::Color(Color { - a: 0.60, - ..self.palette.normal.primary - })), - ..appearance - }, - TableRowStyle::TableRowLowlife => Appearance { - background: Some(Background::Color(Color { - a: 0.60, - ..self.palette.normal.primary - })), - ..appearance - }, - TableRowStyle::TableRowSelected => Appearance { - background: Some(Background::Color(Color { - a: 0.60, - ..self.palette.normal.primary - })), - ..appearance - }, - } - } -} \ No newline at end of file diff --git a/crates/core/src/theme/text_input.rs b/crates/core/src/theme/text_input.rs index 499a062..ad80ecb 100644 --- a/crates/core/src/theme/text_input.rs +++ b/crates/core/src/theme/text_input.rs @@ -1,101 +1,101 @@ use super::Theme; use iced::widget::text_input; use iced::{Background, Color}; +use iced_core::Border; #[derive(Debug, Clone, Copy, Default)] pub enum TextInputStyle { - #[default] - Default, - AddonsQuery, + #[default] + Default, + AddonsQuery, } impl text_input::StyleSheet for Theme { - type Style = TextInputStyle; + type Style = TextInputStyle; - /// Produces the style of an active text input. - fn active(&self, style: &Self::Style) -> text_input::Appearance { - match style { - TextInputStyle::AddonsQuery => text_input::Appearance { - background: Background::Color(self.palette.base.foreground), - border_radius: 2.0.into(), - border_width: 1.0, - border_color: self.palette.base.foreground, - icon_color: self.palette.base.foreground, - }, - _ => todo!("default"), - } - } + /// Produces the style of an active text input. + fn active(&self, style: &Self::Style) -> text_input::Appearance { + match style { + TextInputStyle::AddonsQuery => text_input::Appearance { + background: Background::Color(self.palette.base.foreground), + border: Border { + color: self.palette.normal.primary, + width: 1.0, + radius: 2.0.into(), + }, + icon_color: self.palette.base.foreground, + }, + _ => todo!("default"), + } + } - /// Produces the style of a focused text input. - fn focused(&self, style: &Self::Style) -> text_input::Appearance { - match style { - TextInputStyle::AddonsQuery => text_input::Appearance { - background: Background::Color(self.palette.base.foreground), - border_radius: 2.0.into(), - border_width: 1.0, - border_color: Color { - a: 0.5, - ..self.palette.normal.primary - }, - icon_color: Color { - a: 1.0, - ..self.palette.normal.primary - } - }, - _ => todo!("default"), - } - } + /// Produces the style of a focused text input. + fn focused(&self, style: &Self::Style) -> text_input::Appearance { + match style { + TextInputStyle::AddonsQuery => text_input::Appearance { + background: Background::Color(self.palette.base.foreground), + border: Border { + color: self.palette.bright.primary, + width: 1.0, + radius: 2.0.into(), + }, + icon_color: Color { + a: 1.0, + ..self.palette.normal.primary + }, + }, + _ => todo!("default"), + } + } - fn disabled(&self, style: &Self::Style) -> text_input::Appearance { - match style { - TextInputStyle::AddonsQuery => text_input::Appearance { - background: Background::Color(self.palette.base.foreground), - border_radius: 2.0.into(), - border_width: 1.0, - border_color: Color { - a: 0.5, - ..self.palette.normal.primary - }, - icon_color: Color { - a: 1.0, - ..self.palette.normal.primary - } - }, - _ => todo!("default"), - } - } + fn disabled(&self, style: &Self::Style) -> text_input::Appearance { + match style { + TextInputStyle::AddonsQuery => text_input::Appearance { + background: Background::Color(self.palette.base.foreground), + border: Border { + color: self.palette.normal.primary, + width: 1.0, + radius: 2.0.into(), + }, + icon_color: Color { + a: 1.0, + ..self.palette.normal.primary + }, + }, + _ => todo!("default"), + } + } + fn placeholder_color(&self, style: &Self::Style) -> Color { + match style { + TextInputStyle::AddonsQuery => self.palette.normal.surface, + _ => todo!("default"), + } + } - fn placeholder_color(&self, style: &Self::Style) -> Color { - match style { - TextInputStyle::AddonsQuery => self.palette.normal.surface, - _ => todo!("default"), - } - } + fn value_color(&self, style: &Self::Style) -> Color { + match style { + TextInputStyle::AddonsQuery => self.palette.bright.primary, + _ => todo!("default"), + } + } - fn value_color(&self, style: &Self::Style) -> Color { - match style { - TextInputStyle::AddonsQuery => self.palette.bright.primary, - _ => todo!("default"), - } - } + fn selection_color(&self, style: &Self::Style) -> Color { + match style { + TextInputStyle::AddonsQuery => self.palette.bright.secondary, + _ => todo!("default"), + } + } - fn selection_color(&self, style: &Self::Style) -> Color { - match style { - TextInputStyle::AddonsQuery => self.palette.bright.secondary, - _ => todo!("default"), - } - } + fn disabled_color(&self, style: &Self::Style) -> Color { + match style { + TextInputStyle::AddonsQuery => self.palette.normal.secondary, + _ => todo!("default"), + } + } - fn disabled_color(&self, style: &Self::Style) -> Color { - match style { - TextInputStyle::AddonsQuery => self.palette.normal.secondary, - _ => todo!("default"), - } - } - - /// Produces the style of an hovered text input. - fn hovered(&self, style: &Self::Style) -> text_input::Appearance { - self.focused(style) - } + /// Produces the style of an hovered text input. + fn hovered(&self, style: &Self::Style) -> text_input::Appearance { + self.focused(style) + } } diff --git a/crates/widgets/src/widget/header.rs b/crates/core/src/widget/header.rs similarity index 95% rename from crates/widgets/src/widget/header.rs rename to crates/core/src/widget/header.rs index d87791c..30218c0 100644 --- a/crates/widgets/src/widget/header.rs +++ b/crates/core/src/widget/header.rs @@ -41,12 +41,14 @@ where { pub fn new( state: State, - headers: Vec<(String, Container<'a, Message, Renderer>)>, + headers: Vec<(String, Container<'a, Message, Theme, Renderer>)>, left_margin: Option, right_margin: Option, ) -> Self where - Theme: StyleSheet, + Theme: iced_style::container::StyleSheet, + Renderer: 'a + iced_core::Renderer, + Message: 'a, { let mut names = vec![]; let mut left = false; @@ -158,8 +160,14 @@ where } } - fn layout(&self, renderer: &Renderer, limits: &layout::Limits) -> layout::Node { + fn layout( + &self, + tree: &mut Tree, + renderer: &Renderer, + limits: &layout::Limits, + ) -> layout::Node { let limits = limits.width(self.width).height(self.height); + let mut trees = self.children(); layout::flex::resolve( layout::flex::Axis::Horizontal, @@ -171,7 +179,7 @@ where self.spacing as f32, Alignment::Start, &self.children, - self.children.iter.map(Tree::new), + &mut trees, ) } @@ -371,7 +379,7 @@ where Theme: StyleSheet + iced::widget::container::StyleSheet + widget::text::StyleSheet, Message: 'a, { - fn from(header: Header<'a, Message, Renderer>) -> Element<'a, Message, Theme, Renderer> { + fn from(header: Header<'a, Message, Theme, Renderer>) -> Element<'a, Message, Theme, Renderer> { Element::new(header) } } diff --git a/crates/core/src/widget/header/state.rs b/crates/core/src/widget/header/state.rs new file mode 100644 index 0000000..4fdc052 --- /dev/null +++ b/crates/core/src/widget/header/state.rs @@ -0,0 +1,11 @@ +use iced_core::Point; + +#[derive(Clone, Debug, Default)] +pub struct State { + pub resize_hovering: bool, + pub resizing: bool, + pub starting_cursor_pos: Option, + pub starting_left_width: f32, + pub starting_right_width: f32, + pub resizing_idx: usize, +} diff --git a/crates/widgets/src/widget/mod.rs b/crates/core/src/widget/mod.rs similarity index 100% rename from crates/widgets/src/widget/mod.rs rename to crates/core/src/widget/mod.rs diff --git a/crates/widgets/src/widget/table_row.rs b/crates/core/src/widget/table_row.rs similarity index 100% rename from crates/widgets/src/widget/table_row.rs rename to crates/core/src/widget/table_row.rs diff --git a/crates/widgets/Cargo.toml b/crates/widgets/Cargo.toml deleted file mode 100644 index cee0b48..0000000 --- a/crates/widgets/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -[package] -name = "grin-gui-widgets" -description = "Widget library for Grin Core GUI" -version = "0.1.0-alpha.6" -authors = ["Yeastplume", "Casper Rogild Storm", "tarkah "] -license = "GPL-3.0" -homepage = "https://github.com/mimblewimble/grin-gui" -repository = "https://github.com/mimblewimble/grin-gui" -edition = "2018" - -[features] -default = ["wgpu"] -wgpu = ["iced_wgpu"] -#opengl = ["iced_glow"] - -[dependencies] -iced = { version = "0.12", features = ["advanced", "lazy", "tokio"] } -iced_graphics = { version = "0.12" } -iced_core = { version = "0.12" } -iced_wgpu = { version = "0.12", optional = true } -iced_style = "0.12" diff --git a/crates/widgets/src/lib.rs b/crates/widgets/src/lib.rs deleted file mode 100644 index bf16527..0000000 --- a/crates/widgets/src/lib.rs +++ /dev/null @@ -1,9 +0,0 @@ -#![allow(dead_code)] -#![allow(unused_variables)] - -pub mod style; -pub mod widget; - -pub use widget::header; -pub use widget::table_row; - diff --git a/crates/widgets/src/style/header.rs b/crates/widgets/src/style/header.rs deleted file mode 100644 index d37b3a9..0000000 --- a/crates/widgets/src/style/header.rs +++ /dev/null @@ -1,25 +0,0 @@ -use iced_core::{Background, Color}; - -/// The appearance of a header. -#[derive(Debug, Clone, Copy)] -pub struct Appearance { - pub text_color: Option, - pub background: Option, - pub border_radius: f32, - pub border_width: f32, - pub border_color: Color, - pub offset_left: f32, - pub offset_right: f32, -} - -/// A set of rules that dictate the style of a header. -pub trait StyleSheet { - type Style: std::default::Default + Copy; - - /// Produces the style of a header. - fn appearance(&self, style: &Self::Style) -> Appearance; - - /// Produces the a hovered appearance for header. - fn hovered(&self, style: &Self::Style) -> Appearance; - -} \ No newline at end of file diff --git a/crates/widgets/src/style/table_row.rs b/crates/widgets/src/style/table_row.rs deleted file mode 100644 index 466395b..0000000 --- a/crates/widgets/src/style/table_row.rs +++ /dev/null @@ -1,24 +0,0 @@ -use iced::{Background, Color}; - -/// The appearance of a table row. -#[derive(Debug, Clone, Copy, Default)] -pub struct Appearance { - pub text_color: Option, - pub background: Option, - pub border_radius: f32, - pub border_width: f32, - pub border_color: Color, - pub offset_left: f32, - pub offset_right: f32, -} - -/// A set of rules that dictate the style of a table row. -pub trait StyleSheet { - type Style: std::default::Default + Copy; - - /// Produces the default appearance of a table row. - fn appearance(&self, style: &Self::Style) -> Appearance; - - /// Produces the hovered appearance table row. - fn hovered(&self, style: &Self::Style) -> Appearance; -} diff --git a/crates/widgets/src/widget/header/state.rs b/crates/widgets/src/widget/header/state.rs deleted file mode 100644 index c3ea9a3..0000000 --- a/crates/widgets/src/widget/header/state.rs +++ /dev/null @@ -1,11 +0,0 @@ -use iced_core::Point; - -#[derive(Clone, Debug, Default)] -pub struct State { - pub resize_hovering: bool, - pub resizing: bool, - pub starting_cursor_pos: Option, - pub starting_left_width: f32, - pub starting_right_width: f32, - pub resizing_idx: usize, -}