From 664251f3f5c7b76f69a97683af1468094bba887f Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 14 May 2022 01:47:55 +0200 Subject: Draft first-class `Theme` support RFC: https://github.com/iced-rs/rfcs/pull/6 --- examples/pure/game_of_life/src/main.rs | 17 ++++++-- examples/pure/game_of_life/src/style.rs | 69 +-------------------------------- 2 files changed, 14 insertions(+), 72 deletions(-) (limited to 'examples/pure/game_of_life/src') diff --git a/examples/pure/game_of_life/src/main.rs b/examples/pure/game_of_life/src/main.rs index a3164701..a3e46888 100644 --- a/examples/pure/game_of_life/src/main.rs +++ b/examples/pure/game_of_life/src/main.rs @@ -9,6 +9,7 @@ use iced::pure::{ button, checkbox, column, container, pick_list, row, slider, text, }; use iced::pure::{Application, Element}; +use iced::theme::{self, Theme}; use iced::time; use iced::window; use iced::{Alignment, Color, Command, Length, Settings, Subscription}; @@ -52,6 +53,7 @@ enum Message { impl Application for GameOfLife { type Message = Message; + type Theme = Theme; type Executor = executor::Default; type Flags = (); @@ -168,10 +170,13 @@ fn view_controls<'a>( .spacing(10) .push( button(if is_playing { "Pause" } else { "Play" }) - .on_press(Message::TogglePlayback) - .style(style::Button), + .on_press(Message::TogglePlayback), ) - .push(button("Next").on_press(Message::Next).style(style::Button)); + .push( + button("Next") + .on_press(Message::Next) + .style(theme::Button::Secondary), + ); let speed_controls = row() .width(Length::Fill) @@ -201,7 +206,11 @@ fn view_controls<'a>( .text_size(16) .style(style::PickList), ) - .push(button("Clear").on_press(Message::Clear).style(style::Clear)) + .push( + button("Clear") + .on_press(Message::Clear) + .style(theme::Button::Destructive), + ) .into() } diff --git a/examples/pure/game_of_life/src/style.rs b/examples/pure/game_of_life/src/style.rs index 1a64cf4a..dbd70c26 100644 --- a/examples/pure/game_of_life/src/style.rs +++ b/examples/pure/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, 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, @@ -35,67 +29,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 { -- cgit From 03eda9b162012c503ead649e5ccb95b7ef1d10ed Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 25 May 2022 05:01:18 +0200 Subject: Let a `Theme` control the background color of an application ... and remove `Application::background_color` --- examples/pure/game_of_life/src/main.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'examples/pure/game_of_life/src') diff --git a/examples/pure/game_of_life/src/main.rs b/examples/pure/game_of_life/src/main.rs index a3e46888..0eded2ce 100644 --- a/examples/pure/game_of_life/src/main.rs +++ b/examples/pure/game_of_life/src/main.rs @@ -12,7 +12,7 @@ use iced::pure::{Application, Element}; use iced::theme::{self, Theme}; use iced::time; use iced::window; -use iced::{Alignment, Color, Command, Length, Settings, Subscription}; +use iced::{Alignment, Command, Length, Settings, Subscription}; use preset::Preset; use std::time::{Duration, Instant}; @@ -71,10 +71,6 @@ impl Application for GameOfLife { String::from("Game of Life - Iced") } - fn background_color(&self) -> Color { - style::BACKGROUND - } - fn update(&mut self, message: Message) -> Command { match message { Message::Grid(message, version) => { -- cgit From d5bc610d0139fb331a59fc904a932d156f637391 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 26 May 2022 23:12:11 +0200 Subject: Fix examples and doc-tests --- examples/pure/game_of_life/src/main.rs | 5 +-- examples/pure/game_of_life/src/style.rs | 54 +-------------------------------- 2 files changed, 2 insertions(+), 57 deletions(-) (limited to 'examples/pure/game_of_life/src') diff --git a/examples/pure/game_of_life/src/main.rs b/examples/pure/game_of_life/src/main.rs index 0eded2ce..87c7a204 100644 --- a/examples/pure/game_of_life/src/main.rs +++ b/examples/pure/game_of_life/src/main.rs @@ -178,10 +178,7 @@ fn view_controls<'a>( .width(Length::Fill) .align_items(Alignment::Center) .spacing(10) - .push( - slider(1.0..=1000.0, speed as f32, Message::SpeedChanged) - .style(style::Slider), - ) + .push(slider(1.0..=1000.0, speed as f32, Message::SpeedChanged)) .push(text(format!("x{}", speed)).size(16)); row() diff --git a/examples/pure/game_of_life/src/style.rs b/examples/pure/game_of_life/src/style.rs index dbd70c26..773b88eb 100644 --- a/examples/pure/game_of_life/src/style.rs +++ b/examples/pure/game_of_life/src/style.rs @@ -1,16 +1,4 @@ -use iced::{container, pick_list, slider, Color}; - -const ACTIVE: Color = Color::from_rgb( - 0x72 as f32 / 255.0, - 0x89 as f32 / 255.0, - 0xDA as f32 / 255.0, -); - -const HOVERED: Color = Color::from_rgb( - 0x67 as f32 / 255.0, - 0x7B as f32 / 255.0, - 0xC4 as f32 / 255.0, -); +use iced::{container, pick_list, Color}; pub const BACKGROUND: Color = Color::from_rgb( 0x2F as f32 / 255.0, @@ -29,46 +17,6 @@ impl container::StyleSheet for Container { } } -pub struct Slider; - -impl slider::StyleSheet for Slider { - fn active(&self) -> slider::Style { - slider::Style { - rail_colors: (ACTIVE, Color { a: 0.1, ..ACTIVE }), - handle: slider::Handle { - shape: slider::HandleShape::Circle { radius: 9.0 }, - color: ACTIVE, - border_width: 0.0, - border_color: Color::TRANSPARENT, - }, - } - } - - fn hovered(&self) -> slider::Style { - let active = self.active(); - - slider::Style { - handle: slider::Handle { - color: HOVERED, - ..active.handle - }, - ..active - } - } - - fn dragging(&self) -> slider::Style { - let active = self.active(); - - slider::Style { - handle: slider::Handle { - color: Color::from_rgb(0.85, 0.85, 0.85), - ..active.handle - }, - ..active - } - } -} - pub struct PickList; impl pick_list::StyleSheet for PickList { -- cgit From 97555e67af8b4bcc77df69c5e72156e14948150e Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 7 Jun 2022 04:11:24 +0200 Subject: Implement theme styling for `Container` --- examples/pure/game_of_life/src/main.rs | 1 - examples/pure/game_of_life/src/style.rs | 13 +------------ 2 files changed, 1 insertion(+), 13 deletions(-) (limited to 'examples/pure/game_of_life/src') diff --git a/examples/pure/game_of_life/src/main.rs b/examples/pure/game_of_life/src/main.rs index 87c7a204..4db9fbc7 100644 --- a/examples/pure/game_of_life/src/main.rs +++ b/examples/pure/game_of_life/src/main.rs @@ -151,7 +151,6 @@ impl Application for GameOfLife { container(content) .width(Length::Fill) .height(Length::Fill) - .style(style::Container) .into() } } diff --git a/examples/pure/game_of_life/src/style.rs b/examples/pure/game_of_life/src/style.rs index 773b88eb..d1ca5c9b 100644 --- a/examples/pure/game_of_life/src/style.rs +++ b/examples/pure/game_of_life/src/style.rs @@ -1,4 +1,4 @@ -use iced::{container, pick_list, Color}; +use iced::{pick_list, Color}; pub const BACKGROUND: Color = Color::from_rgb( 0x2F as f32 / 255.0, @@ -6,17 +6,6 @@ pub const BACKGROUND: Color = Color::from_rgb( 0x36 as f32 / 255.0, ); -pub struct Container; - -impl container::StyleSheet for Container { - fn style(&self) -> container::Style { - container::Style { - text_color: Some(Color::WHITE), - ..container::Style::default() - } - } -} - pub struct PickList; impl pick_list::StyleSheet for PickList { -- cgit From 396735b682433928f52ba777891e14f2fbc703c7 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 7 Jun 2022 04:51:44 +0200 Subject: Implement theme styling for `PickList` and `Menu` --- examples/pure/game_of_life/src/main.rs | 4 +-- examples/pure/game_of_life/src/style.rs | 56 --------------------------------- 2 files changed, 1 insertion(+), 59 deletions(-) delete mode 100644 examples/pure/game_of_life/src/style.rs (limited to 'examples/pure/game_of_life/src') diff --git a/examples/pure/game_of_life/src/main.rs b/examples/pure/game_of_life/src/main.rs index 4db9fbc7..58528b96 100644 --- a/examples/pure/game_of_life/src/main.rs +++ b/examples/pure/game_of_life/src/main.rs @@ -1,7 +1,6 @@ //! This example showcases an interactive version of the Game of Life, invented //! by John Conway. It leverages a `Canvas` together with other widgets. mod preset; -mod style; use grid::Grid; use iced::executor; @@ -195,8 +194,7 @@ fn view_controls<'a>( .push( pick_list(preset::ALL, Some(preset), Message::PresetPicked) .padding(8) - .text_size(16) - .style(style::PickList), + .text_size(16), ) .push( button("Clear") diff --git a/examples/pure/game_of_life/src/style.rs b/examples/pure/game_of_life/src/style.rs deleted file mode 100644 index d1ca5c9b..00000000 --- a/examples/pure/game_of_life/src/style.rs +++ /dev/null @@ -1,56 +0,0 @@ -use iced::{pick_list, Color}; - -pub const BACKGROUND: Color = Color::from_rgb( - 0x2F as f32 / 255.0, - 0x31 as f32 / 255.0, - 0x36 as f32 / 255.0, -); - -pub struct PickList; - -impl pick_list::StyleSheet for PickList { - fn menu(&self) -> pick_list::Menu { - pick_list::Menu { - text_color: Color::WHITE, - background: BACKGROUND.into(), - border_width: 1.0, - border_color: Color { - a: 0.7, - ..Color::BLACK - }, - selected_background: Color { - a: 0.5, - ..Color::BLACK - } - .into(), - selected_text_color: Color::WHITE, - } - } - - fn active(&self) -> pick_list::Style { - pick_list::Style { - text_color: Color::WHITE, - background: BACKGROUND.into(), - border_width: 1.0, - border_color: Color { - a: 0.6, - ..Color::BLACK - }, - border_radius: 2.0, - icon_size: 0.5, - ..pick_list::Style::default() - } - } - - fn hovered(&self) -> pick_list::Style { - let active = self.active(); - - pick_list::Style { - border_color: Color { - a: 0.9, - ..Color::BLACK - }, - ..active - } - } -} -- cgit From f92afa795062cf38f0f99d0a1545a990ed35b09c Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 7 Jun 2022 04:57:10 +0200 Subject: Use `Theme::Dark` in `pure_game_of_life` example --- examples/pure/game_of_life/src/main.rs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'examples/pure/game_of_life/src') diff --git a/examples/pure/game_of_life/src/main.rs b/examples/pure/game_of_life/src/main.rs index 58528b96..2af139e8 100644 --- a/examples/pure/game_of_life/src/main.rs +++ b/examples/pure/game_of_life/src/main.rs @@ -152,6 +152,10 @@ impl Application for GameOfLife { .height(Length::Fill) .into() } + + fn theme(&self) -> Theme { + Theme::Dark + } } fn view_controls<'a>( -- cgit From fc13bb3d65c85cfad9f231c0776d3a45f4fbf480 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 7 Jun 2022 05:24:43 +0200 Subject: Implement theme styling for `Canvas` --- examples/pure/game_of_life/src/main.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'examples/pure/game_of_life/src') diff --git a/examples/pure/game_of_life/src/main.rs b/examples/pure/game_of_life/src/main.rs index 2af139e8..851fbd47 100644 --- a/examples/pure/game_of_life/src/main.rs +++ b/examples/pure/game_of_life/src/main.rs @@ -3,6 +3,8 @@ mod preset; use grid::Grid; +use preset::Preset; + use iced::executor; use iced::pure::{ button, checkbox, column, container, pick_list, row, slider, text, @@ -12,7 +14,6 @@ use iced::theme::{self, Theme}; use iced::time; use iced::window; use iced::{Alignment, Command, Length, Settings, Subscription}; -use preset::Preset; use std::time::{Duration, Instant}; pub fn main() -> iced::Result { @@ -216,7 +217,7 @@ mod grid { }; use iced::pure::Element; use iced::{ - alignment, mouse, Color, Length, Point, Rectangle, Size, Vector, + alignment, mouse, Color, Length, Point, Rectangle, Size, Theme, Vector, }; use rustc_hash::{FxHashMap, FxHashSet}; use std::future::Future; @@ -525,6 +526,7 @@ mod grid { fn draw( &self, _interaction: &Interaction, + _theme: &Theme, bounds: Rectangle, cursor: Cursor, ) -> Vec { -- cgit