diff options
Diffstat (limited to 'style')
-rw-r--r-- | style/Cargo.toml | 4 | ||||
-rw-r--r-- | style/src/button.rs | 12 | ||||
-rw-r--r-- | style/src/checkbox.rs | 8 | ||||
-rw-r--r-- | style/src/container.rs | 12 | ||||
-rw-r--r-- | style/src/lib.rs | 7 | ||||
-rw-r--r-- | style/src/menu.rs | 25 | ||||
-rw-r--r-- | style/src/pick_list.rs | 70 | ||||
-rw-r--r-- | style/src/progress_bar.rs | 4 | ||||
-rw-r--r-- | style/src/radio.rs | 4 | ||||
-rw-r--r-- | style/src/rule.rs | 114 | ||||
-rw-r--r-- | style/src/scrollable.rs | 16 | ||||
-rw-r--r-- | style/src/slider.rs | 10 | ||||
-rw-r--r-- | style/src/text_input.rs | 18 |
13 files changed, 263 insertions, 41 deletions
diff --git a/style/Cargo.toml b/style/Cargo.toml index 5928c60d..ac16f8ee 100644 --- a/style/Cargo.toml +++ b/style/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "iced_style" -version = "0.1.0-alpha" +version = "0.2.0" authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"] edition = "2018" description = "The default set of styles of Iced" @@ -11,4 +11,4 @@ keywords = ["gui", "ui", "graphics", "interface", "widgets"] categories = ["gui"] [dependencies] -iced_core = { version = "0.1.0", path = "../core" } +iced_core = { version = "0.3", path = "../core" } diff --git a/style/src/button.rs b/style/src/button.rs index 1e3844f9..43d27216 100644 --- a/style/src/button.rs +++ b/style/src/button.rs @@ -6,8 +6,8 @@ use iced_core::{Background, Color, Vector}; pub struct Style { pub shadow_offset: Vector, pub background: Option<Background>, - pub border_radius: u16, - pub border_width: u16, + pub border_radius: f32, + pub border_width: f32, pub border_color: Color, pub text_color: Color, } @@ -17,8 +17,8 @@ impl std::default::Default for Style { Self { shadow_offset: Vector::default(), background: None, - border_radius: 0, - border_width: 0, + border_radius: 0.0, + border_width: 0.0, border_color: Color::TRANSPARENT, text_color: Color::BLACK, } @@ -72,8 +72,8 @@ impl StyleSheet for Default { Style { shadow_offset: Vector::new(0.0, 0.0), background: Some(Background::Color([0.87, 0.87, 0.87].into())), - border_radius: 2, - border_width: 1, + border_radius: 2.0, + border_width: 1.0, border_color: [0.7, 0.7, 0.7].into(), text_color: Color::BLACK, } diff --git a/style/src/checkbox.rs b/style/src/checkbox.rs index 3c645f15..1c5f2460 100644 --- a/style/src/checkbox.rs +++ b/style/src/checkbox.rs @@ -6,8 +6,8 @@ use iced_core::{Background, Color}; pub struct Style { pub background: Background, pub checkmark_color: Color, - pub border_radius: u16, - pub border_width: u16, + pub border_radius: f32, + pub border_width: f32, pub border_color: Color, } @@ -25,8 +25,8 @@ impl StyleSheet for Default { Style { background: Background::Color(Color::from_rgb(0.95, 0.95, 0.95)), checkmark_color: Color::from_rgb(0.3, 0.3, 0.3), - border_radius: 5, - border_width: 1, + border_radius: 5.0, + border_width: 1.0, border_color: Color::from_rgb(0.6, 0.6, 0.6), } } diff --git a/style/src/container.rs b/style/src/container.rs index d2247342..1ce6a7ca 100644 --- a/style/src/container.rs +++ b/style/src/container.rs @@ -6,8 +6,8 @@ use iced_core::{Background, Color}; pub struct Style { pub text_color: Option<Color>, pub background: Option<Background>, - pub border_radius: u16, - pub border_width: u16, + pub border_radius: f32, + pub border_width: f32, pub border_color: Color, } @@ -16,8 +16,8 @@ impl std::default::Default for Style { Self { text_color: None, background: None, - border_radius: 0, - border_width: 0, + border_radius: 0.0, + border_width: 0.0, border_color: Color::TRANSPARENT, } } @@ -36,8 +36,8 @@ impl StyleSheet for Default { Style { text_color: None, background: None, - border_radius: 0, - border_width: 0, + border_radius: 0.0, + border_width: 0.0, border_color: Color::TRANSPARENT, } } diff --git a/style/src/lib.rs b/style/src/lib.rs index 2c5977b5..7e0a9f49 100644 --- a/style/src/lib.rs +++ b/style/src/lib.rs @@ -2,11 +2,18 @@ //! //! It contains a set of styles and stylesheets for most of the built-in //! widgets. +//! +//!  +pub use iced_core::{Background, Color}; + pub mod button; pub mod checkbox; pub mod container; +pub mod menu; +pub mod pick_list; pub mod progress_bar; pub mod radio; +pub mod rule; pub mod scrollable; pub mod slider; pub mod text_input; diff --git a/style/src/menu.rs b/style/src/menu.rs new file mode 100644 index 00000000..90985b8f --- /dev/null +++ b/style/src/menu.rs @@ -0,0 +1,25 @@ +use iced_core::{Background, Color}; + +/// The appearance of a menu. +#[derive(Debug, Clone, Copy)] +pub struct Style { + pub text_color: Color, + pub background: Background, + pub border_width: f32, + pub border_color: Color, + pub selected_text_color: Color, + pub selected_background: Background, +} + +impl std::default::Default for Style { + fn default() -> Self { + Self { + text_color: Color::BLACK, + background: Background::Color([0.87, 0.87, 0.87].into()), + border_width: 1.0, + border_color: [0.7, 0.7, 0.7].into(), + selected_text_color: Color::WHITE, + selected_background: Background::Color([0.4, 0.4, 1.0].into()), + } + } +} diff --git a/style/src/pick_list.rs b/style/src/pick_list.rs new file mode 100644 index 00000000..a757ba98 --- /dev/null +++ b/style/src/pick_list.rs @@ -0,0 +1,70 @@ +use crate::menu; +use iced_core::{Background, Color}; + +/// The appearance of a pick list. +#[derive(Debug, Clone, Copy)] +pub struct Style { + pub text_color: Color, + pub background: Background, + pub border_radius: f32, + pub border_width: f32, + pub border_color: Color, + pub icon_size: f32, +} + +impl std::default::Default for Style { + fn default() -> Self { + Self { + text_color: Color::BLACK, + background: Background::Color([0.87, 0.87, 0.87].into()), + border_radius: 0.0, + border_width: 1.0, + border_color: [0.7, 0.7, 0.7].into(), + icon_size: 0.7, + } + } +} + +/// A set of rules that dictate the style of a container. +pub trait StyleSheet { + fn menu(&self) -> menu::Style; + + fn active(&self) -> Style; + + /// Produces the style of a container. + fn hovered(&self) -> Style; +} + +struct Default; + +impl StyleSheet for Default { + fn menu(&self) -> menu::Style { + menu::Style::default() + } + + fn active(&self) -> Style { + Style::default() + } + + fn hovered(&self) -> Style { + Style { + border_color: Color::BLACK, + ..self.active() + } + } +} + +impl std::default::Default for Box<dyn StyleSheet> { + fn default() -> Self { + Box::new(Default) + } +} + +impl<T> From<T> for Box<dyn StyleSheet> +where + T: 'static + StyleSheet, +{ + fn from(style: T) -> Self { + Box::new(style) + } +} diff --git a/style/src/progress_bar.rs b/style/src/progress_bar.rs index 73503fa8..36be63f9 100644 --- a/style/src/progress_bar.rs +++ b/style/src/progress_bar.rs @@ -6,7 +6,7 @@ use iced_core::{Background, Color}; pub struct Style { pub background: Background, pub bar: Background, - pub border_radius: u16, + pub border_radius: f32, } /// A set of rules that dictate the style of a progress bar. @@ -21,7 +21,7 @@ impl StyleSheet for Default { Style { background: Background::Color(Color::from_rgb(0.6, 0.6, 0.6)), bar: Background::Color(Color::from_rgb(0.3, 0.9, 0.3)), - border_radius: 5, + border_radius: 5.0, } } } diff --git a/style/src/radio.rs b/style/src/radio.rs index 1f0689b9..83310e05 100644 --- a/style/src/radio.rs +++ b/style/src/radio.rs @@ -6,7 +6,7 @@ use iced_core::{Background, Color}; pub struct Style { pub background: Background, pub dot_color: Color, - pub border_width: u16, + pub border_width: f32, pub border_color: Color, } @@ -24,7 +24,7 @@ impl StyleSheet for Default { Style { background: Background::Color(Color::from_rgb(0.95, 0.95, 0.95)), dot_color: Color::from_rgb(0.3, 0.3, 0.3), - border_width: 1, + border_width: 1.0, border_color: Color::from_rgb(0.6, 0.6, 0.6), } } diff --git a/style/src/rule.rs b/style/src/rule.rs new file mode 100644 index 00000000..5021340b --- /dev/null +++ b/style/src/rule.rs @@ -0,0 +1,114 @@ +//! Display a horizontal or vertical rule for dividing content. + +use iced_core::Color; + +/// The fill mode of a rule. +#[derive(Debug, Clone, Copy)] +pub enum FillMode { + /// Fill the whole length of the container. + Full, + /// Fill a percent of the length of the container. The rule + /// will be centered in that container. + /// + /// The range is `[0.0, 100.0]`. + Percent(f32), + /// Uniform offset from each end, length units. + Padded(u16), + /// Different offset on each end of the rule, length units. + /// First = top or left. + AsymmetricPadding(u16, u16), +} + +impl FillMode { + /// Return the starting offset and length of the rule. + /// + /// * `space` - The space to fill. + /// + /// # Returns + /// + /// * (starting_offset, length) + pub fn fill(&self, space: f32) -> (f32, f32) { + match *self { + FillMode::Full => (0.0, space), + FillMode::Percent(percent) => { + if percent >= 100.0 { + (0.0, space) + } else { + let percent_width = (space * percent / 100.0).round(); + + (((space - percent_width) / 2.0).round(), percent_width) + } + } + FillMode::Padded(padding) => { + if padding == 0 { + (0.0, space) + } else { + let padding = padding as f32; + let mut line_width = space - (padding * 2.0); + if line_width < 0.0 { + line_width = 0.0; + } + + (padding, line_width) + } + } + FillMode::AsymmetricPadding(first_pad, second_pad) => { + let first_pad = first_pad as f32; + let second_pad = second_pad as f32; + let mut line_width = space - first_pad - second_pad; + if line_width < 0.0 { + line_width = 0.0; + } + + (first_pad, line_width) + } + } + } +} + +/// The appearance of a rule. +#[derive(Debug, Clone, Copy)] +pub struct Style { + /// The color of the rule. + pub color: Color, + /// The width (thickness) of the rule line. + pub width: u16, + /// The radius of the line corners. + pub radius: f32, + /// The [`FillMode`] of the rule. + pub fill_mode: FillMode, +} + +/// A set of rules that dictate the style of a rule. +pub trait StyleSheet { + /// Produces the style of a rule. + fn style(&self) -> Style; +} + +struct Default; + +impl StyleSheet for Default { + fn style(&self) -> Style { + Style { + color: [0.6, 0.6, 0.6, 0.51].into(), + width: 1, + radius: 0.0, + fill_mode: FillMode::Percent(90.0), + } + } +} + +impl std::default::Default for Box<dyn StyleSheet> { + fn default() -> Self { + Box::new(Default) + } +} + +impl<T> From<T> for Box<dyn StyleSheet> +where + T: 'static + StyleSheet, +{ + fn from(style: T) -> Self { + Box::new(style) + } +} diff --git a/style/src/scrollable.rs b/style/src/scrollable.rs index 690c14a2..65da9803 100644 --- a/style/src/scrollable.rs +++ b/style/src/scrollable.rs @@ -5,8 +5,8 @@ use iced_core::{Background, Color}; #[derive(Debug, Clone, Copy)] pub struct Scrollbar { pub background: Option<Background>, - pub border_radius: u16, - pub border_width: u16, + pub border_radius: f32, + pub border_width: f32, pub border_color: Color, pub scroller: Scroller, } @@ -15,8 +15,8 @@ pub struct Scrollbar { #[derive(Debug, Clone, Copy)] pub struct Scroller { pub color: Color, - pub border_radius: u16, - pub border_width: u16, + pub border_radius: f32, + pub border_width: f32, pub border_color: Color, } @@ -40,13 +40,13 @@ impl StyleSheet for Default { fn active(&self) -> Scrollbar { Scrollbar { background: None, - border_radius: 5, - border_width: 0, + border_radius: 5.0, + border_width: 0.0, border_color: Color::TRANSPARENT, scroller: Scroller { color: [0.0, 0.0, 0.0, 0.7].into(), - border_radius: 5, - border_width: 0, + border_radius: 5.0, + border_width: 0.0, border_color: Color::TRANSPARENT, }, } diff --git a/style/src/slider.rs b/style/src/slider.rs index 776e180c..9148fcbe 100644 --- a/style/src/slider.rs +++ b/style/src/slider.rs @@ -13,15 +13,15 @@ pub struct Style { pub struct Handle { pub shape: HandleShape, pub color: Color, - pub border_width: u16, + pub border_width: f32, pub border_color: Color, } /// The shape of the handle of a slider. #[derive(Debug, Clone, Copy)] pub enum HandleShape { - Circle { radius: u16 }, - Rectangle { width: u16, border_radius: u16 }, + Circle { radius: f32 }, + Rectangle { width: u16, border_radius: f32 }, } /// A set of rules that dictate the style of a slider. @@ -45,11 +45,11 @@ impl StyleSheet for Default { handle: Handle { shape: HandleShape::Rectangle { width: 8, - border_radius: 4, + border_radius: 4.0, }, color: Color::from_rgb(0.95, 0.95, 0.95), border_color: Color::from_rgb(0.6, 0.6, 0.6), - border_width: 1, + border_width: 1.0, }, } } diff --git a/style/src/text_input.rs b/style/src/text_input.rs index c5123b20..19acea65 100644 --- a/style/src/text_input.rs +++ b/style/src/text_input.rs @@ -5,8 +5,8 @@ use iced_core::{Background, Color}; #[derive(Debug, Clone, Copy)] pub struct Style { pub background: Background, - pub border_radius: u16, - pub border_width: u16, + pub border_radius: f32, + pub border_width: f32, pub border_color: Color, } @@ -14,8 +14,8 @@ impl std::default::Default for Style { fn default() -> Self { Self { background: Background::Color(Color::WHITE), - border_radius: 0, - border_width: 0, + border_radius: 0.0, + border_width: 0.0, border_color: Color::TRANSPARENT, } } @@ -33,6 +33,8 @@ pub trait StyleSheet { fn value_color(&self) -> Color; + fn selection_color(&self) -> Color; + /// Produces the style of an hovered text input. fn hovered(&self) -> Style { self.focused() @@ -45,8 +47,8 @@ impl StyleSheet for Default { fn active(&self) -> Style { Style { background: Background::Color(Color::WHITE), - border_radius: 5, - border_width: 1, + border_radius: 5.0, + border_width: 1.0, border_color: Color::from_rgb(0.7, 0.7, 0.7), } } @@ -65,6 +67,10 @@ impl StyleSheet for Default { fn value_color(&self) -> Color { Color::from_rgb(0.3, 0.3, 0.3) } + + fn selection_color(&self) -> Color { + Color::from_rgb(0.8, 0.8, 1.0) + } } impl std::default::Default for Box<dyn StyleSheet> { |