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/bezier_tool/src/main.rs | 9 +++++++-- examples/clock/src/main.rs | 7 ++++++- examples/color_palette/src/main.rs | 7 ++++++- examples/game_of_life/src/main.rs | 9 +++++++-- examples/pure/game_of_life/src/main.rs | 6 ++++-- examples/solar_system/src/main.rs | 1 + 6 files changed, 31 insertions(+), 8 deletions(-) (limited to 'examples') diff --git a/examples/bezier_tool/src/main.rs b/examples/bezier_tool/src/main.rs index 35b5182c..11e4828e 100644 --- a/examples/bezier_tool/src/main.rs +++ b/examples/bezier_tool/src/main.rs @@ -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)] @@ -158,7 +158,12 @@ mod bezier { } } - fn draw(&self, bounds: Rectangle, cursor: Cursor) -> Vec { + fn draw( + &self, + _theme: &Theme, + bounds: Rectangle, + cursor: Cursor, + ) -> Vec { let content = self.state.cache.draw(bounds.size(), |frame: &mut Frame| { Curve::draw_all(self.curves, frame); diff --git a/examples/clock/src/main.rs b/examples/clock/src/main.rs index fa4181a9..48b4cd7b 100644 --- a/examples/clock/src/main.rs +++ b/examples/clock/src/main.rs @@ -81,7 +81,12 @@ impl Application for Clock { } impl canvas::Program for Clock { - fn draw(&self, bounds: Rectangle, _cursor: Cursor) -> Vec { + fn draw( + &self, + _theme: &Theme, + bounds: Rectangle, + _cursor: Cursor, + ) -> Vec { let clock = self.clock.draw(bounds.size(), |frame| { let center = frame.center(); let radius = frame.width().min(frame.height()) / 2.0; diff --git a/examples/color_palette/src/main.rs b/examples/color_palette/src/main.rs index 98f68f9d..16c87a75 100644 --- a/examples/color_palette/src/main.rs +++ b/examples/color_palette/src/main.rs @@ -236,7 +236,12 @@ impl Theme { } impl canvas::Program for Theme { - fn draw(&self, bounds: Rectangle, _cursor: Cursor) -> Vec { + fn draw( + &self, + _theme: &iced::Theme, + bounds: Rectangle, + _cursor: Cursor, + ) -> Vec { let theme = self.canvas_cache.draw(bounds.size(), |frame| { self.draw(frame); }); diff --git a/examples/game_of_life/src/main.rs b/examples/game_of_life/src/main.rs index b2ae6953..35399584 100644 --- a/examples/game_of_life/src/main.rs +++ b/examples/game_of_life/src/main.rs @@ -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; @@ -445,7 +445,12 @@ mod grid { } } - fn draw(&self, bounds: Rectangle, cursor: Cursor) -> Vec { + fn draw( + &self, + _theme: &Theme, + bounds: Rectangle, + cursor: Cursor, + ) -> Vec { let center = Vector::new(bounds.width / 2.0, bounds.height / 2.0); let life = self.life_cache.draw(bounds.size(), |frame| { 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 { diff --git a/examples/solar_system/src/main.rs b/examples/solar_system/src/main.rs index 308c8c39..5f6c309d 100644 --- a/examples/solar_system/src/main.rs +++ b/examples/solar_system/src/main.rs @@ -135,6 +135,7 @@ impl State { impl canvas::Program for State { fn draw( &self, + _theme: &Theme, bounds: Rectangle, _cursor: Cursor, ) -> Vec { -- cgit