diff options
author | 2023-07-12 12:23:18 -0700 | |
---|---|---|
committer | 2023-07-12 12:23:18 -0700 | |
commit | 633f405f3f78bc7f82d2b2061491b0e011137451 (patch) | |
tree | 5ebfc1f45d216a5c14a90492563599e6969eab4d /style | |
parent | 41836dd80d0534608e7aedfbf2319c540a23de1a (diff) | |
parent | 21bd51426d900e271206f314e0c915dd41065521 (diff) | |
download | iced-633f405f3f78bc7f82d2b2061491b0e011137451.tar.gz iced-633f405f3f78bc7f82d2b2061491b0e011137451.tar.bz2 iced-633f405f3f78bc7f82d2b2061491b0e011137451.zip |
Merge remote-tracking branch 'origin/master' into feat/multi-window-support
# Conflicts:
# Cargo.toml
# core/src/window/icon.rs
# core/src/window/id.rs
# core/src/window/position.rs
# core/src/window/settings.rs
# examples/integration/src/main.rs
# examples/integration_opengl/src/main.rs
# glutin/src/application.rs
# native/src/subscription.rs
# native/src/window.rs
# runtime/src/window/action.rs
# src/lib.rs
# src/window.rs
# winit/Cargo.toml
# winit/src/application.rs
# winit/src/icon.rs
# winit/src/settings.rs
# winit/src/window.rs
Diffstat (limited to 'style')
-rw-r--r-- | style/Cargo.toml | 6 | ||||
-rw-r--r-- | style/src/button.rs | 9 | ||||
-rw-r--r-- | style/src/checkbox.rs | 4 | ||||
-rw-r--r-- | style/src/container.rs | 6 | ||||
-rw-r--r-- | style/src/lib.rs | 3 | ||||
-rw-r--r-- | style/src/menu.rs | 4 | ||||
-rw-r--r-- | style/src/pane_grid.rs | 38 | ||||
-rw-r--r-- | style/src/pick_list.rs | 4 | ||||
-rw-r--r-- | style/src/progress_bar.rs | 4 | ||||
-rw-r--r-- | style/src/rule.rs | 4 | ||||
-rw-r--r-- | style/src/scrollable.rs | 28 | ||||
-rw-r--r-- | style/src/slider.rs | 17 | ||||
-rw-r--r-- | style/src/text.rs | 20 | ||||
-rw-r--r-- | style/src/text_input.rs | 12 | ||||
-rw-r--r-- | style/src/theme.rs | 182 | ||||
-rw-r--r-- | style/src/theme/palette.rs | 22 |
16 files changed, 236 insertions, 127 deletions
diff --git a/style/Cargo.toml b/style/Cargo.toml index 3b54f1ec..8af4a9b3 100644 --- a/style/Cargo.toml +++ b/style/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "iced_style" -version = "0.7.0" +version = "0.8.0" authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"] edition = "2021" description = "The default set of styles of Iced" @@ -11,12 +11,12 @@ keywords = ["gui", "ui", "graphics", "interface", "widgets"] categories = ["gui"] [dependencies.iced_core] -version = "0.8" +version = "0.9" path = "../core" features = ["palette"] [dependencies.palette] -version = "0.6" +version = "0.7" [dependencies.once_cell] version = "1.15" diff --git a/style/src/button.rs b/style/src/button.rs index a564a2b7..e49ad94a 100644 --- a/style/src/button.rs +++ b/style/src/button.rs @@ -1,5 +1,5 @@ //! Change the apperance of a button. -use iced_core::{Background, Color, Vector}; +use iced_core::{Background, BorderRadius, Color, Vector}; /// The appearance of a button. #[derive(Debug, Clone, Copy)] @@ -9,7 +9,7 @@ pub struct Appearance { /// The [`Background`] of the button. pub background: Option<Background>, /// The border radius of the button. - pub border_radius: f32, + pub border_radius: BorderRadius, /// The border width of the button. pub border_width: f32, /// The border [`Color`] of the button. @@ -23,7 +23,7 @@ impl std::default::Default for Appearance { Self { shadow_offset: Vector::default(), background: None, - border_radius: 0.0, + border_radius: 0.0.into(), border_width: 0.0, border_color: Color::TRANSPARENT, text_color: Color::BLACK, @@ -68,6 +68,9 @@ pub trait StyleSheet { a: color.a * 0.5, ..color }), + Background::Gradient(gradient) => { + Background::Gradient(gradient.mul_alpha(0.5)) + } }), text_color: Color { a: active.text_color.a * 0.5, diff --git a/style/src/checkbox.rs b/style/src/checkbox.rs index 52b90ec9..cf52c05d 100644 --- a/style/src/checkbox.rs +++ b/style/src/checkbox.rs @@ -1,5 +1,5 @@ //! Change the appearance of a checkbox. -use iced_core::{Background, Color}; +use iced_core::{Background, BorderRadius, Color}; /// The appearance of a checkbox. #[derive(Debug, Clone, Copy)] @@ -9,7 +9,7 @@ pub struct Appearance { /// The icon [`Color`] of the checkbox. pub icon_color: Color, /// The border radius of the checkbox. - pub border_radius: f32, + pub border_radius: BorderRadius, /// The border width of the checkbox. pub border_width: f32, /// The border [`Color`] of the checkbox. diff --git a/style/src/container.rs b/style/src/container.rs index 560b2d5b..ec543ae4 100644 --- a/style/src/container.rs +++ b/style/src/container.rs @@ -1,5 +1,5 @@ //! Change the appearance of a container. -use iced_core::{Background, Color}; +use iced_core::{Background, BorderRadius, Color}; /// The appearance of a container. #[derive(Debug, Clone, Copy)] @@ -9,7 +9,7 @@ pub struct Appearance { /// The [`Background`] of the container. pub background: Option<Background>, /// The border radius of the container. - pub border_radius: f32, + pub border_radius: BorderRadius, /// The border width of the container. pub border_width: f32, /// The border [`Color`] of the container. @@ -21,7 +21,7 @@ impl std::default::Default for Appearance { Self { text_color: None, background: None, - border_radius: 0.0, + border_radius: 0.0.into(), border_width: 0.0, border_color: Color::TRANSPARENT, } diff --git a/style/src/lib.rs b/style/src/lib.rs index 59eb1eb8..286ff9db 100644 --- a/style/src/lib.rs +++ b/style/src/lib.rs @@ -18,7 +18,7 @@ #![deny(missing_docs, unused_results)] #![forbid(unsafe_code, rust_2018_idioms)] #![allow(clippy::inherent_to_string, clippy::type_complexity)] -pub use iced_core::{Background, Color}; +pub use iced_core as core; pub mod application; pub mod button; @@ -33,7 +33,6 @@ pub mod rule; pub mod scrollable; pub mod slider; pub mod svg; -pub mod text; pub mod text_input; pub mod theme; pub mod toggler; diff --git a/style/src/menu.rs b/style/src/menu.rs index 7d878748..dbf19dae 100644 --- a/style/src/menu.rs +++ b/style/src/menu.rs @@ -1,5 +1,5 @@ //! Change the appearance of menus. -use iced_core::{Background, Color}; +use iced_core::{Background, BorderRadius, Color}; /// The appearance of a menu. #[derive(Debug, Clone, Copy)] @@ -11,7 +11,7 @@ pub struct Appearance { /// The border width of the menu. pub border_width: f32, /// The border radius of the menu. - pub border_radius: f32, + pub border_radius: BorderRadius, /// The border [`Color`] of the menu. pub border_color: Color, /// The text [`Color`] of a selected option in the menu. diff --git a/style/src/pane_grid.rs b/style/src/pane_grid.rs index fd8fc05f..dfdc9186 100644 --- a/style/src/pane_grid.rs +++ b/style/src/pane_grid.rs @@ -1,16 +1,17 @@ //! Change the appearance of a pane grid. -use iced_core::Color; +use iced_core::{Background, BorderRadius, Color}; -/// A set of rules that dictate the style of a container. -pub trait StyleSheet { - /// The supported style of the [`StyleSheet`]. - type Style: Default; - - /// The [`Line`] to draw when a split is picked. - fn picked_split(&self, style: &Self::Style) -> Option<Line>; - - /// The [`Line`] to draw when a split is hovered. - fn hovered_split(&self, style: &Self::Style) -> Option<Line>; +/// The appearance of the hovered region of a pane grid. +#[derive(Debug, Clone, Copy)] +pub struct Appearance { + /// The [`Background`] of the hovered pane region. + pub background: Background, + /// The border width of the hovered pane region. + pub border_width: f32, + /// The border [`Color`] of the hovered pane region. + pub border_color: Color, + /// The border radius of the hovered pane region. + pub border_radius: BorderRadius, } /// A line. @@ -24,3 +25,18 @@ pub struct Line { /// The width of the [`Line`]. pub width: f32, } + +/// A set of rules that dictate the style of a container. +pub trait StyleSheet { + /// The supported style of the [`StyleSheet`]. + type Style: Default; + + /// The [`Appearance`] to draw when a pane is hovered. + fn hovered_region(&self, style: &Self::Style) -> Appearance; + + /// The [`Line`] to draw when a split is picked. + fn picked_split(&self, style: &Self::Style) -> Option<Line>; + + /// The [`Line`] to draw when a split is hovered. + fn hovered_split(&self, style: &Self::Style) -> Option<Line>; +} diff --git a/style/src/pick_list.rs b/style/src/pick_list.rs index 11e13b01..961c1e93 100644 --- a/style/src/pick_list.rs +++ b/style/src/pick_list.rs @@ -1,5 +1,5 @@ //! Change the appearance of a pick list. -use iced_core::{Background, Color}; +use iced_core::{Background, BorderRadius, Color}; /// The appearance of a pick list. #[derive(Debug, Clone, Copy)] @@ -13,7 +13,7 @@ pub struct Appearance { /// The [`Background`] of the pick list. pub background: Background, /// The border radius of the pick list. - pub border_radius: f32, + pub border_radius: BorderRadius, /// The border width of the pick list. pub border_width: f32, /// The border color of the pick list. diff --git a/style/src/progress_bar.rs b/style/src/progress_bar.rs index fb1819fc..c05a6ee4 100644 --- a/style/src/progress_bar.rs +++ b/style/src/progress_bar.rs @@ -1,5 +1,5 @@ //! Change the appearance of a progress bar. -use iced_core::Background; +use iced_core::{Background, BorderRadius}; /// The appearance of a progress bar. #[derive(Debug, Clone, Copy)] @@ -9,7 +9,7 @@ pub struct Appearance { /// The [`Background`] of the bar of the progress bar. pub bar: Background, /// The border radius of the progress bar. - pub border_radius: f32, + pub border_radius: BorderRadius, } /// A set of rules that dictate the style of a progress bar. diff --git a/style/src/rule.rs b/style/src/rule.rs index b7380747..afae085c 100644 --- a/style/src/rule.rs +++ b/style/src/rule.rs @@ -1,5 +1,5 @@ //! Change the appearance of a rule. -use iced_core::Color; +use iced_core::{BorderRadius, Color}; /// The appearance of a rule. #[derive(Debug, Clone, Copy)] @@ -9,7 +9,7 @@ pub struct Appearance { /// The width (thickness) of the rule line. pub width: u16, /// The radius of the line corners. - pub radius: f32, + pub radius: BorderRadius, /// The [`FillMode`] of the rule. pub fill_mode: FillMode, } diff --git a/style/src/scrollable.rs b/style/src/scrollable.rs index 64ed8462..952c11e1 100644 --- a/style/src/scrollable.rs +++ b/style/src/scrollable.rs @@ -1,5 +1,5 @@ //! Change the appearance of a scrollable. -use iced_core::{Background, Color}; +use iced_core::{Background, BorderRadius, Color}; /// The appearance of a scrollable. #[derive(Debug, Clone, Copy)] @@ -7,7 +7,7 @@ pub struct Scrollbar { /// The [`Background`] of a scrollable. pub background: Option<Background>, /// The border radius of a scrollable. - pub border_radius: f32, + pub border_radius: BorderRadius, /// The border width of a scrollable. pub border_width: f32, /// The border [`Color`] of a scrollable. @@ -22,7 +22,7 @@ pub struct Scroller { /// The [`Color`] of the scroller. pub color: Color, /// The border radius of the scroller. - pub border_radius: f32, + pub border_radius: BorderRadius, /// The border width of the scroller. pub border_width: f32, /// The border [`Color`] of the scroller. @@ -37,12 +37,16 @@ pub trait StyleSheet { /// Produces the style of an active scrollbar. fn active(&self, style: &Self::Style) -> Scrollbar; - /// Produces the style of a hovered scrollbar. - fn hovered(&self, style: &Self::Style) -> Scrollbar; + /// Produces the style of a scrollbar when the scrollable is being hovered. + fn hovered( + &self, + style: &Self::Style, + is_mouse_over_scrollbar: bool, + ) -> Scrollbar; /// Produces the style of a scrollbar that is being dragged. fn dragging(&self, style: &Self::Style) -> Scrollbar { - self.hovered(style) + self.hovered(style, true) } /// Produces the style of an active horizontal scrollbar. @@ -50,13 +54,17 @@ pub trait StyleSheet { self.active(style) } - /// Produces the style of a hovered horizontal scrollbar. - fn hovered_horizontal(&self, style: &Self::Style) -> Scrollbar { - self.hovered(style) + /// Produces the style of a horizontal scrollbar when the scrollable is being hovered. + fn hovered_horizontal( + &self, + style: &Self::Style, + is_mouse_over_scrollbar: bool, + ) -> Scrollbar { + self.hovered(style, is_mouse_over_scrollbar) } /// Produces the style of a horizontal scrollbar that is being dragged. fn dragging_horizontal(&self, style: &Self::Style) -> Scrollbar { - self.hovered_horizontal(style) + self.hovered_horizontal(style, true) } } diff --git a/style/src/slider.rs b/style/src/slider.rs index 4b52fad3..f0068558 100644 --- a/style/src/slider.rs +++ b/style/src/slider.rs @@ -1,15 +1,26 @@ //! Change the apperance of a slider. -use iced_core::Color; +use iced_core::{BorderRadius, Color}; /// The appearance of a slider. #[derive(Debug, Clone, Copy)] pub struct Appearance { /// The colors of the rail of the slider. - pub rail_colors: (Color, Color), + pub rail: Rail, /// The appearance of the [`Handle`] of the slider. pub handle: Handle, } +/// The appearance of a slider rail +#[derive(Debug, Clone, Copy)] +pub struct Rail { + /// The colors of the rail of the slider. + pub colors: (Color, Color), + /// The width of the stroke of a slider rail. + pub width: f32, + /// The border radius of the corners of the rail. + pub border_radius: BorderRadius, +} + /// The appearance of the handle of a slider. #[derive(Debug, Clone, Copy)] pub struct Handle { @@ -36,7 +47,7 @@ pub enum HandleShape { /// The width of the rectangle. width: u16, /// The border radius of the corners of the rectangle. - border_radius: f32, + border_radius: BorderRadius, }, } diff --git a/style/src/text.rs b/style/src/text.rs deleted file mode 100644 index f31c2306..00000000 --- a/style/src/text.rs +++ /dev/null @@ -1,20 +0,0 @@ -//! Change the appearance of text. -use iced_core::Color; - -/// The style sheet of some text. -pub trait StyleSheet { - /// The supported style of the [`StyleSheet`]. - type Style: Default + Copy; - - /// Produces the [`Appearance`] of some text. - fn appearance(&self, style: Self::Style) -> Appearance; -} - -/// The apperance of some text. -#[derive(Debug, Clone, Copy, Default)] -pub struct Appearance { - /// The [`Color`] of the text. - /// - /// The default, `None`, means using the inherited color. - pub color: Option<Color>, -} diff --git a/style/src/text_input.rs b/style/src/text_input.rs index d97016dc..90251b5c 100644 --- a/style/src/text_input.rs +++ b/style/src/text_input.rs @@ -1,5 +1,5 @@ //! Change the appearance of a text input. -use iced_core::{Background, Color}; +use iced_core::{Background, BorderRadius, Color}; /// The appearance of a text input. #[derive(Debug, Clone, Copy)] @@ -7,11 +7,13 @@ pub struct Appearance { /// The [`Background`] of the text input. pub background: Background, /// The border radius of the text input. - pub border_radius: f32, + pub border_radius: BorderRadius, /// The border width of the text input. pub border_width: f32, /// The border [`Color`] of the text input. pub border_color: Color, + /// The icon [`Color`] of the text input. + pub icon_color: Color, } /// A set of rules that dictate the style of a text input. @@ -31,6 +33,9 @@ pub trait StyleSheet { /// Produces the [`Color`] of the value of a text input. fn value_color(&self, style: &Self::Style) -> Color; + /// Produces the [`Color`] of the value of a disabled text input. + fn disabled_color(&self, style: &Self::Style) -> Color; + /// Produces the [`Color`] of the selection of a text input. fn selection_color(&self, style: &Self::Style) -> Color; @@ -38,4 +43,7 @@ pub trait StyleSheet { fn hovered(&self, style: &Self::Style) -> Appearance { self.focused(style) } + + /// Produces the style of a disabled text input. + fn disabled(&self, style: &Self::Style) -> Appearance; } diff --git a/style/src/theme.rs b/style/src/theme.rs index 4ba4facf..64497181 100644 --- a/style/src/theme.rs +++ b/style/src/theme.rs @@ -8,6 +8,7 @@ use crate::application; use crate::button; use crate::checkbox; use crate::container; +use crate::core::widget::text; use crate::menu; use crate::pane_grid; use crate::pick_list; @@ -17,7 +18,6 @@ use crate::rule; use crate::scrollable; use crate::slider; use crate::svg; -use crate::text; use crate::text_input; use crate::toggler; @@ -105,7 +105,7 @@ impl application::StyleSheet for Theme { } } -impl application::StyleSheet for fn(&Theme) -> application::Appearance { +impl<T: Fn(&Theme) -> application::Appearance> application::StyleSheet for T { type Style = Theme; fn appearance(&self, style: &Self::Style) -> application::Appearance { @@ -113,8 +113,10 @@ impl application::StyleSheet for fn(&Theme) -> application::Appearance { } } -impl From<fn(&Theme) -> application::Appearance> for Application { - fn from(f: fn(&Theme) -> application::Appearance) -> Self { +impl<T: Fn(&Theme) -> application::Appearance + 'static> From<T> + for Application +{ + fn from(f: T) -> Self { Self::Custom(Box::new(f)) } } @@ -139,6 +141,15 @@ pub enum Button { Custom(Box<dyn button::StyleSheet<Style = Theme>>), } +impl Button { + /// Creates a custom [`Button`] style variant. + pub fn custom( + style_sheet: impl button::StyleSheet<Style = Theme> + 'static, + ) -> Self { + Self::Custom(Box::new(style_sheet)) + } +} + impl button::StyleSheet for Theme { type Style = Button; @@ -146,7 +157,7 @@ impl button::StyleSheet for Theme { let palette = self.extended_palette(); let appearance = button::Appearance { - border_radius: 2.0, + border_radius: 2.0.into(), ..button::Appearance::default() }; @@ -217,6 +228,9 @@ impl button::StyleSheet for Theme { a: color.a * 0.5, ..color }), + Background::Gradient(gradient) => { + Background::Gradient(gradient.mul_alpha(0.5)) + } }), text_color: Color { a: active.text_color.a * 0.5, @@ -332,7 +346,7 @@ fn checkbox_appearance( base.color }), icon_color, - border_radius: 2.0, + border_radius: 2.0.into(), border_width: 1.0, border_color: accent.color, text_color: None, @@ -351,8 +365,8 @@ pub enum Container { Custom(Box<dyn container::StyleSheet<Style = Theme>>), } -impl From<fn(&Theme) -> container::Appearance> for Container { - fn from(f: fn(&Theme) -> container::Appearance) -> Self { +impl<T: Fn(&Theme) -> container::Appearance + 'static> From<T> for Container { + fn from(f: T) -> Self { Self::Custom(Box::new(f)) } } @@ -368,8 +382,8 @@ impl container::StyleSheet for Theme { container::Appearance { text_color: None, - background: palette.background.weak.color.into(), - border_radius: 2.0, + background: Some(palette.background.weak.color.into()), + border_radius: 2.0.into(), border_width: 0.0, border_color: Color::TRANSPARENT, } @@ -379,7 +393,7 @@ impl container::StyleSheet for Theme { } } -impl container::StyleSheet for fn(&Theme) -> container::Appearance { +impl<T: Fn(&Theme) -> container::Appearance> container::StyleSheet for T { type Style = Theme; fn appearance(&self, style: &Self::Style) -> container::Appearance { @@ -408,7 +422,7 @@ impl slider::StyleSheet for Theme { let handle = slider::Handle { shape: slider::HandleShape::Rectangle { width: 8, - border_radius: 4.0, + border_radius: 4.0.into(), }, color: Color::WHITE, border_color: Color::WHITE, @@ -416,10 +430,14 @@ impl slider::StyleSheet for Theme { }; slider::Appearance { - rail_colors: ( - palette.primary.base.color, - Color::TRANSPARENT, - ), + rail: slider::Rail { + colors: ( + palette.primary.base.color, + palette.secondary.base.color, + ), + width: 4.0, + border_radius: 2.0.into(), + }, handle: slider::Handle { color: palette.background.base.color, border_color: palette.primary.base.color, @@ -490,7 +508,7 @@ impl menu::StyleSheet for Theme { text_color: palette.background.weak.text, background: palette.background.weak.color.into(), border_width: 1.0, - border_radius: 0.0, + border_radius: 0.0.into(), border_color: palette.background.strong.color, selected_text_color: palette.primary.strong.text, selected_background: palette.primary.strong.color.into(), @@ -536,7 +554,7 @@ impl pick_list::StyleSheet for Theme { background: palette.background.weak.color.into(), placeholder_color: palette.background.strong.color, handle_color: palette.background.weak.text, - border_radius: 2.0, + border_radius: 2.0.into(), border_width: 1.0, border_color: palette.background.strong.color, } @@ -555,7 +573,7 @@ impl pick_list::StyleSheet for Theme { background: palette.background.weak.color.into(), placeholder_color: palette.background.strong.color, handle_color: palette.background.weak.text, - border_radius: 2.0, + border_radius: 2.0.into(), border_width: 1.0, border_color: palette.primary.strong.color, } @@ -700,6 +718,25 @@ pub enum PaneGrid { impl pane_grid::StyleSheet for Theme { type Style = PaneGrid; + fn hovered_region(&self, style: &Self::Style) -> pane_grid::Appearance { + match style { + PaneGrid::Default => { + let palette = self.extended_palette(); + + pane_grid::Appearance { + background: Background::Color(Color { + a: 0.5, + ..palette.primary.base.color + }), + border_width: 2.0, + border_color: palette.primary.strong.color, + border_radius: 0.0.into(), + } + } + PaneGrid::Custom(custom) => custom.hovered_region(self), + } + } + fn picked_split(&self, style: &Self::Style) -> Option<pane_grid::Line> { match style { PaneGrid::Default => { @@ -743,8 +780,10 @@ pub enum ProgressBar { Custom(Box<dyn progress_bar::StyleSheet<Style = Theme>>), } -impl From<fn(&Theme) -> progress_bar::Appearance> for ProgressBar { - fn from(f: fn(&Theme) -> progress_bar::Appearance) -> Self { +impl<T: Fn(&Theme) -> progress_bar::Appearance + 'static> From<T> + for ProgressBar +{ + fn from(f: T) -> Self { Self::Custom(Box::new(f)) } } @@ -762,7 +801,7 @@ impl progress_bar::StyleSheet for Theme { let from_palette = |bar: Color| progress_bar::Appearance { background: palette.background.strong.color.into(), bar: bar.into(), - border_radius: 2.0, + border_radius: 2.0.into(), }; match style { @@ -774,7 +813,7 @@ impl progress_bar::StyleSheet for Theme { } } -impl progress_bar::StyleSheet for fn(&Theme) -> progress_bar::Appearance { +impl<T: Fn(&Theme) -> progress_bar::Appearance> progress_bar::StyleSheet for T { type Style = Theme; fn appearance(&self, style: &Self::Style) -> progress_bar::Appearance { @@ -792,8 +831,8 @@ pub enum Rule { Custom(Box<dyn rule::StyleSheet<Style = Theme>>), } -impl From<fn(&Theme) -> rule::Appearance> for Rule { - fn from(f: fn(&Theme) -> rule::Appearance) -> Self { +impl<T: Fn(&Theme) -> rule::Appearance + 'static> From<T> for Rule { + fn from(f: T) -> Self { Self::Custom(Box::new(f)) } } @@ -808,7 +847,7 @@ impl rule::StyleSheet for Theme { Rule::Default => rule::Appearance { color: palette.background.strong.color, width: 1, - radius: 0.0, + radius: 0.0.into(), fill_mode: rule::FillMode::Full, }, Rule::Custom(custom) => custom.appearance(self), @@ -816,7 +855,7 @@ impl rule::StyleSheet for Theme { } } -impl rule::StyleSheet for fn(&Theme) -> rule::Appearance { +impl<T: Fn(&Theme) -> rule::Appearance> rule::StyleSheet for T { type Style = Theme; fn appearance(&self, style: &Self::Style) -> rule::Appearance { @@ -890,13 +929,13 @@ impl scrollable::StyleSheet for Theme { let palette = self.extended_palette(); scrollable::Scrollbar { - background: palette.background.weak.color.into(), - border_radius: 2.0, + background: Some(palette.background.weak.color.into()), + border_radius: 2.0.into(), border_width: 0.0, border_color: Color::TRANSPARENT, scroller: scrollable::Scroller { color: palette.background.strong.color, - border_radius: 2.0, + border_radius: 2.0.into(), border_width: 0.0, border_color: Color::TRANSPARENT, }, @@ -906,31 +945,41 @@ impl scrollable::StyleSheet for Theme { } } - fn hovered(&self, style: &Self::Style) -> scrollable::Scrollbar { + fn hovered( + &self, + style: &Self::Style, + is_mouse_over_scrollbar: bool, + ) -> scrollable::Scrollbar { match style { Scrollable::Default => { - let palette = self.extended_palette(); + if is_mouse_over_scrollbar { + let palette = self.extended_palette(); - scrollable::Scrollbar { - background: palette.background.weak.color.into(), - border_radius: 2.0, - border_width: 0.0, - border_color: Color::TRANSPARENT, - scroller: scrollable::Scroller { - color: palette.primary.strong.color, - border_radius: 2.0, + scrollable::Scrollbar { + background: Some(palette.background.weak.color.into()), + border_radius: 2.0.into(), border_width: 0.0, border_color: Color::TRANSPARENT, - }, + scroller: scrollable::Scroller { + color: palette.primary.strong.color, + border_radius: 2.0.into(), + border_width: 0.0, + border_color: Color::TRANSPARENT, + }, + } + } else { + self.active(style) } } - Scrollable::Custom(custom) => custom.hovered(self), + Scrollable::Custom(custom) => { + custom.hovered(self, is_mouse_over_scrollbar) + } } } fn dragging(&self, style: &Self::Style) -> scrollable::Scrollbar { match style { - Scrollable::Default => self.hovered(style), + Scrollable::Default => self.hovered(style, true), Scrollable::Custom(custom) => custom.dragging(self), } } @@ -942,10 +991,16 @@ impl scrollable::StyleSheet for Theme { } } - fn hovered_horizontal(&self, style: &Self::Style) -> scrollable::Scrollbar { + fn hovered_horizontal( + &self, + style: &Self::Style, + is_mouse_over_scrollbar: bool, + ) -> scrollable::Scrollbar { match style { - Scrollable::Default => self.hovered(style), - Scrollable::Custom(custom) => custom.hovered_horizontal(self), + Scrollable::Default => self.hovered(style, is_mouse_over_scrollbar), + Scrollable::Custom(custom) => { + custom.hovered_horizontal(self, is_mouse_over_scrollbar) + } } } @@ -954,7 +1009,7 @@ impl scrollable::StyleSheet for Theme { style: &Self::Style, ) -> scrollable::Scrollbar { match style { - Scrollable::Default => self.hovered_horizontal(style), + Scrollable::Default => self.hovered_horizontal(style, true), Scrollable::Custom(custom) => custom.dragging_horizontal(self), } } @@ -1009,9 +1064,10 @@ impl text_input::StyleSheet for Theme { text_input::Appearance { background: palette.background.base.color.into(), - border_radius: 2.0, + border_radius: 2.0.into(), border_width: 1.0, border_color: palette.background.strong.color, + icon_color: palette.background.weak.text, } } @@ -1024,9 +1080,10 @@ impl text_input::StyleSheet for Theme { text_input::Appearance { background: palette.background.base.color.into(), - border_radius: 2.0, + border_radius: 2.0.into(), border_width: 1.0, border_color: palette.background.base.text, + icon_color: palette.background.weak.text, } } @@ -1039,9 +1096,10 @@ impl text_input::StyleSheet for Theme { text_input::Appearance { background: palette.background.base.color.into(), - border_radius: 2.0, + border_radius: 2.0.into(), border_width: 1.0, border_color: palette.primary.strong.color, + icon_color: palette.background.weak.text, } } @@ -1074,4 +1132,28 @@ impl text_input::StyleSheet for Theme { palette.primary.weak.color } + + fn disabled(&self, style: &Self::Style) -> text_input::Appearance { + if let TextInput::Custom(custom) = style { + return custom.disabled(self); + } + + let palette = self.extended_palette(); + + text_input::Appearance { + background: palette.background.weak.color.into(), + border_radius: 2.0.into(), + border_width: 1.0, + border_color: palette.background.strong.color, + icon_color: palette.background.strong.color, + } + } + + fn disabled_color(&self, style: &Self::Style) -> Color { + if let TextInput::Custom(custom) = style { + return custom.disabled_color(self); + } + + self.placeholder_color(style) + } } diff --git a/style/src/theme/palette.rs b/style/src/theme/palette.rs index 0f15494b..aaeb799d 100644 --- a/style/src/theme/palette.rs +++ b/style/src/theme/palette.rs @@ -2,7 +2,9 @@ use iced_core::Color; use once_cell::sync::Lazy; -use palette::{FromColor, Hsl, Mix, RelativeContrast, Srgb}; +use palette::color_difference::Wcag21RelativeContrast; +use palette::rgb::Rgb; +use palette::{FromColor, Hsl, Mix}; /// A color palette. #[derive(Debug, Clone, Copy, PartialEq)] @@ -298,11 +300,11 @@ fn deviate(color: Color, amount: f32) -> Color { } fn mix(a: Color, b: Color, factor: f32) -> Color { - let a_lin = Srgb::from(a).into_linear(); - let b_lin = Srgb::from(b).into_linear(); + let a_lin = Rgb::from(a).into_linear(); + let b_lin = Rgb::from(b).into_linear(); - let mixed = a_lin.mix(&b_lin, factor); - Srgb::from_linear(mixed).into() + let mixed = a_lin.mix(b_lin, factor); + Rgb::from_linear(mixed).into() } fn readable(background: Color, text: Color) -> Color { @@ -320,16 +322,16 @@ fn is_dark(color: Color) -> bool { } fn is_readable(a: Color, b: Color) -> bool { - let a_srgb = Srgb::from(a); - let b_srgb = Srgb::from(b); + let a_srgb = Rgb::from(a); + let b_srgb = Rgb::from(b); - a_srgb.has_enhanced_contrast_text(&b_srgb) + a_srgb.has_enhanced_contrast_text(b_srgb) } fn to_hsl(color: Color) -> Hsl { - Hsl::from_color(Srgb::from(color)) + Hsl::from_color(Rgb::from(color)) } fn from_hsl(hsl: Hsl) -> Color { - Srgb::from_color(hsl).into() + Rgb::from_color(hsl).into() } |