Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Theming #1362

Merged
merged 38 commits into from
Jul 9, 2022
Merged

Theming #1362

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
664251f
Draft first-class `Theme` support
hecrj May 13, 2022
2cfb307
Implement basic theming `Palette`
hecrj May 21, 2022
03eda9b
Let a `Theme` control the background color of an application
hecrj May 25, 2022
3a820b4
Implement theme styling for `Slider`
hecrj May 25, 2022
822a3cd
Let a `Theme` control the `text_color` of an application
hecrj May 25, 2022
5a39dad
Tweak styling of `Slider` and improve contrast of `Background`
hecrj May 26, 2022
3e8f4cd
Add "Theming" section to the `tour` example
hecrj May 26, 2022
7f3b707
Rename `theme::Definition` to `application::StyleSheet`
hecrj May 26, 2022
cf02300
Rename `Variant` to `Style` and `Style` to `Appearance`
hecrj May 26, 2022
d5bc610
Fix examples and doc-tests
hecrj May 26, 2022
d988d81
Introduce specific types for each `palette::Extended` field
hecrj May 26, 2022
28d09bf
Implement theme styling for `Radio`
hecrj May 26, 2022
3e2b624
Implement theme styling for `Toggler`
hecrj May 31, 2022
a206d22
Use `Theme` background in `styling` example
hecrj May 31, 2022
6f69df3
Implement theme styling for `PaneGrid`
hecrj May 31, 2022
c275fde
Implement theme styling for `Rule`
hecrj May 31, 2022
e4ca779
Introduce `Custom` style variant for `Rule`
hecrj Jun 1, 2022
77dc9dc
Implement theme styling for `ProgressBar`
hecrj Jun 1, 2022
1388d71
Expose `palette` module in `theme`
hecrj Jun 4, 2022
835877f
Implement theme styling for `Checkbox`
hecrj Jun 4, 2022
ce53d39
Implement theme styling for `TextInput`
hecrj Jun 6, 2022
de21a65
Implement theme styling for `Scrollable`
hecrj Jun 7, 2022
2933ac7
Remove `style` module leftover in `scrollable` example
hecrj Jun 7, 2022
97555e6
Implement theme styling for `Container`
hecrj Jun 7, 2022
396735b
Implement theme styling for `PickList` and `Menu`
hecrj Jun 7, 2022
3a22faa
Remove unused code warnings
hecrj Jun 7, 2022
f92afa7
Use `Theme::Dark` in `pure_game_of_life` example
hecrj Jun 7, 2022
fc13bb3
Implement theme styling for `Canvas`
hecrj Jun 7, 2022
c807abd
Fix `Theme` not being refreshed in `iced_glutin`
hecrj Jun 25, 2022
1dd1a2f
Introduce `StyleSheet` for `Text` widget
hecrj Jun 29, 2022
fa55dff
Merge branch 'master' into theming
hecrj Jul 8, 2022
bb07d01
Add `Style` variant support to `application::StyleSheet`
hecrj Jul 8, 2022
3514bd1
Add `theme::Application` styling support to `Sandbox`
hecrj Jul 8, 2022
3e643a9
Fix inconsistent styling for `Radio` and `Checkbox`
hecrj Jul 8, 2022
2d6d26c
Make widget aliases in `iced` compatible with `iced_native`
hecrj Jul 8, 2022
48bc505
Fix missing docs in `iced` crate
hecrj Jul 8, 2022
4407385
Make `Element` aliases in `iced` compatible with `iced_native` and `i…
hecrj Jul 8, 2022
7105db9
Remove redundant `crate::Theme` in alias of `Element`
hecrj Jul 8, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions examples/bezier_tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ mod bezier {
use iced::{
canvas::event::{self, Event},
canvas::{self, Canvas, Cursor, Frame, Geometry, Path, Stroke},
mouse, Element, Length, Point, Rectangle,
mouse, Element, Length, Point, Rectangle, Theme,
};

#[derive(Default)]
Expand Down Expand Up @@ -158,7 +158,12 @@ mod bezier {
}
}

fn draw(&self, bounds: Rectangle, cursor: Cursor) -> Vec<Geometry> {
fn draw(
&self,
_theme: &Theme,
bounds: Rectangle,
cursor: Cursor,
) -> Vec<Geometry> {
let content =
self.state.cache.draw(bounds.size(), |frame: &mut Frame| {
Curve::draw_all(self.curves, frame);
Expand Down
19 changes: 14 additions & 5 deletions examples/clock/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use iced::canvas::{
self, Cache, Canvas, Cursor, Geometry, LineCap, Path, Stroke,
};
use iced::executor;
use iced::{
canvas::{self, Cache, Canvas, Cursor, Geometry, LineCap, Path, Stroke},
executor, Application, Color, Command, Container, Element, Length, Point,
Rectangle, Settings, Subscription, Vector,
Application, Color, Command, Container, Element, Length, Point, Rectangle,
Settings, Subscription, Theme, Vector,
};

pub fn main() -> iced::Result {
Expand All @@ -22,8 +25,9 @@ enum Message {
}

impl Application for Clock {
type Executor = executor::Default;
type Message = Message;
type Theme = Theme;
type Executor = executor::Default;
type Flags = ();

fn new(_flags: ()) -> (Self, Command<Message>) {
Expand Down Expand Up @@ -77,7 +81,12 @@ impl Application for Clock {
}

impl<Message> canvas::Program<Message> for Clock {
fn draw(&self, bounds: Rectangle, _cursor: Cursor) -> Vec<Geometry> {
fn draw(
&self,
_theme: &Theme,
bounds: Rectangle,
_cursor: Cursor,
) -> Vec<Geometry> {
let clock = self.clock.draw(bounds.size(), |frame| {
let center = frame.center();
let radius = frame.width().min(frame.height()) / 2.0;
Expand Down
9 changes: 7 additions & 2 deletions examples/color_palette/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,12 @@ impl Theme {
}

impl<Message> canvas::Program<Message> for Theme {
fn draw(&self, bounds: Rectangle, _cursor: Cursor) -> Vec<Geometry> {
fn draw(
&self,
_theme: &iced::Theme,
bounds: Rectangle,
_cursor: Cursor,
) -> Vec<Geometry> {
let theme = self.canvas_cache.draw(bounds.size(), |frame| {
self.draw(frame);
});
Expand Down Expand Up @@ -288,7 +293,7 @@ impl<C: 'static + ColorSpace + Copy> ColorPicker<C> {
range: RangeInclusive<f64>,
component: f32,
update: impl Fn(f32) -> C + 'static,
) -> Slider<f64, C> {
) -> Slider<f64, C, iced::Renderer> {
Slider::new(state, range, f64::from(component), move |v| {
update(v as f32)
})
Expand Down
8 changes: 7 additions & 1 deletion examples/component/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ mod numeric_input {
use iced_native::text;
use iced_native::widget::button::{self, Button};
use iced_native::widget::text_input::{self, TextInput};
use iced_native::widget::{Row, Text};
use iced_native::widget::{self, Row, Text};
use iced_native::{Element, Length};

pub struct NumericInput<'a, Message> {
Expand Down Expand Up @@ -95,6 +95,9 @@ mod numeric_input {
for NumericInput<'a, Message>
where
Renderer: 'a + text::Renderer,
Renderer::Theme: button::StyleSheet
+ text_input::StyleSheet
+ widget::text::StyleSheet,
{
type Event = Event;

Expand Down Expand Up @@ -172,6 +175,9 @@ mod numeric_input {
where
Message: 'a,
Renderer: text::Renderer + 'a,
Renderer::Theme: button::StyleSheet
+ text_input::StyleSheet
+ widget::text::StyleSheet,
{
fn from(numeric_input: NumericInput<'a, Message>) -> Self {
component::view(numeric_input)
Expand Down
5 changes: 2 additions & 3 deletions examples/counter/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use iced::{
button, Alignment, Button, Column, Element, Sandbox, Settings, Text,
};
use iced::button::{self, Button};
use iced::{Alignment, Column, Element, Sandbox, Settings, Text};

pub fn main() -> iced::Result {
Counter::run(Settings::default())
Expand Down
1 change: 1 addition & 0 deletions examples/custom_widget/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ mod circle {
fn draw(
&self,
renderer: &mut Renderer,
_theme: &Renderer::Theme,
_style: &renderer::Style,
layout: Layout<'_>,
_cursor_position: Point,
Expand Down
9 changes: 6 additions & 3 deletions examples/download_progress/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use iced::button;
use iced::executor;
use iced::{
button, executor, Alignment, Application, Button, Column, Command,
Container, Element, Length, ProgressBar, Settings, Subscription, Text,
Alignment, Application, Button, Column, Command, Container, Element,
Length, ProgressBar, Settings, Subscription, Text, Theme,
};

mod download;
Expand All @@ -24,8 +26,9 @@ pub enum Message {
}

impl Application for Example {
type Executor = executor::Default;
type Message = Message;
type Theme = Theme;
type Executor = executor::Default;
type Flags = ();

fn new(_flags: ()) -> (Example, Command<Message>) {
Expand Down
10 changes: 7 additions & 3 deletions examples/events/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use iced::alignment;
use iced::button;
use iced::executor;
use iced::{
alignment, button, executor, Alignment, Application, Button, Checkbox,
Column, Command, Container, Element, Length, Settings, Subscription, Text,
Alignment, Application, Button, Checkbox, Column, Command, Container,
Element, Length, Settings, Subscription, Text, Theme,
};
use iced_native::{window, Event};

Expand All @@ -27,8 +30,9 @@ enum Message {
}

impl Application for Events {
type Executor = executor::Default;
type Message = Message;
type Theme = Theme;
type Executor = executor::Default;
type Flags = ();

fn new(_flags: ()) -> (Events, Command<Message>) {
Expand Down
53 changes: 27 additions & 26 deletions examples/game_of_life/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
//! 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::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::{
Alignment, Application, Checkbox, Column, Command, Container, Element,
Length, Row, Settings, Subscription, Text,
Alignment, Application, Checkbox, Column, Command, Element, Length, Row,
Settings, Subscription, Text,
};
use preset::Preset;
use std::time::{Duration, Instant};
Expand Down Expand Up @@ -55,6 +55,7 @@ enum Message {

impl Application for GameOfLife {
type Message = Message;
type Theme = Theme;
type Executor = executor::Default;
type Flags = ();

Expand Down Expand Up @@ -141,20 +142,19 @@ impl Application for GameOfLife {
self.grid.preset(),
);

let content = Column::new()
Column::new()
.push(
self.grid
.view()
.map(move |message| Message::Grid(message, version)),
)
.push(controls);

Container::new(content)
.width(Length::Fill)
.height(Length::Fill)
.style(style::Container)
.push(controls)
.into()
}

fn theme(&self) -> Theme {
Theme::Dark
}
}

mod grid {
Expand All @@ -163,7 +163,7 @@ mod grid {
alignment,
canvas::event::{self, Event},
canvas::{self, Cache, Canvas, Cursor, Frame, Geometry, Path, Text},
mouse, Color, Element, Length, Point, Rectangle, Size, Vector,
mouse, Color, Element, Length, Point, Rectangle, Size, Theme, Vector,
};
use rustc_hash::{FxHashMap, FxHashSet};
use std::future::Future;
Expand Down Expand Up @@ -445,7 +445,12 @@ mod grid {
}
}

fn draw(&self, bounds: Rectangle, cursor: Cursor) -> Vec<Geometry> {
fn draw(
&self,
_theme: &Theme,
bounds: Rectangle,
cursor: Cursor,
) -> Vec<Geometry> {
let center = Vector::new(bounds.width / 2.0, bounds.height / 2.0);

let life = self.life_cache.draw(bounds.size(), |frame| {
Expand Down Expand Up @@ -836,27 +841,24 @@ 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()
.width(Length::Fill)
.align_items(Alignment::Center)
.spacing(10)
.push(
Slider::new(
&mut self.speed_slider,
1.0..=1000.0,
speed as f32,
Message::SpeedChanged,
)
.style(style::Slider),
)
.push(Slider::new(
&mut self.speed_slider,
1.0..=1000.0,
speed as f32,
Message::SpeedChanged,
))
.push(Text::new(format!("x{}", speed)).size(16));

Row::new()
Expand All @@ -879,13 +881,12 @@ impl Controls {
Message::PresetPicked,
)
.padding(8)
.text_size(16)
.style(style::PickList),
.text_size(16),
)
.push(
Button::new(&mut self.clear_button, Text::new("Clear"))
.on_press(Message::Clear)
.style(style::Clear),
.style(theme::Button::Destructive),
)
.into()
}
Expand Down
Loading