summaryrefslogtreecommitdiffstats
path: root/style
diff options
context:
space:
mode:
Diffstat (limited to 'style')
-rw-r--r--style/Cargo.toml7
-rw-r--r--style/src/button.rs14
-rw-r--r--style/src/checkbox.rs10
-rw-r--r--style/src/container.rs12
-rw-r--r--style/src/lib.rs4
-rw-r--r--style/src/menu.rs4
-rw-r--r--style/src/pane_grid.rs51
-rw-r--r--style/src/pick_list.rs10
-rw-r--r--style/src/progress_bar.rs6
-rw-r--r--style/src/radio.rs6
-rw-r--r--style/src/rule.rs22
-rw-r--r--style/src/scrollable.rs16
-rw-r--r--style/src/slider.rs10
-rw-r--r--style/src/text_input.rs12
-rw-r--r--style/src/toggler.rs57
15 files changed, 180 insertions, 61 deletions
diff --git a/style/Cargo.toml b/style/Cargo.toml
index abc64c0f..a3086477 100644
--- a/style/Cargo.toml
+++ b/style/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "iced_style"
-version = "0.1.0"
+version = "0.3.0"
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
edition = "2018"
description = "The default set of styles of Iced"
@@ -10,5 +10,6 @@ documentation = "https://docs.rs/iced_style"
keywords = ["gui", "ui", "graphics", "interface", "widgets"]
categories = ["gui"]
-[dependencies]
-iced_core = { version = "0.2", path = "../core" }
+[dependencies.iced_core]
+version = "0.4"
+path = "../core"
diff --git a/style/src/button.rs b/style/src/button.rs
index 1e3844f9..2281e32f 100644
--- a/style/src/button.rs
+++ b/style/src/button.rs
@@ -2,12 +2,12 @@
use iced_core::{Background, Color, Vector};
/// The appearance of a button.
-#[derive(Debug)]
+#[derive(Debug, Clone, Copy)]
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..566136bb 100644
--- a/style/src/checkbox.rs
+++ b/style/src/checkbox.rs
@@ -2,12 +2,12 @@
use iced_core::{Background, Color};
/// The appearance of a checkbox.
-#[derive(Debug)]
+#[derive(Debug, Clone, Copy)]
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 3d23d990..08d9f044 100644
--- a/style/src/lib.rs
+++ b/style/src/lib.rs
@@ -2,12 +2,15 @@
//!
//! It contains a set of styles and stylesheets for most of the built-in
//! widgets.
+//!
+//! ![The foundations of the Iced ecosystem](https://github.com/hecrj/iced/blob/0525d76ff94e828b7b21634fa94a747022001c83/docs/graphs/foundations.png?raw=true)
pub use iced_core::{Background, Color};
pub mod button;
pub mod checkbox;
pub mod container;
pub mod menu;
+pub mod pane_grid;
pub mod pick_list;
pub mod progress_bar;
pub mod radio;
@@ -15,3 +18,4 @@ pub mod rule;
pub mod scrollable;
pub mod slider;
pub mod text_input;
+pub mod toggler;
diff --git a/style/src/menu.rs b/style/src/menu.rs
index e8321dc7..90985b8f 100644
--- a/style/src/menu.rs
+++ b/style/src/menu.rs
@@ -5,7 +5,7 @@ use iced_core::{Background, Color};
pub struct Style {
pub text_color: Color,
pub background: Background,
- pub border_width: u16,
+ pub border_width: f32,
pub border_color: Color,
pub selected_text_color: Color,
pub selected_background: Background,
@@ -16,7 +16,7 @@ impl std::default::Default for Style {
Self {
text_color: Color::BLACK,
background: Background::Color([0.87, 0.87, 0.87].into()),
- border_width: 1,
+ 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/pane_grid.rs b/style/src/pane_grid.rs
new file mode 100644
index 00000000..e39ee797
--- /dev/null
+++ b/style/src/pane_grid.rs
@@ -0,0 +1,51 @@
+//! Let your users split regions of your application and organize layout
+//! dynamically.
+use iced_core::Color;
+
+/// A set of rules that dictate the style of a container.
+pub trait StyleSheet {
+ /// The [`Line`] to draw when a split is picked.
+ fn picked_split(&self) -> Option<Line>;
+
+ /// The [`Line`] to draw when a split is hovered.
+ fn hovered_split(&self) -> Option<Line>;
+}
+
+/// A line.
+///
+/// It is normally used to define the highlight of something, like a split.
+#[derive(Debug, Clone, Copy, PartialEq)]
+pub struct Line {
+ /// The [`Color`] of the [`Line`].
+ pub color: Color,
+
+ /// The width of the [`Line`].
+ pub width: f32,
+}
+
+struct Default;
+
+impl StyleSheet for Default {
+ fn picked_split(&self) -> Option<Line> {
+ None
+ }
+
+ fn hovered_split(&self) -> Option<Line> {
+ None
+ }
+}
+
+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/pick_list.rs b/style/src/pick_list.rs
index fbd431c0..d1801e5f 100644
--- a/style/src/pick_list.rs
+++ b/style/src/pick_list.rs
@@ -5,9 +5,10 @@ use iced_core::{Background, Color};
#[derive(Debug, Clone, Copy)]
pub struct Style {
pub text_color: Color,
+ pub placeholder_color: Color,
pub background: Background,
- pub border_radius: u16,
- pub border_width: u16,
+ pub border_radius: f32,
+ pub border_width: f32,
pub border_color: Color,
pub icon_size: f32,
}
@@ -16,9 +17,10 @@ impl std::default::Default for Style {
fn default() -> Self {
Self {
text_color: Color::BLACK,
+ placeholder_color: [0.4, 0.4, 0.4].into(),
background: Background::Color([0.87, 0.87, 0.87].into()),
- border_radius: 0,
- border_width: 1,
+ border_radius: 0.0,
+ border_width: 1.0,
border_color: [0.7, 0.7, 0.7].into(),
icon_size: 0.7,
}
diff --git a/style/src/progress_bar.rs b/style/src/progress_bar.rs
index 73503fa8..d0878c84 100644
--- a/style/src/progress_bar.rs
+++ b/style/src/progress_bar.rs
@@ -2,11 +2,11 @@
use iced_core::{Background, Color};
/// The appearance of a progress bar.
-#[derive(Debug)]
+#[derive(Debug, Clone, Copy)]
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..c41b70c0 100644
--- a/style/src/radio.rs
+++ b/style/src/radio.rs
@@ -2,11 +2,11 @@
use iced_core::{Background, Color};
/// The appearance of a radio button.
-#[derive(Debug)]
+#[derive(Debug, Clone, Copy)]
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
index 6ba54e33..be4c86d1 100644
--- a/style/src/rule.rs
+++ b/style/src/rule.rs
@@ -74,13 +74,22 @@ pub struct Style {
/// The width (thickness) of the rule line.
pub width: u16,
/// The radius of the line corners.
- pub radius: u16,
+ pub radius: f32,
/// The [`FillMode`] of the rule.
- ///
- /// [`FillMode`]: enum.FillMode.html
pub fill_mode: FillMode,
}
+impl std::default::Default for Style {
+ fn default() -> Self {
+ Style {
+ color: [0.6, 0.6, 0.6, 0.51].into(),
+ width: 1,
+ radius: 0.0,
+ fill_mode: FillMode::Percent(90.0),
+ }
+ }
+}
+
/// A set of rules that dictate the style of a rule.
pub trait StyleSheet {
/// Produces the style of a rule.
@@ -91,12 +100,7 @@ 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,
- fill_mode: FillMode::Percent(90.0),
- }
+ Style::default()
}
}
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 1cb72364..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,
}
}
@@ -47,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),
}
}
diff --git a/style/src/toggler.rs b/style/src/toggler.rs
new file mode 100644
index 00000000..5a155123
--- /dev/null
+++ b/style/src/toggler.rs
@@ -0,0 +1,57 @@
+//! Show toggle controls using togglers.
+use iced_core::Color;
+
+/// The appearance of a toggler.
+#[derive(Debug)]
+pub struct Style {
+ pub background: Color,
+ pub background_border: Option<Color>,
+ pub foreground: Color,
+ pub foreground_border: Option<Color>,
+}
+
+/// A set of rules that dictate the style of a toggler.
+pub trait StyleSheet {
+ fn active(&self, is_active: bool) -> Style;
+
+ fn hovered(&self, is_active: bool) -> Style;
+}
+
+struct Default;
+
+impl StyleSheet for Default {
+ fn active(&self, is_active: bool) -> Style {
+ Style {
+ background: if is_active {
+ Color::from_rgb(0.0, 1.0, 0.0)
+ } else {
+ Color::from_rgb(0.7, 0.7, 0.7)
+ },
+ background_border: None,
+ foreground: Color::WHITE,
+ foreground_border: None,
+ }
+ }
+
+ fn hovered(&self, is_active: bool) -> Style {
+ Style {
+ foreground: Color::from_rgb(0.95, 0.95, 0.95),
+ ..self.active(is_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)
+ }
+}