diff options
author | 2024-01-20 13:29:25 +0100 | |
---|---|---|
committer | 2024-01-20 13:29:25 +0100 | |
commit | 25f182f933ea6b7c112c8f9a450a98dc9b9eebdd (patch) | |
tree | fdc498d705f033d3c432e6a06b8cd223dfd82633 /style | |
parent | 4d502012b3e3ed9d9ef80f21078d53d182cdaa1b (diff) | |
download | iced-25f182f933ea6b7c112c8f9a450a98dc9b9eebdd.tar.gz iced-25f182f933ea6b7c112c8f9a450a98dc9b9eebdd.tar.bz2 iced-25f182f933ea6b7c112c8f9a450a98dc9b9eebdd.zip |
Introduce `Border` struct analogous to `Shadow`
Diffstat (limited to 'style')
-rw-r--r-- | style/src/button.rs | 14 | ||||
-rw-r--r-- | style/src/checkbox.rs | 10 | ||||
-rw-r--r-- | style/src/container.rs | 31 | ||||
-rw-r--r-- | style/src/menu.rs | 10 | ||||
-rw-r--r-- | style/src/pane_grid.rs | 12 | ||||
-rw-r--r-- | style/src/pick_list.rs | 10 | ||||
-rw-r--r-- | style/src/progress_bar.rs | 5 | ||||
-rw-r--r-- | style/src/rule.rs | 5 | ||||
-rw-r--r-- | style/src/scrollable.rs | 18 | ||||
-rw-r--r-- | style/src/slider.rs | 7 | ||||
-rw-r--r-- | style/src/text_editor.rs | 12 | ||||
-rw-r--r-- | style/src/text_input.rs | 10 | ||||
-rw-r--r-- | style/src/theme.rs | 128 |
13 files changed, 120 insertions, 152 deletions
diff --git a/style/src/button.rs b/style/src/button.rs index e49ad94a..d8732263 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, BorderRadius, Color, Vector}; +use iced_core::{Background, Border, Color, Vector}; /// The appearance of a button. #[derive(Debug, Clone, Copy)] @@ -8,12 +8,8 @@ pub struct Appearance { pub shadow_offset: Vector, /// The [`Background`] of the button. pub background: Option<Background>, - /// The border radius of the button. - pub border_radius: BorderRadius, - /// The border width of the button. - pub border_width: f32, - /// The border [`Color`] of the button. - pub border_color: Color, + /// The [`Border`] of the butoon. + pub border: Border, /// The text [`Color`] of the button. pub text_color: Color, } @@ -23,9 +19,7 @@ impl std::default::Default for Appearance { Self { shadow_offset: Vector::default(), background: None, - border_radius: 0.0.into(), - border_width: 0.0, - border_color: Color::TRANSPARENT, + border: Border::default(), text_color: Color::BLACK, } } diff --git a/style/src/checkbox.rs b/style/src/checkbox.rs index cf52c05d..d96ea4ad 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, BorderRadius, Color}; +use iced_core::{Background, Border, Color}; /// The appearance of a checkbox. #[derive(Debug, Clone, Copy)] @@ -8,12 +8,8 @@ pub struct Appearance { pub background: Background, /// The icon [`Color`] of the checkbox. pub icon_color: Color, - /// The border radius of the checkbox. - pub border_radius: BorderRadius, - /// The border width of the checkbox. - pub border_width: f32, - /// The border [`Color`] of the checkbox. - pub border_color: Color, + /// The [`Border`] of hte checkbox. + pub border: Border, /// The text [`Color`] of the checkbox. pub text_color: Option<Color>, } diff --git a/style/src/container.rs b/style/src/container.rs index 490a9dab..a490c187 100644 --- a/style/src/container.rs +++ b/style/src/container.rs @@ -1,19 +1,15 @@ //! Change the appearance of a container. -use crate::core::{Background, BorderRadius, Color, Pixels}; +use crate::core::{Background, Border, Color, Pixels}; /// The appearance of a container. -#[derive(Debug, Clone, Copy)] +#[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 radius of the container. - pub border_radius: BorderRadius, - /// The border width of the container. - pub border_width: f32, - /// The border [`Color`] of the container. - pub border_color: Color, + /// The [`Border`] of the container. + pub border: Border, } impl Appearance { @@ -25,8 +21,11 @@ impl Appearance { width: impl Into<Pixels>, ) -> Self { Self { - border_color: color.into(), - border_width: width.into().0, + border: Border { + color: color.into(), + width: width.into().0, + ..Border::default() + }, ..self } } @@ -40,18 +39,6 @@ impl Appearance { } } -impl std::default::Default for Appearance { - fn default() -> Self { - Self { - text_color: None, - background: None, - border_radius: 0.0.into(), - border_width: 0.0, - border_color: Color::TRANSPARENT, - } - } -} - /// A set of rules that dictate the [`Appearance`] of a container. pub trait StyleSheet { /// The supported style of the [`StyleSheet`]. diff --git a/style/src/menu.rs b/style/src/menu.rs index dbf19dae..be60a3f8 100644 --- a/style/src/menu.rs +++ b/style/src/menu.rs @@ -1,5 +1,5 @@ //! Change the appearance of menus. -use iced_core::{Background, BorderRadius, Color}; +use iced_core::{Background, Border, Color}; /// The appearance of a menu. #[derive(Debug, Clone, Copy)] @@ -8,12 +8,8 @@ pub struct Appearance { pub text_color: Color, /// The [`Background`] of the menu. pub background: Background, - /// The border width of the menu. - pub border_width: f32, - /// The border radius of the menu. - pub border_radius: BorderRadius, - /// The border [`Color`] of the menu. - pub border_color: Color, + /// The [`Border`] of the menu. + pub border: Border, /// The text [`Color`] of a selected option in the menu. pub selected_text_color: Color, /// The background [`Color`] of a selected option in the menu. diff --git a/style/src/pane_grid.rs b/style/src/pane_grid.rs index dfdc9186..35570584 100644 --- a/style/src/pane_grid.rs +++ b/style/src/pane_grid.rs @@ -1,17 +1,13 @@ //! Change the appearance of a pane grid. -use iced_core::{Background, BorderRadius, Color}; +use iced_core::{Background, Border, Color}; /// The appearance of the hovered region of a pane grid. #[derive(Debug, Clone, Copy)] pub struct Appearance { - /// The [`Background`] of the hovered pane region. + /// The [`Background`] of the 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, + /// The [`Border`] of the pane region. + pub border: Border, } /// A line. diff --git a/style/src/pick_list.rs b/style/src/pick_list.rs index 961c1e93..8f008f4a 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, BorderRadius, Color}; +use iced_core::{Background, Border, Color}; /// The appearance of a pick list. #[derive(Debug, Clone, Copy)] @@ -12,12 +12,8 @@ pub struct Appearance { pub handle_color: Color, /// The [`Background`] of the pick list. pub background: Background, - /// The border radius of the pick list. - pub border_radius: BorderRadius, - /// The border width of the pick list. - pub border_width: f32, - /// The border color of the pick list. - pub border_color: Color, + /// The [`Border`] of the pick list. + pub border: Border, } /// A set of rules that dictate the style of a container. diff --git a/style/src/progress_bar.rs b/style/src/progress_bar.rs index c05a6ee4..b62512d8 100644 --- a/style/src/progress_bar.rs +++ b/style/src/progress_bar.rs @@ -1,5 +1,6 @@ //! Change the appearance of a progress bar. -use iced_core::{Background, BorderRadius}; +use crate::core::border; +use crate::core::Background; /// The appearance of a progress bar. #[derive(Debug, Clone, Copy)] @@ -9,7 +10,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: BorderRadius, + pub border_radius: border::Radius, } /// 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 efbe7444..12980da7 100644 --- a/style/src/rule.rs +++ b/style/src/rule.rs @@ -1,5 +1,6 @@ //! Change the appearance of a rule. -use iced_core::{BorderRadius, Color}; +use crate::core::border; +use crate::core::Color; /// The appearance of a rule. #[derive(Debug, Clone, Copy)] @@ -9,7 +10,7 @@ pub struct Appearance { /// The width (thickness) of the rule line. pub width: u16, /// The radius of the line corners. - pub radius: BorderRadius, + pub radius: border::Radius, /// The [`FillMode`] of the rule. pub fill_mode: FillMode, } diff --git a/style/src/scrollable.rs b/style/src/scrollable.rs index 952c11e1..6f37305f 100644 --- a/style/src/scrollable.rs +++ b/style/src/scrollable.rs @@ -1,17 +1,13 @@ //! Change the appearance of a scrollable. -use iced_core::{Background, BorderRadius, Color}; +use crate::core::{Background, Border, Color}; /// The appearance of a scrollable. #[derive(Debug, Clone, Copy)] pub struct Scrollbar { /// The [`Background`] of a scrollable. pub background: Option<Background>, - /// The border radius of a scrollable. - pub border_radius: BorderRadius, - /// The border width of a scrollable. - pub border_width: f32, - /// The border [`Color`] of a scrollable. - pub border_color: Color, + /// The [`Border`] of a scrollable. + pub border: Border, /// The appearance of the [`Scroller`] of a scrollable. pub scroller: Scroller, } @@ -21,12 +17,8 @@ pub struct Scrollbar { pub struct Scroller { /// The [`Color`] of the scroller. pub color: Color, - /// The border radius of the scroller. - pub border_radius: BorderRadius, - /// The border width of the scroller. - pub border_width: f32, - /// The border [`Color`] of the scroller. - pub border_color: Color, + /// The [`Border`] of the scroller. + pub border: Border, } /// A set of rules that dictate the style of a scrollable. diff --git a/style/src/slider.rs b/style/src/slider.rs index f0068558..bf1c7329 100644 --- a/style/src/slider.rs +++ b/style/src/slider.rs @@ -1,5 +1,6 @@ //! Change the apperance of a slider. -use iced_core::{BorderRadius, Color}; +use crate::core::border; +use crate::core::Color; /// The appearance of a slider. #[derive(Debug, Clone, Copy)] @@ -18,7 +19,7 @@ pub struct Rail { /// 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, + pub border_radius: border::Radius, } /// The appearance of the handle of a slider. @@ -47,7 +48,7 @@ pub enum HandleShape { /// The width of the rectangle. width: u16, /// The border radius of the corners of the rectangle. - border_radius: BorderRadius, + border_radius: border::Radius, }, } diff --git a/style/src/text_editor.rs b/style/src/text_editor.rs index f6bae7e6..87f481e3 100644 --- a/style/src/text_editor.rs +++ b/style/src/text_editor.rs @@ -1,17 +1,13 @@ //! Change the appearance of a text editor. -use crate::core::{Background, BorderRadius, Color}; +use crate::core::{Background, Border, Color}; /// The appearance of a text input. #[derive(Debug, Clone, Copy)] pub struct Appearance { - /// The [`Background`] of the text input. + /// The [`Background`] of the text editor. pub background: Background, - /// The border radius of the text input. - 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 [`Border`] of the text editor. + pub border: Border, } /// A set of rules that dictate the style of a text input. diff --git a/style/src/text_input.rs b/style/src/text_input.rs index 90251b5c..8ba9957f 100644 --- a/style/src/text_input.rs +++ b/style/src/text_input.rs @@ -1,17 +1,13 @@ //! Change the appearance of a text input. -use iced_core::{Background, BorderRadius, Color}; +use iced_core::{Background, Border, Color}; /// The appearance of a text input. #[derive(Debug, Clone, Copy)] pub struct Appearance { /// The [`Background`] of the text input. pub background: Background, - /// The border radius of the text input. - 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 [`Border`] of the text input. + pub border: Border, /// The icon [`Color`] of the text input. pub icon_color: Color, } diff --git a/style/src/theme.rs b/style/src/theme.rs index f78587e5..d90efb0a 100644 --- a/style/src/theme.rs +++ b/style/src/theme.rs @@ -21,7 +21,7 @@ use crate::text_editor; use crate::text_input; use crate::toggler; -use iced_core::{Background, Color, Vector}; +use crate::core::{Background, Border, Color, Vector}; use std::fmt; use std::rc::Rc; @@ -199,7 +199,7 @@ impl button::StyleSheet for Theme { let palette = self.extended_palette(); let appearance = button::Appearance { - border_radius: 2.0.into(), + border: Border::with_radius(2), ..button::Appearance::default() }; @@ -388,9 +388,11 @@ fn checkbox_appearance( base.color }), icon_color, - border_radius: 2.0.into(), - border_width: 1.0, - border_color: accent.color, + border: Border { + radius: 2.0.into(), + width: 1.0, + color: accent.color, + }, text_color: None, } } @@ -431,9 +433,7 @@ impl container::StyleSheet for Theme { container::Appearance { text_color: None, background: Some(palette.background.weak.color.into()), - border_radius: 2.0.into(), - border_width: 0.0, - border_color: Color::TRANSPARENT, + border: Border::with_radius(2), } } Container::Custom(custom) => custom.appearance(self), @@ -555,9 +555,11 @@ impl menu::StyleSheet for Theme { menu::Appearance { text_color: palette.background.weak.text, background: palette.background.weak.color.into(), - border_width: 1.0, - border_radius: 0.0.into(), - border_color: palette.background.strong.color, + border: Border { + width: 1.0, + radius: 0.0.into(), + color: palette.background.strong.color, + }, selected_text_color: palette.primary.strong.text, selected_background: palette.primary.strong.color.into(), } @@ -602,9 +604,11 @@ 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.into(), - border_width: 1.0, - border_color: palette.background.strong.color, + border: Border { + radius: 2.0.into(), + width: 1.0, + color: palette.background.strong.color, + }, } } PickList::Custom(custom, _) => custom.active(self), @@ -621,9 +625,11 @@ 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.into(), - border_width: 1.0, - border_color: palette.primary.strong.color, + border: Border { + radius: 2.0.into(), + width: 1.0, + color: palette.primary.strong.color, + }, } } PickList::Custom(custom, _) => custom.hovered(self), @@ -776,9 +782,11 @@ impl pane_grid::StyleSheet for Theme { a: 0.5, ..palette.primary.base.color }), - border_width: 2.0, - border_color: palette.primary.strong.color, - border_radius: 0.0.into(), + border: Border { + width: 2.0, + color: palette.primary.strong.color, + radius: 0.0.into(), + }, } } PaneGrid::Custom(custom) => custom.hovered_region(self), @@ -986,14 +994,10 @@ impl scrollable::StyleSheet for Theme { scrollable::Scrollbar { background: Some(palette.background.weak.color.into()), - border_radius: 2.0.into(), - border_width: 0.0, - border_color: Color::TRANSPARENT, + border: Border::with_radius(2), scroller: scrollable::Scroller { color: palette.background.strong.color, - border_radius: 2.0.into(), - border_width: 0.0, - border_color: Color::TRANSPARENT, + border: Border::with_radius(2), }, } } @@ -1013,14 +1017,10 @@ impl scrollable::StyleSheet for Theme { scrollable::Scrollbar { background: Some(palette.background.weak.color.into()), - border_radius: 2.0.into(), - border_width: 0.0, - border_color: Color::TRANSPARENT, + border: Border::with_radius(2), scroller: scrollable::Scroller { color: palette.primary.strong.color, - border_radius: 2.0.into(), - border_width: 0.0, - border_color: Color::TRANSPARENT, + border: Border::with_radius(2), }, } } else { @@ -1120,9 +1120,11 @@ impl text_input::StyleSheet for Theme { text_input::Appearance { background: palette.background.base.color.into(), - border_radius: 2.0.into(), - border_width: 1.0, - border_color: palette.background.strong.color, + border: Border { + radius: 2.0.into(), + width: 1.0, + color: palette.background.strong.color, + }, icon_color: palette.background.weak.text, } } @@ -1136,9 +1138,11 @@ impl text_input::StyleSheet for Theme { text_input::Appearance { background: palette.background.base.color.into(), - border_radius: 2.0.into(), - border_width: 1.0, - border_color: palette.background.base.text, + border: Border { + radius: 2.0.into(), + width: 1.0, + color: palette.background.base.text, + }, icon_color: palette.background.weak.text, } } @@ -1152,9 +1156,11 @@ impl text_input::StyleSheet for Theme { text_input::Appearance { background: palette.background.base.color.into(), - border_radius: 2.0.into(), - border_width: 1.0, - border_color: palette.primary.strong.color, + border: Border { + radius: 2.0.into(), + width: 1.0, + color: palette.primary.strong.color, + }, icon_color: palette.background.weak.text, } } @@ -1198,9 +1204,11 @@ impl text_input::StyleSheet for Theme { text_input::Appearance { background: palette.background.weak.color.into(), - border_radius: 2.0.into(), - border_width: 1.0, - border_color: palette.background.strong.color, + border: Border { + radius: 2.0.into(), + width: 1.0, + color: palette.background.strong.color, + }, icon_color: palette.background.strong.color, } } @@ -1236,9 +1244,11 @@ impl text_editor::StyleSheet for Theme { text_editor::Appearance { background: palette.background.base.color.into(), - border_radius: 2.0.into(), - border_width: 1.0, - border_color: palette.background.strong.color, + border: Border { + radius: 2.0.into(), + width: 1.0, + color: palette.background.strong.color, + }, } } @@ -1251,9 +1261,11 @@ impl text_editor::StyleSheet for Theme { text_editor::Appearance { background: palette.background.base.color.into(), - border_radius: 2.0.into(), - border_width: 1.0, - border_color: palette.background.base.text, + border: Border { + radius: 2.0.into(), + width: 1.0, + color: palette.background.base.text, + }, } } @@ -1266,9 +1278,11 @@ impl text_editor::StyleSheet for Theme { text_editor::Appearance { background: palette.background.base.color.into(), - border_radius: 2.0.into(), - border_width: 1.0, - border_color: palette.primary.strong.color, + border: Border { + radius: 2.0.into(), + width: 1.0, + color: palette.primary.strong.color, + }, } } @@ -1311,9 +1325,11 @@ impl text_editor::StyleSheet for Theme { text_editor::Appearance { background: palette.background.weak.color.into(), - border_radius: 2.0.into(), - border_width: 1.0, - border_color: palette.background.strong.color, + border: Border { + radius: 2.0.into(), + width: 1.0, + color: palette.background.strong.color, + }, } } |