summaryrefslogtreecommitdiffstats
path: root/examples/todos.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-12-29 10:57:01 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-12-29 10:57:01 +0100
commitc7b170da6d180f80e539910cccb543720fa3713c (patch)
tree6ef48d17104173f0ac7182d3647bd461e5581bd2 /examples/todos.rs
parent4b86c2ff987e334c3454540828c6f8d16d27c670 (diff)
downloadiced-c7b170da6d180f80e539910cccb543720fa3713c.tar.gz
iced-c7b170da6d180f80e539910cccb543720fa3713c.tar.bz2
iced-c7b170da6d180f80e539910cccb543720fa3713c.zip
Draft `Style` and `StyleSheet` for `Button`
Diffstat (limited to 'examples/todos.rs')
-rw-r--r--examples/todos.rs51
1 files changed, 42 insertions, 9 deletions
diff --git a/examples/todos.rs b/examples/todos.rs
index 42e88f65..00edd7fb 100644
--- a/examples/todos.rs
+++ b/examples/todos.rs
@@ -296,7 +296,8 @@ impl Task {
edit_icon().color([0.5, 0.5, 0.5]),
)
.on_press(TaskMessage::Edit)
- .padding(10),
+ .padding(10)
+ .style(style::Button::NoBackground),
)
.into()
}
@@ -331,8 +332,7 @@ impl Task {
)
.on_press(TaskMessage::Delete)
.padding(10)
- .border_radius(5)
- .background(Color::from_rgb(0.8, 0.2, 0.2)),
+ .style(style::Button::Destructive),
)
.into()
}
@@ -361,15 +361,12 @@ impl Controls {
let label = Text::new(label).size(16).width(Length::Shrink);
let button = if filter == current_filter {
Button::new(state, label.color(Color::WHITE))
- .background(Color::from_rgb(0.2, 0.2, 0.7))
+ .style(style::Button::FilterSelected)
} else {
- Button::new(state, label)
+ Button::new(state, label).style(style::Button::NoBackground)
};
- button
- .on_press(Message::FilterChanged(filter))
- .padding(8)
- .border_radius(10)
+ button.on_press(Message::FilterChanged(filter)).padding(8)
};
Row::new()
@@ -562,3 +559,39 @@ impl SavedState {
Ok(())
}
}
+
+mod style {
+ use iced::{button, Background, Color};
+
+ pub enum Button {
+ FilterSelected,
+ NoBackground,
+ Destructive,
+ }
+
+ impl button::StyleSheet for Button {
+ fn active(&self) -> button::Style {
+ match self {
+ Button::FilterSelected => button::Style {
+ background: Some(Background::Color(Color::from_rgb(
+ 0.2, 0.2, 0.7,
+ ))),
+ border_radius: 10,
+ shadow_offset: 0.0,
+ },
+ Button::NoBackground => button::Style {
+ background: None,
+ border_radius: 0,
+ shadow_offset: 0.0,
+ },
+ Button::Destructive => button::Style {
+ background: Some(Background::Color(Color::from_rgb(
+ 0.8, 0.2, 0.2,
+ ))),
+ border_radius: 5,
+ shadow_offset: 1.0,
+ },
+ }
+ }
+ }
+}