summaryrefslogtreecommitdiffstats
path: root/examples/todos
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 /examples/todos
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 'examples/todos')
-rw-r--r--examples/todos/src/main.rs64
1 files changed, 6 insertions, 58 deletions
diff --git a/examples/todos/src/main.rs b/examples/todos/src/main.rs
index 0b889407..453cddc3 100644
--- a/examples/todos/src/main.rs
+++ b/examples/todos/src/main.rs
@@ -2,6 +2,7 @@ use iced::alignment::{self, Alignment};
use iced::button::{self, Button};
use iced::scrollable::{self, Scrollable};
use iced::text_input::{self, TextInput};
+use iced::theme::{self, Theme};
use iced::{
Application, Checkbox, Column, Command, Container, Element, Font, Length,
Row, Settings, Text,
@@ -42,6 +43,7 @@ enum Message {
impl Application for Todos {
type Executor = iced::executor::Default;
+ type Theme = Theme;
type Message = Message;
type Flags = ();
@@ -304,7 +306,7 @@ impl Task {
Button::new(edit_button, edit_icon())
.on_press(TaskMessage::Edit)
.padding(10)
- .style(style::Button::Icon),
+ .style(theme::Button::Text),
)
.into()
}
@@ -335,7 +337,7 @@ impl Task {
)
.on_press(TaskMessage::Delete)
.padding(10)
- .style(style::Button::Destructive),
+ .style(theme::Button::Destructive),
)
.into()
}
@@ -364,9 +366,9 @@ impl Controls {
let label = Text::new(label).size(16);
let button =
Button::new(state, label).style(if filter == current_filter {
- style::Button::FilterSelected
+ theme::Button::Primary
} else {
- style::Button::FilterActive
+ theme::Button::Text
});
button.on_press(Message::FilterChanged(filter)).padding(8)
@@ -599,57 +601,3 @@ impl SavedState {
Ok(())
}
}
-
-mod style {
- use iced::{button, Background, Color, Vector};
-
- pub enum Button {
- FilterActive,
- FilterSelected,
- Icon,
- Destructive,
- }
-
- impl button::StyleSheet for Button {
- fn active(&self) -> button::Style {
- match self {
- Button::FilterActive => button::Style::default(),
- Button::FilterSelected => button::Style {
- background: Some(Background::Color(Color::from_rgb(
- 0.2, 0.2, 0.7,
- ))),
- border_radius: 10.0,
- text_color: Color::WHITE,
- ..button::Style::default()
- },
- Button::Icon => button::Style {
- text_color: Color::from_rgb(0.5, 0.5, 0.5),
- ..button::Style::default()
- },
- Button::Destructive => button::Style {
- background: Some(Background::Color(Color::from_rgb(
- 0.8, 0.2, 0.2,
- ))),
- border_radius: 5.0,
- text_color: Color::WHITE,
- shadow_offset: Vector::new(1.0, 1.0),
- ..button::Style::default()
- },
- }
- }
-
- fn hovered(&self) -> button::Style {
- let active = self.active();
-
- button::Style {
- text_color: match self {
- Button::Icon => Color::from_rgb(0.2, 0.2, 0.7),
- Button::FilterActive => Color::from_rgb(0.2, 0.2, 0.7),
- _ => active.text_color,
- },
- shadow_offset: active.shadow_offset + Vector::new(0.0, 1.0),
- ..active
- }
- }
- }
-}