summaryrefslogtreecommitdiffstats
path: root/style/src/theme.rs
diff options
context:
space:
mode:
Diffstat (limited to 'style/src/theme.rs')
-rw-r--r--style/src/theme.rs104
1 files changed, 70 insertions, 34 deletions
diff --git a/style/src/theme.rs b/style/src/theme.rs
index d9893bcf..64497181 100644
--- a/style/src/theme.rs
+++ b/style/src/theme.rs
@@ -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;
@@ -146,7 +157,7 @@ impl button::StyleSheet for Theme {
let palette = self.extended_palette();
let appearance = button::Appearance {
- border_radius: 2.0,
+ border_radius: 2.0.into(),
..button::Appearance::default()
};
@@ -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,
@@ -332,7 +346,7 @@ fn checkbox_appearance(
base.color
}),
icon_color,
- border_radius: 2.0,
+ border_radius: 2.0.into(),
border_width: 1.0,
border_color: accent.color,
text_color: None,
@@ -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,8 +382,8 @@ impl container::StyleSheet for Theme {
container::Appearance {
text_color: None,
- background: palette.background.weak.color.into(),
- border_radius: 2.0,
+ background: Some(palette.background.weak.color.into()),
+ border_radius: 2.0.into(),
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 {
@@ -408,7 +422,7 @@ impl slider::StyleSheet for Theme {
let handle = slider::Handle {
shape: slider::HandleShape::Rectangle {
width: 8,
- border_radius: 4.0,
+ border_radius: 4.0.into(),
},
color: Color::WHITE,
border_color: Color::WHITE,
@@ -419,9 +433,10 @@ impl slider::StyleSheet for Theme {
rail: slider::Rail {
colors: (
palette.primary.base.color,
- palette.primary.base.color,
+ palette.secondary.base.color,
),
- width: 2.0,
+ width: 4.0,
+ border_radius: 2.0.into(),
},
handle: slider::Handle {
color: palette.background.base.color,
@@ -493,7 +508,7 @@ impl menu::StyleSheet for Theme {
text_color: palette.background.weak.text,
background: palette.background.weak.color.into(),
border_width: 1.0,
- border_radius: 0.0,
+ border_radius: 0.0.into(),
border_color: palette.background.strong.color,
selected_text_color: palette.primary.strong.text,
selected_background: palette.primary.strong.color.into(),
@@ -539,7 +554,7 @@ 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,
+ border_radius: 2.0.into(),
border_width: 1.0,
border_color: palette.background.strong.color,
}
@@ -558,7 +573,7 @@ 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,
+ border_radius: 2.0.into(),
border_width: 1.0,
border_color: palette.primary.strong.color,
}
@@ -703,6 +718,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.into(),
+ }
+ }
+ PaneGrid::Custom(custom) => custom.hovered_region(self),
+ }
+ }
+
fn picked_split(&self, style: &Self::Style) -> Option<pane_grid::Line> {
match style {
PaneGrid::Default => {
@@ -746,8 +780,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))
}
}
@@ -765,7 +801,7 @@ impl progress_bar::StyleSheet for Theme {
let from_palette = |bar: Color| progress_bar::Appearance {
background: palette.background.strong.color.into(),
bar: bar.into(),
- border_radius: 2.0,
+ border_radius: 2.0.into(),
};
match style {
@@ -777,7 +813,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 +831,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))
}
}
@@ -811,7 +847,7 @@ impl rule::StyleSheet for Theme {
Rule::Default => rule::Appearance {
color: palette.background.strong.color,
width: 1,
- radius: 0.0,
+ radius: 0.0.into(),
fill_mode: rule::FillMode::Full,
},
Rule::Custom(custom) => custom.appearance(self),
@@ -819,7 +855,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,13 +929,13 @@ impl scrollable::StyleSheet for Theme {
let palette = self.extended_palette();
scrollable::Scrollbar {
- background: palette.background.weak.color.into(),
- border_radius: 2.0,
+ background: Some(palette.background.weak.color.into()),
+ border_radius: 2.0.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
scroller: scrollable::Scroller {
color: palette.background.strong.color,
- border_radius: 2.0,
+ border_radius: 2.0.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
},
@@ -920,13 +956,13 @@ impl scrollable::StyleSheet for Theme {
let palette = self.extended_palette();
scrollable::Scrollbar {
- background: palette.background.weak.color.into(),
- border_radius: 2.0,
+ background: Some(palette.background.weak.color.into()),
+ border_radius: 2.0.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
scroller: scrollable::Scroller {
color: palette.primary.strong.color,
- border_radius: 2.0,
+ border_radius: 2.0.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
},
@@ -1028,7 +1064,7 @@ impl text_input::StyleSheet for Theme {
text_input::Appearance {
background: palette.background.base.color.into(),
- border_radius: 2.0,
+ border_radius: 2.0.into(),
border_width: 1.0,
border_color: palette.background.strong.color,
icon_color: palette.background.weak.text,
@@ -1044,7 +1080,7 @@ impl text_input::StyleSheet for Theme {
text_input::Appearance {
background: palette.background.base.color.into(),
- border_radius: 2.0,
+ border_radius: 2.0.into(),
border_width: 1.0,
border_color: palette.background.base.text,
icon_color: palette.background.weak.text,
@@ -1060,7 +1096,7 @@ impl text_input::StyleSheet for Theme {
text_input::Appearance {
background: palette.background.base.color.into(),
- border_radius: 2.0,
+ border_radius: 2.0.into(),
border_width: 1.0,
border_color: palette.primary.strong.color,
icon_color: palette.background.weak.text,
@@ -1106,7 +1142,7 @@ impl text_input::StyleSheet for Theme {
text_input::Appearance {
background: palette.background.weak.color.into(),
- border_radius: 2.0,
+ border_radius: 2.0.into(),
border_width: 1.0,
border_color: palette.background.strong.color,
icon_color: palette.background.strong.color,