From 40f45d7b7e35dd4937abe6b5ce16b6256b4f1eeb Mon Sep 17 00:00:00 2001 From: shan Date: Thu, 29 Sep 2022 10:52:58 -0700 Subject: Adds linear gradient support to 2D meshes in the canvas widget. --- examples/solar_system/src/main.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'examples/solar_system/src') diff --git a/examples/solar_system/src/main.rs b/examples/solar_system/src/main.rs index c59d73a8..fcd20561 100644 --- a/examples/solar_system/src/main.rs +++ b/examples/solar_system/src/main.rs @@ -19,6 +19,7 @@ use iced::{ }; use std::time::Instant; +use crate::canvas::StrokeStyle; pub fn main() -> iced::Result { SolarSystem::run(Settings { @@ -37,9 +38,9 @@ enum Message { } impl Application for SolarSystem { + type Executor = executor::Default; type Message = Message; type Theme = Theme; - type Executor = executor::Default; type Flags = (); fn new(_flags: ()) -> (Self, Command) { @@ -65,10 +66,6 @@ impl Application for SolarSystem { Command::none() } - fn subscription(&self) -> Subscription { - time::every(std::time::Duration::from_millis(10)).map(Message::Tick) - } - fn view(&self) -> Element { canvas(&self.state) .width(Length::Fill) @@ -86,6 +83,10 @@ impl Application for SolarSystem { text_color: Color::WHITE, }) } + + fn subscription(&self) -> Subscription { + time::every(std::time::Duration::from_millis(10)).map(Message::Tick) + } } #[derive(Debug)] @@ -178,8 +179,8 @@ impl canvas::Program for State { frame.stroke( &orbit, Stroke { + style: StrokeStyle::Solid(Color::from_rgba8(0, 153, 255, 0.1)), width: 1.0, - color: Color::from_rgba8(0, 153, 255, 0.1), line_dash: canvas::LineDash { offset: 0, segments: &[3.0, 6.0], -- cgit From 6e7b3ced0b1daf368e44e181ecdb4ae529877eb6 Mon Sep 17 00:00:00 2001 From: shan Date: Tue, 4 Oct 2022 18:24:46 -0700 Subject: Reworked wgpu buffers, updated glow side to have proper transform location storage, attempting to fix visibility modifiers, implemented some of the feedback received in initial PR. --- examples/solar_system/src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'examples/solar_system/src') diff --git a/examples/solar_system/src/main.rs b/examples/solar_system/src/main.rs index fcd20561..8d713ce0 100644 --- a/examples/solar_system/src/main.rs +++ b/examples/solar_system/src/main.rs @@ -19,7 +19,7 @@ use iced::{ }; use std::time::Instant; -use crate::canvas::StrokeStyle; +use crate::canvas::Style; pub fn main() -> iced::Result { SolarSystem::run(Settings { @@ -179,7 +179,7 @@ impl canvas::Program for State { frame.stroke( &orbit, Stroke { - style: StrokeStyle::Solid(Color::from_rgba8(0, 153, 255, 0.1)), + style: Style::Solid(Color::from_rgba8(0, 153, 255, 0.1)), width: 1.0, line_dash: canvas::LineDash { offset: 0, -- cgit From cb7c4676543cd508dfae8d4dcbd9cc8b61b1a94e Mon Sep 17 00:00:00 2001 From: shan Date: Thu, 6 Oct 2022 07:28:05 -0700 Subject: Fixed lint issues & cleaned up some documentation. --- examples/solar_system/src/main.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'examples/solar_system/src') diff --git a/examples/solar_system/src/main.rs b/examples/solar_system/src/main.rs index 8d713ce0..5f90245c 100644 --- a/examples/solar_system/src/main.rs +++ b/examples/solar_system/src/main.rs @@ -11,7 +11,7 @@ use iced::executor; use iced::theme::{self, Theme}; use iced::time; use iced::widget::canvas; -use iced::widget::canvas::{Cursor, Path, Stroke}; +use iced::widget::canvas::{Cursor, Path, Stroke, stroke}; use iced::window; use iced::{ Application, Color, Command, Element, Length, Point, Rectangle, Settings, @@ -19,7 +19,6 @@ use iced::{ }; use std::time::Instant; -use crate::canvas::Style; pub fn main() -> iced::Result { SolarSystem::run(Settings { @@ -85,7 +84,7 @@ impl Application for SolarSystem { } fn subscription(&self) -> Subscription { - time::every(std::time::Duration::from_millis(10)).map(Message::Tick) + time::every(time::Duration::from_millis(10)).map(Message::Tick) } } @@ -179,7 +178,7 @@ impl canvas::Program for State { frame.stroke( &orbit, Stroke { - style: Style::Solid(Color::from_rgba8(0, 153, 255, 0.1)), + style: stroke::Style::Solid(Color::from_rgba8(0, 153, 255, 0.1)), width: 1.0, line_dash: canvas::LineDash { offset: 0, -- cgit From 9c7bf417ac9c1ac72bcc55aa3cd5e8eb962243a2 Mon Sep 17 00:00:00 2001 From: shan Date: Thu, 6 Oct 2022 16:57:38 -0700 Subject: Added support for gradients to respect current frame transform. --- examples/solar_system/src/main.rs | 40 ++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) (limited to 'examples/solar_system/src') diff --git a/examples/solar_system/src/main.rs b/examples/solar_system/src/main.rs index 5f90245c..73ddb01e 100644 --- a/examples/solar_system/src/main.rs +++ b/examples/solar_system/src/main.rs @@ -10,14 +10,14 @@ use iced::application; use iced::executor; use iced::theme::{self, Theme}; use iced::time; -use iced::widget::canvas; -use iced::widget::canvas::{Cursor, Path, Stroke, stroke}; +use iced::widget::canvas::{self, stroke, Cursor, Path, Stroke}; use iced::window; use iced::{ Application, Color, Command, Element, Length, Point, Rectangle, Settings, Size, Subscription, Vector, }; +use crate::canvas::{fill, Fill, Gradient}; use std::time::Instant; pub fn main() -> iced::Result { @@ -178,7 +178,9 @@ impl canvas::Program for State { frame.stroke( &orbit, Stroke { - style: stroke::Style::Solid(Color::from_rgba8(0, 153, 255, 0.1)), + style: stroke::Style::Solid(Color::from_rgba8( + 0, 153, 255, 0.1, + )), width: 1.0, line_dash: canvas::LineDash { offset: 0, @@ -198,15 +200,23 @@ impl canvas::Program for State { frame.translate(Vector::new(Self::ORBIT_RADIUS, 0.0)); let earth = Path::circle(Point::ORIGIN, Self::EARTH_RADIUS); - let shadow = Path::rectangle( - Point::new(0.0, -Self::EARTH_RADIUS), - Size::new( - Self::EARTH_RADIUS * 4.0, - Self::EARTH_RADIUS * 2.0, - ), - ); - frame.fill(&earth, Color::from_rgb8(0x6B, 0x93, 0xD6)); + let earth_fill = Gradient::linear( + Point::new(-Self::EARTH_RADIUS, 0.0), + Point::new(Self::EARTH_RADIUS, 0.0), + ) + .add_stop(0.2, Color::from_rgb(0.15, 0.50, 1.0)) + .add_stop(0.8, Color::from_rgb(0.0, 0.20, 0.47)) + .build() + .unwrap(); + + frame.fill( + &earth, + Fill { + style: fill::Style::Gradient(&earth_fill), + ..Default::default() + }, + ); frame.with_save(|frame| { frame.rotate(rotation * 10.0); @@ -215,14 +225,6 @@ impl canvas::Program for State { let moon = Path::circle(Point::ORIGIN, Self::MOON_RADIUS); frame.fill(&moon, Color::WHITE); }); - - frame.fill( - &shadow, - Color { - a: 0.7, - ..Color::BLACK - }, - ); }); }); -- cgit From 72feba51bed41db0bc04b43167d5d3b43007fd44 Mon Sep 17 00:00:00 2001 From: shan Date: Thu, 6 Oct 2022 19:13:40 -0700 Subject: Fixed some imports/documentation. --- examples/solar_system/src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'examples/solar_system/src') diff --git a/examples/solar_system/src/main.rs b/examples/solar_system/src/main.rs index 73ddb01e..6f38f480 100644 --- a/examples/solar_system/src/main.rs +++ b/examples/solar_system/src/main.rs @@ -10,14 +10,14 @@ use iced::application; use iced::executor; use iced::theme::{self, Theme}; use iced::time; -use iced::widget::canvas::{self, stroke, Cursor, Path, Stroke}; +use iced::widget::canvas; +use iced::widget::canvas::{Cursor, Path, Stroke, Fill, fill, Gradient, stroke}; use iced::window; use iced::{ Application, Color, Command, Element, Length, Point, Rectangle, Settings, Size, Subscription, Vector, }; -use crate::canvas::{fill, Fill, Gradient}; use std::time::Instant; pub fn main() -> iced::Result { -- cgit From 12a87c54eb68b992676060c80e518ffb29445cfc Mon Sep 17 00:00:00 2001 From: shan Date: Fri, 7 Oct 2022 11:41:50 -0700 Subject: Added support for relative positioning of gradient fills. Addressed some PR feedback. --- examples/solar_system/src/main.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'examples/solar_system/src') diff --git a/examples/solar_system/src/main.rs b/examples/solar_system/src/main.rs index 6f38f480..9200391b 100644 --- a/examples/solar_system/src/main.rs +++ b/examples/solar_system/src/main.rs @@ -19,6 +19,7 @@ use iced::{ }; use std::time::Instant; +use crate::canvas::Position; pub fn main() -> iced::Result { SolarSystem::run(Settings { @@ -202,8 +203,10 @@ impl canvas::Program for State { let earth = Path::circle(Point::ORIGIN, Self::EARTH_RADIUS); let earth_fill = Gradient::linear( - Point::new(-Self::EARTH_RADIUS, 0.0), - Point::new(Self::EARTH_RADIUS, 0.0), + Position::Absolute { + start: Point::new(-Self::EARTH_RADIUS, 0.0), + end: Point::new(Self::EARTH_RADIUS, 0.0) + } ) .add_stop(0.2, Color::from_rgb(0.15, 0.50, 1.0)) .add_stop(0.8, Color::from_rgb(0.0, 0.20, 0.47)) -- cgit From 3e600fe7754645ffdfca595060273b1e96c9a162 Mon Sep 17 00:00:00 2001 From: shan Date: Fri, 7 Oct 2022 13:10:37 -0700 Subject: Adjusted reexports for clarity. --- examples/solar_system/src/main.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'examples/solar_system/src') diff --git a/examples/solar_system/src/main.rs b/examples/solar_system/src/main.rs index 9200391b..10154621 100644 --- a/examples/solar_system/src/main.rs +++ b/examples/solar_system/src/main.rs @@ -11,7 +11,7 @@ use iced::executor; use iced::theme::{self, Theme}; use iced::time; use iced::widget::canvas; -use iced::widget::canvas::{Cursor, Path, Stroke, Fill, fill, Gradient, stroke}; +use iced::widget::canvas::{Cursor, Path, Stroke, Fill, fill, Gradient, stroke, gradient::Position}; use iced::window; use iced::{ Application, Color, Command, Element, Length, Point, Rectangle, Settings, @@ -19,7 +19,6 @@ use iced::{ }; use std::time::Instant; -use crate::canvas::Position; pub fn main() -> iced::Result { SolarSystem::run(Settings { -- cgit From a4a1262fa2d625be5ad7a37e409e0e9c399b09b6 Mon Sep 17 00:00:00 2001 From: shan Date: Fri, 7 Oct 2022 16:28:13 -0700 Subject: Fixed import issue with canvas in the gradient mod for situations where canvas feature is not enabled. --- examples/solar_system/src/main.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'examples/solar_system/src') diff --git a/examples/solar_system/src/main.rs b/examples/solar_system/src/main.rs index 10154621..b638c6d0 100644 --- a/examples/solar_system/src/main.rs +++ b/examples/solar_system/src/main.rs @@ -11,7 +11,7 @@ use iced::executor; use iced::theme::{self, Theme}; use iced::time; use iced::widget::canvas; -use iced::widget::canvas::{Cursor, Path, Stroke, Fill, fill, Gradient, stroke, gradient::Position}; +use iced::widget::canvas::{Cursor, Path, Stroke, Gradient, stroke, gradient::Position}; use iced::window; use iced::{ Application, Color, Command, Element, Length, Point, Rectangle, Settings, @@ -212,13 +212,7 @@ impl canvas::Program for State { .build() .unwrap(); - frame.fill( - &earth, - Fill { - style: fill::Style::Gradient(&earth_fill), - ..Default::default() - }, - ); + frame.fill(&earth, &earth_fill); frame.with_save(|frame| { frame.rotate(rotation * 10.0); -- cgit From b95745340441835bd25b5cadc2342254631f8c05 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 3 Nov 2022 04:35:16 +0100 Subject: Run `cargo fmt` --- examples/solar_system/src/main.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'examples/solar_system/src') diff --git a/examples/solar_system/src/main.rs b/examples/solar_system/src/main.rs index b638c6d0..09ac508d 100644 --- a/examples/solar_system/src/main.rs +++ b/examples/solar_system/src/main.rs @@ -11,7 +11,9 @@ use iced::executor; use iced::theme::{self, Theme}; use iced::time; use iced::widget::canvas; -use iced::widget::canvas::{Cursor, Path, Stroke, Gradient, stroke, gradient::Position}; +use iced::widget::canvas::{ + gradient::Position, stroke, Cursor, Gradient, Path, Stroke, +}; use iced::window; use iced::{ Application, Color, Command, Element, Length, Point, Rectangle, Settings, @@ -201,12 +203,10 @@ impl canvas::Program for State { let earth = Path::circle(Point::ORIGIN, Self::EARTH_RADIUS); - let earth_fill = Gradient::linear( - Position::Absolute { - start: Point::new(-Self::EARTH_RADIUS, 0.0), - end: Point::new(Self::EARTH_RADIUS, 0.0) - } - ) + let earth_fill = Gradient::linear(Position::Absolute { + start: Point::new(-Self::EARTH_RADIUS, 0.0), + end: Point::new(Self::EARTH_RADIUS, 0.0), + }) .add_stop(0.2, Color::from_rgb(0.15, 0.50, 1.0)) .add_stop(0.8, Color::from_rgb(0.0, 0.20, 0.47)) .build() -- cgit From e07344428de93055ac4b4f7e02505bbcbc43ab98 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 3 Nov 2022 05:19:58 +0100 Subject: Refactor imports in `solar_system` example --- examples/solar_system/src/main.rs | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'examples/solar_system/src') diff --git a/examples/solar_system/src/main.rs b/examples/solar_system/src/main.rs index 09ac508d..8d27d154 100644 --- a/examples/solar_system/src/main.rs +++ b/examples/solar_system/src/main.rs @@ -11,9 +11,9 @@ use iced::executor; use iced::theme::{self, Theme}; use iced::time; use iced::widget::canvas; -use iced::widget::canvas::{ - gradient::Position, stroke, Cursor, Gradient, Path, Stroke, -}; +use iced::widget::canvas::gradient::{self, Gradient}; +use iced::widget::canvas::stroke::{self, Stroke}; +use iced::widget::canvas::{Cursor, Path}; use iced::window; use iced::{ Application, Color, Command, Element, Length, Point, Rectangle, Settings, @@ -203,14 +203,15 @@ impl canvas::Program for State { let earth = Path::circle(Point::ORIGIN, Self::EARTH_RADIUS); - let earth_fill = Gradient::linear(Position::Absolute { - start: Point::new(-Self::EARTH_RADIUS, 0.0), - end: Point::new(Self::EARTH_RADIUS, 0.0), - }) - .add_stop(0.2, Color::from_rgb(0.15, 0.50, 1.0)) - .add_stop(0.8, Color::from_rgb(0.0, 0.20, 0.47)) - .build() - .unwrap(); + let earth_fill = + Gradient::linear(gradient::Position::Absolute { + start: Point::new(-Self::EARTH_RADIUS, 0.0), + end: Point::new(Self::EARTH_RADIUS, 0.0), + }) + .add_stop(0.2, Color::from_rgb(0.15, 0.50, 1.0)) + .add_stop(0.8, Color::from_rgb(0.0, 0.20, 0.47)) + .build() + .expect("Build Earth fill gradient"); frame.fill(&earth, &earth_fill); -- cgit From 84d1b79fefc88534835fdfbe79bc0eb3b43627cf Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 3 Nov 2022 05:50:53 +0100 Subject: Move `mesh::Style` to `triangle` and reuse it in `fill` and `stroke` --- examples/solar_system/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/solar_system/src') diff --git a/examples/solar_system/src/main.rs b/examples/solar_system/src/main.rs index 8d27d154..56787a99 100644 --- a/examples/solar_system/src/main.rs +++ b/examples/solar_system/src/main.rs @@ -213,7 +213,7 @@ impl canvas::Program for State { .build() .expect("Build Earth fill gradient"); - frame.fill(&earth, &earth_fill); + frame.fill(&earth, earth_fill); frame.with_save(|frame| { frame.rotate(rotation * 10.0); -- cgit