summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-01-08 03:30:15 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-01-08 03:30:15 +0100
commitcae4463e8379cddefbd8322a40ad8957bce07215 (patch)
treecca5db7b0a01cceb840721c828f78c0419badaa7 /examples
parent08faaaf6234e93acb3b0dc8e10bf9c4cb266f21c (diff)
downloadiced-cae4463e8379cddefbd8322a40ad8957bce07215.tar.gz
iced-cae4463e8379cddefbd8322a40ad8957bce07215.tar.bz2
iced-cae4463e8379cddefbd8322a40ad8957bce07215.zip
Allow `Checkbox` style to change based on its state
Diffstat (limited to 'examples')
-rw-r--r--examples/styling.rs19
1 files changed, 13 insertions, 6 deletions
diff --git a/examples/styling.rs b/examples/styling.rs
index f0edfd82..59c9c734 100644
--- a/examples/styling.rs
+++ b/examples/styling.rs
@@ -493,20 +493,27 @@ mod style {
pub struct Checkbox;
impl checkbox::StyleSheet for Checkbox {
- fn active(&self) -> checkbox::Style {
+ fn active(&self, is_checked: bool) -> checkbox::Style {
checkbox::Style {
- background: Background::Color(SURFACE),
- checkmark_color: ACTIVE,
+ background: Background::Color(if is_checked {
+ ACTIVE
+ } else {
+ SURFACE
+ }),
+ checkmark_color: Color::WHITE,
border_radius: 2,
border_width: 1,
border_color: ACTIVE,
}
}
- fn hovered(&self) -> checkbox::Style {
+ fn hovered(&self, is_checked: bool) -> checkbox::Style {
checkbox::Style {
- background: Background::Color(Color { a: 0.5, ..SURFACE }),
- ..self.active()
+ background: Background::Color(Color {
+ a: 0.8,
+ ..if is_checked { ACTIVE } else { SURFACE }
+ }),
+ ..self.active(is_checked)
}
}
}