Draft first-class Theme support
RFC: https://github.com/iced-rs/rfcs/pull/6
This commit is contained in:
parent
5de337f214
commit
664251f3f5
113 changed files with 767 additions and 878 deletions
|
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue