summaryrefslogtreecommitdiffstats
path: root/style/src/button.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-05-14 01:47:55 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-05-14 01:56:32 +0200
commit664251f3f5c7b76f69a97683af1468094bba887f (patch)
treef43a495036ed117ce5dbb479c62652d872a6d273 /style/src/button.rs
parent5de337f214530faab1d5fe47784afd7006c3f7f0 (diff)
downloadiced-664251f3f5c7b76f69a97683af1468094bba887f.tar.gz
iced-664251f3f5c7b76f69a97683af1468094bba887f.tar.bz2
iced-664251f3f5c7b76f69a97683af1468094bba887f.zip
Draft first-class `Theme` support
RFC: https://github.com/iced-rs/rfcs/pull/6
Diffstat (limited to 'style/src/button.rs')
-rw-r--r--style/src/button.rs46
1 files changed, 9 insertions, 37 deletions
diff --git a/style/src/button.rs b/style/src/button.rs
index de2de4f4..9f00185c 100644
--- a/style/src/button.rs
+++ b/style/src/button.rs
@@ -27,10 +27,12 @@ impl std::default::Default for Style {
/// A set of rules that dictate the style of a button.
pub trait StyleSheet {
- fn active(&self) -> Style;
+ type Variant;
- fn hovered(&self) -> Style {
- let active = self.active();
+ fn active(&self, variant: Self::Variant) -> Style;
+
+ fn hovered(&self, variant: Self::Variant) -> Style {
+ let active = self.active(variant);
Style {
shadow_offset: active.shadow_offset + Vector::new(0.0, 1.0),
@@ -38,15 +40,15 @@ pub trait StyleSheet {
}
}
- fn pressed(&self) -> Style {
+ fn pressed(&self, variant: Self::Variant) -> Style {
Style {
shadow_offset: Vector::default(),
- ..self.active()
+ ..self.active(variant)
}
}
- fn disabled(&self) -> Style {
- let active = self.active();
+ fn disabled(&self, variant: Self::Variant) -> Style {
+ let active = self.active(variant);
Style {
shadow_offset: Vector::default(),
@@ -64,33 +66,3 @@ pub trait StyleSheet {
}
}
}
-
-struct Default;
-
-impl StyleSheet for Default {
- fn active(&self) -> Style {
- Style {
- shadow_offset: Vector::new(0.0, 0.0),
- background: Some(Background::Color([0.87, 0.87, 0.87].into())),
- border_radius: 2.0,
- border_width: 1.0,
- border_color: [0.7, 0.7, 0.7].into(),
- text_color: Color::BLACK,
- }
- }
-}
-
-impl<'a> std::default::Default for Box<dyn StyleSheet + 'a> {
- fn default() -> Self {
- Box::new(Default)
- }
-}
-
-impl<'a, T> From<T> for Box<dyn StyleSheet + 'a>
-where
- T: StyleSheet + 'a,
-{
- fn from(style_sheet: T) -> Self {
- Box::new(style_sheet)
- }
-}