summaryrefslogtreecommitdiffstats
path: root/examples/stopwatch
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/stopwatch
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/stopwatch')
-rw-r--r--examples/stopwatch/src/main.rs56
1 files changed, 18 insertions, 38 deletions
diff --git a/examples/stopwatch/src/main.rs b/examples/stopwatch/src/main.rs
index 377d7a2d..b83b92ec 100644
--- a/examples/stopwatch/src/main.rs
+++ b/examples/stopwatch/src/main.rs
@@ -1,7 +1,13 @@
+use iced::alignment;
+use iced::button;
+use iced::executor;
+use iced::theme::{self, Theme};
+use iced::time;
use iced::{
- alignment, button, executor, time, Alignment, Application, Button, Column,
- Command, Container, Element, Length, Row, Settings, Subscription, Text,
+ Alignment, Application, Button, Column, Command, Container, Element,
+ Length, Row, Settings, Subscription, Text,
};
+
use std::time::{Duration, Instant};
pub fn main() -> iced::Result {
@@ -28,8 +34,9 @@ enum Message {
}
impl Application for Stopwatch {
- type Executor = executor::Default;
type Message = Message;
+ type Theme = Theme;
+ type Executor = executor::Default;
type Flags = ();
fn new(_flags: ()) -> (Stopwatch, Command<Message>) {
@@ -99,7 +106,7 @@ impl Application for Stopwatch {
))
.size(40);
- let button = |state, label, style| {
+ let button = |state, label| {
Button::new(
state,
Text::new(label)
@@ -107,21 +114,20 @@ impl Application for Stopwatch {
)
.padding(10)
.width(Length::Units(80))
- .style(style)
};
let toggle_button = {
- let (label, color) = match self.state {
- State::Idle => ("Start", style::Button::Primary),
- State::Ticking { .. } => ("Stop", style::Button::Destructive),
+ let label = match self.state {
+ State::Idle => "Start",
+ State::Ticking { .. } => "Stop",
};
- button(&mut self.toggle, label, color).on_press(Message::Toggle)
+ button(&mut self.toggle, label).on_press(Message::Toggle)
};
- let reset_button =
- button(&mut self.reset, "Reset", style::Button::Secondary)
- .on_press(Message::Reset);
+ let reset_button = button(&mut self.reset, "Reset")
+ .style(theme::Button::Destructive)
+ .on_press(Message::Reset);
let controls = Row::new()
.spacing(20)
@@ -142,29 +148,3 @@ impl Application for Stopwatch {
.into()
}
}
-
-mod style {
- use iced::{button, Background, Color, Vector};
-
- pub enum Button {
- Primary,
- Secondary,
- Destructive,
- }
-
- impl button::StyleSheet for Button {
- fn active(&self) -> button::Style {
- button::Style {
- background: Some(Background::Color(match self {
- Button::Primary => Color::from_rgb(0.11, 0.42, 0.87),
- Button::Secondary => Color::from_rgb(0.5, 0.5, 0.5),
- Button::Destructive => Color::from_rgb(0.8, 0.2, 0.2),
- })),
- border_radius: 12.0,
- shadow_offset: Vector::new(1.0, 1.0),
- text_color: Color::WHITE,
- ..button::Style::default()
- }
- }
- }
-}