diff options
author | 2024-03-05 04:42:25 +0100 | |
---|---|---|
committer | 2024-03-05 04:49:07 +0100 | |
commit | d681aaa57e3106cf0ce90b74ade040ca7bb97832 (patch) | |
tree | e182bb66db63e6e77df0f92fd20f6db051dc6b71 /style | |
parent | 29326215ccf13e1d1e25bf3bf5ada007856bff69 (diff) | |
download | iced-d681aaa57e3106cf0ce90b74ade040ca7bb97832.tar.gz iced-d681aaa57e3106cf0ce90b74ade040ca7bb97832.tar.bz2 iced-d681aaa57e3106cf0ce90b74ade040ca7bb97832.zip |
Simplify theming for `Scrollable` widget
Diffstat (limited to 'style')
-rw-r--r-- | style/src/container.rs | 51 | ||||
-rw-r--r-- | style/src/lib.rs | 2 | ||||
-rw-r--r-- | style/src/scrollable.rs | 55 | ||||
-rw-r--r-- | style/src/theme.rs | 87 |
4 files changed, 0 insertions, 195 deletions
diff --git a/style/src/container.rs b/style/src/container.rs deleted file mode 100644 index 00649c25..00000000 --- a/style/src/container.rs +++ /dev/null @@ -1,51 +0,0 @@ -//! Change the appearance of a container. -use crate::core::{Background, Border, Color, Pixels, Shadow}; - -/// The appearance of a container. -#[derive(Debug, Clone, Copy, Default)] -pub struct Appearance { - /// The text [`Color`] of the container. - pub text_color: Option<Color>, - /// The [`Background`] of the container. - pub background: Option<Background>, - /// The [`Border`] of the container. - pub border: Border, - /// The [`Shadow`] of the container. - pub shadow: Shadow, -} - -impl Appearance { - /// Derives a new [`Appearance`] with a border of the given [`Color`] and - /// `width`. - pub fn with_border( - self, - color: impl Into<Color>, - width: impl Into<Pixels>, - ) -> Self { - Self { - border: Border { - color: color.into(), - width: width.into().0, - ..Border::default() - }, - ..self - } - } - - /// Derives a new [`Appearance`] with the given [`Background`]. - pub fn with_background(self, background: impl Into<Background>) -> Self { - Self { - background: Some(background.into()), - ..self - } - } -} - -/// A set of rules that dictate the [`Appearance`] of a container. -pub trait StyleSheet { - /// The supported style of the [`StyleSheet`]. - type Style: Default; - - /// Produces the [`Appearance`] of a container. - fn appearance(&self, style: &Self::Style) -> Appearance; -} diff --git a/style/src/lib.rs b/style/src/lib.rs index 1b2ce444..da3c0676 100644 --- a/style/src/lib.rs +++ b/style/src/lib.rs @@ -17,7 +17,6 @@ pub use iced_core as core; pub mod application; -pub mod container; pub mod menu; pub mod pane_grid; pub mod pick_list; @@ -25,7 +24,6 @@ pub mod progress_bar; pub mod qr_code; pub mod radio; pub mod rule; -pub mod scrollable; pub mod slider; pub mod svg; pub mod text_editor; diff --git a/style/src/scrollable.rs b/style/src/scrollable.rs deleted file mode 100644 index d2348510..00000000 --- a/style/src/scrollable.rs +++ /dev/null @@ -1,55 +0,0 @@ -//! Change the appearance of a scrollable. -use crate::container; -use crate::core::{Background, Border, Color}; - -/// The appearance of a scrolable. -#[derive(Debug, Clone, Copy)] -pub struct Appearance { - /// The [`container::Appearance`] of a scrollable. - pub container: container::Appearance, - /// The [`Scrollbar`] appearance. - pub scrollbar: Scrollbar, - /// The [`Background`] of the gap between a horizontal and vertical scrollbar. - pub gap: Option<Background>, -} - -/// The appearance of the scrollbar of a scrollable. -#[derive(Debug, Clone, Copy)] -pub struct Scrollbar { - /// The [`Background`] of a scrollbar. - pub background: Option<Background>, - /// The [`Border`] of a scrollbar. - pub border: Border, - /// The appearance of the [`Scroller`] of a scrollbar. - pub scroller: Scroller, -} - -/// The appearance of the scroller of a scrollable. -#[derive(Debug, Clone, Copy)] -pub struct Scroller { - /// The [`Color`] of the scroller. - pub color: Color, - /// The [`Border`] of the scroller. - pub border: Border, -} - -/// A set of rules that dictate the style of a scrollable. -pub trait StyleSheet { - /// The supported style of the [`StyleSheet`]. - type Style: Default; - - /// Produces the [`Appearance`] of an active scrollable. - fn active(&self, style: &Self::Style) -> Appearance; - - /// Produces the [`Appearance`] of a scrollable when it is being hovered. - fn hovered( - &self, - style: &Self::Style, - is_mouse_over_scrollbar: bool, - ) -> Appearance; - - /// Produces the [`Appearance`] of a scrollable when it is being dragged. - fn dragging(&self, style: &Self::Style) -> Appearance { - self.hovered(style, true) - } -} diff --git a/style/src/theme.rs b/style/src/theme.rs index c3260427..6fee19ff 100644 --- a/style/src/theme.rs +++ b/style/src/theme.rs @@ -4,7 +4,6 @@ pub mod palette; pub use palette::Palette; use crate::application; -use crate::container; use crate::core::widget::text; use crate::menu; use crate::pane_grid; @@ -13,7 +12,6 @@ use crate::progress_bar; use crate::qr_code; use crate::radio; use crate::rule; -use crate::scrollable; use crate::slider; use crate::svg; use crate::text_editor; @@ -793,91 +791,6 @@ impl svg::StyleSheet for fn(&Theme) -> svg::Appearance { } } -/// The style of a scrollable. -#[derive(Default)] -pub enum Scrollable { - /// The default style. - #[default] - Default, - /// A custom style. - Custom(Box<dyn scrollable::StyleSheet<Style = Theme>>), -} - -impl Scrollable { - /// Creates a custom [`Scrollable`] theme. - pub fn custom<T: scrollable::StyleSheet<Style = Theme> + 'static>( - style: T, - ) -> Self { - Self::Custom(Box::new(style)) - } -} - -impl scrollable::StyleSheet for Theme { - type Style = Scrollable; - - fn active(&self, style: &Self::Style) -> scrollable::Appearance { - match style { - Scrollable::Default => { - let palette = self.extended_palette(); - - scrollable::Appearance { - container: container::Appearance::default(), - scrollbar: scrollable::Scrollbar { - background: Some(palette.background.weak.color.into()), - border: Border::with_radius(2), - scroller: scrollable::Scroller { - color: palette.background.strong.color, - border: Border::with_radius(2), - }, - }, - gap: None, - } - } - Scrollable::Custom(custom) => custom.active(self), - } - } - - fn hovered( - &self, - style: &Self::Style, - is_mouse_over_scrollbar: bool, - ) -> scrollable::Appearance { - match style { - Scrollable::Default => { - if is_mouse_over_scrollbar { - let palette = self.extended_palette(); - - scrollable::Appearance { - scrollbar: scrollable::Scrollbar { - background: Some( - palette.background.weak.color.into(), - ), - border: Border::with_radius(2), - scroller: scrollable::Scroller { - color: palette.primary.strong.color, - border: Border::with_radius(2), - }, - }, - ..self.active(style) - } - } else { - self.active(style) - } - } - Scrollable::Custom(custom) => { - custom.hovered(self, is_mouse_over_scrollbar) - } - } - } - - fn dragging(&self, style: &Self::Style) -> scrollable::Appearance { - match style { - Scrollable::Default => self.hovered(style, true), - Scrollable::Custom(custom) => custom.dragging(self), - } - } -} - impl text::StyleSheet for Theme {} /// The style of a text input. |