Implement theme styling for Canvas

This commit is contained in:
Héctor Ramón Jiménez 2022-06-07 05:24:43 +02:00
parent f92afa7950
commit fc13bb3d65
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
10 changed files with 94 additions and 45 deletions

View file

@ -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<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);

View file

@ -81,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;

View file

@ -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);
});

View file

@ -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<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| {

View file

@ -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<Geometry> {

View file

@ -135,6 +135,7 @@ impl State {
impl<Message> canvas::Program<Message> for State {
fn draw(
&self,
_theme: &Theme,
bounds: Rectangle,
_cursor: Cursor,
) -> Vec<canvas::Geometry> {