summaryrefslogtreecommitdiffstats
path: root/examples/game_of_life
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/game_of_life
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/game_of_life')
-rw-r--r--examples/game_of_life/src/main.rs8
-rw-r--r--examples/game_of_life/src/style.rs69
2 files changed, 6 insertions, 71 deletions
diff --git a/examples/game_of_life/src/main.rs b/examples/game_of_life/src/main.rs
index ab8b80e4..3e9c24a0 100644
--- a/examples/game_of_life/src/main.rs
+++ b/examples/game_of_life/src/main.rs
@@ -8,6 +8,7 @@ use iced::button::{self, Button};
use iced::executor;
use iced::pick_list::{self, PickList};
use iced::slider::{self, Slider};
+use iced::theme::{self, Theme};
use iced::time;
use iced::window;
use iced::{
@@ -55,6 +56,7 @@ enum Message {
impl Application for GameOfLife {
type Message = Message;
+ type Theme = Theme;
type Executor = executor::Default;
type Flags = ();
@@ -836,12 +838,12 @@ impl Controls {
Text::new(if is_playing { "Pause" } else { "Play" }),
)
.on_press(Message::TogglePlayback)
- .style(style::Button),
+ .style(theme::Button::Primary),
)
.push(
Button::new(&mut self.next_button, Text::new("Next"))
.on_press(Message::Next)
- .style(style::Button),
+ .style(theme::Button::Secondary),
);
let speed_controls = Row::new()
@@ -885,7 +887,7 @@ impl Controls {
.push(
Button::new(&mut self.clear_button, Text::new("Clear"))
.on_press(Message::Clear)
- .style(style::Clear),
+ .style(theme::Button::Destructive),
)
.into()
}
diff --git a/examples/game_of_life/src/style.rs b/examples/game_of_life/src/style.rs
index be9a0e96..688635e0 100644
--- a/examples/game_of_life/src/style.rs
+++ b/examples/game_of_life/src/style.rs
@@ -1,4 +1,4 @@
-use iced::{button, container, pick_list, slider, Background, Color};
+use iced::{container, pick_list, slider, Background, Color};
const ACTIVE: Color = Color::from_rgb(
0x72 as f32 / 255.0,
@@ -6,12 +6,6 @@ const ACTIVE: Color = Color::from_rgb(
0xDA as f32 / 255.0,
);
-const DESTRUCTIVE: Color = Color::from_rgb(
- 0xC0 as f32 / 255.0,
- 0x47 as f32 / 255.0,
- 0x47 as f32 / 255.0,
-);
-
const HOVERED: Color = Color::from_rgb(
0x67 as f32 / 255.0,
0x7B as f32 / 255.0,
@@ -38,67 +32,6 @@ impl container::StyleSheet for Container {
}
}
-pub struct Button;
-
-impl button::StyleSheet for Button {
- fn active(&self) -> button::Style {
- button::Style {
- background: Some(Background::Color(ACTIVE)),
- border_radius: 3.0,
- text_color: Color::WHITE,
- ..button::Style::default()
- }
- }
-
- fn hovered(&self) -> button::Style {
- button::Style {
- background: Some(Background::Color(HOVERED)),
- text_color: Color::WHITE,
- ..self.active()
- }
- }
-
- fn pressed(&self) -> button::Style {
- button::Style {
- border_width: 1.0,
- border_color: Color::WHITE,
- ..self.hovered()
- }
- }
-}
-
-pub struct Clear;
-
-impl button::StyleSheet for Clear {
- fn active(&self) -> button::Style {
- button::Style {
- background: Some(Background::Color(DESTRUCTIVE)),
- border_radius: 3.0,
- text_color: Color::WHITE,
- ..button::Style::default()
- }
- }
-
- fn hovered(&self) -> button::Style {
- button::Style {
- background: Some(Background::Color(Color {
- a: 0.5,
- ..DESTRUCTIVE
- })),
- text_color: Color::WHITE,
- ..self.active()
- }
- }
-
- fn pressed(&self) -> button::Style {
- button::Style {
- border_width: 1.0,
- border_color: Color::WHITE,
- ..self.hovered()
- }
- }
-}
-
pub struct Slider;
impl slider::StyleSheet for Slider {