summaryrefslogtreecommitdiffstats
path: root/style/src
diff options
context:
space:
mode:
Diffstat (limited to 'style/src')
-rw-r--r--style/src/button.rs3
-rw-r--r--style/src/lib.rs3
-rw-r--r--style/src/pane_grid.rs38
-rw-r--r--style/src/text.rs20
-rw-r--r--style/src/theme.rs67
5 files changed, 82 insertions, 49 deletions
diff --git a/style/src/button.rs b/style/src/button.rs
index a564a2b7..32ec28b7 100644
--- a/style/src/button.rs
+++ b/style/src/button.rs
@@ -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/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/pane_grid.rs b/style/src/pane_grid.rs
index fd8fc05f..c1002725 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, 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: f32,
}
/// 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 [`Region`] 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/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/theme.rs b/style/src/theme.rs
index 6711fd72..9500fe9d 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;
@@ -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,
@@ -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,7 +382,7 @@ impl container::StyleSheet for Theme {
container::Appearance {
text_color: None,
- background: palette.background.weak.color.into(),
+ background: Some(palette.background.weak.color.into()),
border_radius: 2.0,
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 {
@@ -703,6 +717,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,
+ }
+ }
+ PaneGrid::Custom(custom) => custom.hovered_region(self),
+ }
+ }
+
fn picked_split(&self, style: &Self::Style) -> Option<pane_grid::Line> {
match style {
PaneGrid::Default => {
@@ -746,8 +779,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))
}
}
@@ -777,7 +812,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 {
@@ -795,8 +830,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))
}
}
@@ -819,7 +854,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 {
@@ -893,7 +928,7 @@ impl scrollable::StyleSheet for Theme {
let palette = self.extended_palette();
scrollable::Scrollbar {
- background: palette.background.weak.color.into(),
+ background: Some(palette.background.weak.color.into()),
border_radius: 2.0,
border_width: 0.0,
border_color: Color::TRANSPARENT,
@@ -920,7 +955,7 @@ impl scrollable::StyleSheet for Theme {
let palette = self.extended_palette();
scrollable::Scrollbar {
- background: palette.background.weak.color.into(),
+ background: Some(palette.background.weak.color.into()),
border_radius: 2.0,
border_width: 0.0,
border_color: Color::TRANSPARENT,