From 0b5028b1ab47707a469176e9bf20cacdd3a19861 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 19 Apr 2020 14:39:30 +0200 Subject: Draft `Program` interactivity for `Canvas` --- wgpu/src/widget/canvas.rs | 82 +++++++++++++++++++++++++++++++---------------- 1 file changed, 55 insertions(+), 27 deletions(-) (limited to 'wgpu/src/widget/canvas.rs') diff --git a/wgpu/src/widget/canvas.rs b/wgpu/src/widget/canvas.rs index 325f90ce..de4f0203 100644 --- a/wgpu/src/widget/canvas.rs +++ b/wgpu/src/widget/canvas.rs @@ -9,7 +9,8 @@ use crate::{Defaults, Primitive, Renderer}; use iced_native::{ - layout, Element, Hasher, Layout, Length, MouseCursor, Point, Size, Widget, + input::mouse, layout, Clipboard, Element, Hasher, Layout, Length, + MouseCursor, Point, Size, Widget, }; use std::hash::Hash; @@ -17,16 +18,20 @@ pub mod layer; pub mod path; mod drawable; +mod event; mod fill; mod frame; +mod program; mod stroke; mod text; pub use drawable::Drawable; +pub use event::Event; pub use fill::Fill; pub use frame::Frame; pub use layer::Layer; pub use path::Path; +pub use program::Program; pub use stroke::{LineCap, LineJoin, Stroke}; pub use text::Text; @@ -81,31 +86,31 @@ pub use text::Text; /// } /// /// // We can use a `Cache` to avoid unnecessary re-tessellation -/// let cache: layer::Cache = layer::Cache::new(); +/// let mut cache: layer::Cache = layer::Cache::new(); /// -/// // Finally, we simply provide the data to our `Cache` and push the resulting -/// // layer into a `Canvas` -/// let canvas = Canvas::new() -/// .push(cache.with(&Circle { radius: 50.0 })); +/// // Finally, we simply use our `Cache` to create the `Canvas`! +/// let canvas = Canvas::new(&mut cache, &Circle { radius: 50.0 }); /// ``` #[derive(Debug)] -pub struct Canvas<'a> { +pub struct Canvas<'a, P: Program> { width: Length, height: Length, - layers: Vec>, + program: &'a mut P, + input: &'a P::Input, } -impl<'a> Canvas<'a> { +impl<'a, P: Program> Canvas<'a, P> { const DEFAULT_SIZE: u16 = 100; /// Creates a new [`Canvas`] with no layers. /// /// [`Canvas`]: struct.Canvas.html - pub fn new() -> Self { + pub fn new(program: &'a mut P, input: &'a P::Input) -> Self { Canvas { width: Length::Units(Self::DEFAULT_SIZE), height: Length::Units(Self::DEFAULT_SIZE), - layers: Vec::new(), + program, + input, } } @@ -124,20 +129,9 @@ impl<'a> Canvas<'a> { self.height = height; self } - - /// Adds a [`Layer`] to the [`Canvas`]. - /// - /// It will be drawn on top of previous layers. - /// - /// [`Layer`]: layer/trait.Layer.html - /// [`Canvas`]: struct.Canvas.html - pub fn push(mut self, layer: impl Layer + 'a) -> Self { - self.layers.push(Box::new(layer)); - self - } } -impl<'a, Message> Widget for Canvas<'a> { +impl<'a, Message, P: Program> Widget for Canvas<'a, P> { fn width(&self) -> Length { self.width } @@ -157,6 +151,37 @@ impl<'a, Message> Widget for Canvas<'a> { layout::Node::new(size) } + fn on_event( + &mut self, + event: iced_native::Event, + layout: Layout<'_>, + cursor_position: Point, + _messages: &mut Vec, + _renderer: &Renderer, + _clipboard: Option<&dyn Clipboard>, + ) { + let bounds = layout.bounds(); + + let canvas_event = match event { + iced_native::Event::Mouse(mouse_event) => { + Some(Event::Mouse(match mouse_event { + mouse::Event::CursorMoved { .. } => { + mouse::Event::CursorMoved { + x: cursor_position.x - bounds.x, + y: cursor_position.y - bounds.y, + } + } + _ => mouse_event, + })) + } + _ => None, + }; + + if let Some(canvas_event) = canvas_event { + self.program.update(canvas_event, bounds.size(), self.input) + } + } + fn draw( &self, _renderer: &mut Renderer, @@ -171,7 +196,8 @@ impl<'a, Message> Widget for Canvas<'a> { ( Primitive::Group { primitives: self - .layers + .program + .layers(self.input) .iter() .map(|layer| Primitive::Cached { origin, @@ -184,18 +210,20 @@ impl<'a, Message> Widget for Canvas<'a> { } fn hash_layout(&self, state: &mut Hasher) { - std::any::TypeId::of::>().hash(state); + struct Marker; + std::any::TypeId::of::().hash(state); self.width.hash(state); self.height.hash(state); } } -impl<'a, Message> From> for Element<'a, Message, Renderer> +impl<'a, Message, P: Program> From> + for Element<'a, Message, Renderer> where Message: 'static, { - fn from(canvas: Canvas<'a>) -> Element<'a, Message, Renderer> { + fn from(canvas: Canvas<'a, P>) -> Element<'a, Message, Renderer> { Element::new(canvas) } } -- cgit From 8ade09a0f6fd6bfdcefebb92ccbbff25d741062a Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 19 Apr 2020 14:41:25 +0200 Subject: Simplify `Canvas` example in documentation --- wgpu/src/widget/canvas.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'wgpu/src/widget/canvas.rs') diff --git a/wgpu/src/widget/canvas.rs b/wgpu/src/widget/canvas.rs index de4f0203..326bc7d5 100644 --- a/wgpu/src/widget/canvas.rs +++ b/wgpu/src/widget/canvas.rs @@ -78,7 +78,7 @@ pub use text::Text; /// impl Drawable for Circle { /// fn draw(&self, frame: &mut Frame) { /// // We create a `Path` representing a simple circle -/// let circle = Path::new(|p| p.circle(frame.center(), self.radius)); +/// let circle = Path::circle(frame.center(), self.radius); /// /// // And fill it with some color /// frame.fill(&circle, Fill::Color(Color::BLACK)); -- cgit From 592cc685067c36cbba87e4db14f4ebc71d65b951 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 19 Apr 2020 21:55:23 +0200 Subject: Remove `Layer` trait and simplify `Canvas` --- wgpu/src/widget/canvas.rs | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'wgpu/src/widget/canvas.rs') diff --git a/wgpu/src/widget/canvas.rs b/wgpu/src/widget/canvas.rs index 326bc7d5..2b485e18 100644 --- a/wgpu/src/widget/canvas.rs +++ b/wgpu/src/widget/canvas.rs @@ -14,24 +14,26 @@ use iced_native::{ }; use std::hash::Hash; -pub mod layer; pub mod path; +mod cache; mod drawable; mod event; mod fill; mod frame; -mod program; +mod geometry; +mod state; mod stroke; mod text; +pub use cache::Cache; pub use drawable::Drawable; pub use event::Event; pub use fill::Fill; pub use frame::Frame; -pub use layer::Layer; +pub use geometry::Geometry; pub use path::Path; -pub use program::Program; +pub use state::State; pub use stroke::{LineCap, LineJoin, Stroke}; pub use text::Text; @@ -65,7 +67,7 @@ pub use text::Text; /// # pub use iced_wgpu::canvas; /// # pub use iced_native::Color; /// # } -/// use iced::canvas::{self, layer, Canvas, Drawable, Fill, Frame, Path}; +/// use iced::canvas::{self, Cache, Canvas, Drawable, Fill, Frame, Path}; /// use iced::Color; /// /// // First, we define the data we need for drawing @@ -86,31 +88,29 @@ pub use text::Text; /// } /// /// // We can use a `Cache` to avoid unnecessary re-tessellation -/// let mut cache: layer::Cache = layer::Cache::new(); +/// let cache = Cache::new(); /// /// // Finally, we simply use our `Cache` to create the `Canvas`! -/// let canvas = Canvas::new(&mut cache, &Circle { radius: 50.0 }); +/// let canvas = Canvas::new(cache.with(Circle { radius: 50.0 })); /// ``` #[derive(Debug)] -pub struct Canvas<'a, P: Program> { +pub struct Canvas { width: Length, height: Length, - program: &'a mut P, - input: &'a P::Input, + state: S, } -impl<'a, P: Program> Canvas<'a, P> { +impl Canvas { const DEFAULT_SIZE: u16 = 100; /// Creates a new [`Canvas`] with no layers. /// /// [`Canvas`]: struct.Canvas.html - pub fn new(program: &'a mut P, input: &'a P::Input) -> Self { + pub fn new(state: S) -> Self { Canvas { width: Length::Units(Self::DEFAULT_SIZE), height: Length::Units(Self::DEFAULT_SIZE), - program, - input, + state, } } @@ -131,7 +131,7 @@ impl<'a, P: Program> Canvas<'a, P> { } } -impl<'a, Message, P: Program> Widget for Canvas<'a, P> { +impl Widget for Canvas { fn width(&self) -> Length { self.width } @@ -178,7 +178,7 @@ impl<'a, Message, P: Program> Widget for Canvas<'a, P> { }; if let Some(canvas_event) = canvas_event { - self.program.update(canvas_event, bounds.size(), self.input) + self.state.update(canvas_event, bounds.size()) } } @@ -196,12 +196,12 @@ impl<'a, Message, P: Program> Widget for Canvas<'a, P> { ( Primitive::Group { primitives: self - .program - .layers(self.input) - .iter() - .map(|layer| Primitive::Cached { + .state + .draw(size) + .into_iter() + .map(|geometry| Primitive::Cached { origin, - cache: layer.draw(size), + cache: geometry.into_primitive(), }) .collect(), }, @@ -218,12 +218,12 @@ impl<'a, Message, P: Program> Widget for Canvas<'a, P> { } } -impl<'a, Message, P: Program> From> +impl<'a, Message, S: State + 'a> From> for Element<'a, Message, Renderer> where Message: 'static, { - fn from(canvas: Canvas<'a, P>) -> Element<'a, Message, Renderer> { + fn from(canvas: Canvas) -> Element<'a, Message, Renderer> { Element::new(canvas) } } -- cgit From 59b1e90661ee9e479f404bae71029db824cc7b46 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 28 Apr 2020 03:18:31 +0200 Subject: Introduce `Translate` primitive in `iced_wgpu` --- wgpu/src/widget/canvas.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'wgpu/src/widget/canvas.rs') diff --git a/wgpu/src/widget/canvas.rs b/wgpu/src/widget/canvas.rs index 2b485e18..744d901e 100644 --- a/wgpu/src/widget/canvas.rs +++ b/wgpu/src/widget/canvas.rs @@ -10,7 +10,7 @@ use crate::{Defaults, Primitive, Renderer}; use iced_native::{ input::mouse, layout, Clipboard, Element, Hasher, Layout, Length, - MouseCursor, Point, Size, Widget, + MouseCursor, Point, Size, Vector, Widget, }; use std::hash::Hash; @@ -190,20 +190,20 @@ impl Widget for Canvas { _cursor_position: Point, ) -> (Primitive, MouseCursor) { let bounds = layout.bounds(); - let origin = Point::new(bounds.x, bounds.y); + let translation = Vector::new(bounds.x, bounds.y); let size = Size::new(bounds.width, bounds.height); ( - Primitive::Group { - primitives: self - .state - .draw(size) - .into_iter() - .map(|geometry| Primitive::Cached { - origin, - cache: geometry.into_primitive(), - }) - .collect(), + Primitive::Translate { + translation, + content: Box::new(Primitive::Group { + primitives: self + .state + .draw(size) + .into_iter() + .map(Geometry::into_primitive) + .collect(), + }), }, MouseCursor::Idle, ) -- cgit From e4eb0553de13053c9828fd5454c281e27e598d65 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 28 Apr 2020 03:46:03 +0200 Subject: Allow `canvas::State` to produce messages --- wgpu/src/widget/canvas.rs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'wgpu/src/widget/canvas.rs') diff --git a/wgpu/src/widget/canvas.rs b/wgpu/src/widget/canvas.rs index 744d901e..044bc3ec 100644 --- a/wgpu/src/widget/canvas.rs +++ b/wgpu/src/widget/canvas.rs @@ -13,6 +13,7 @@ use iced_native::{ MouseCursor, Point, Size, Vector, Widget, }; use std::hash::Hash; +use std::marker::PhantomData; pub mod path; @@ -91,16 +92,17 @@ pub use text::Text; /// let cache = Cache::new(); /// /// // Finally, we simply use our `Cache` to create the `Canvas`! -/// let canvas = Canvas::new(cache.with(Circle { radius: 50.0 })); +/// let canvas: Canvas<_, ()> = Canvas::new(cache.with(Circle { radius: 50.0 })); /// ``` #[derive(Debug)] -pub struct Canvas { +pub struct Canvas, Message> { width: Length, height: Length, state: S, + phantom: PhantomData, } -impl Canvas { +impl> Canvas { const DEFAULT_SIZE: u16 = 100; /// Creates a new [`Canvas`] with no layers. @@ -111,6 +113,7 @@ impl Canvas { width: Length::Units(Self::DEFAULT_SIZE), height: Length::Units(Self::DEFAULT_SIZE), state, + phantom: PhantomData, } } @@ -131,7 +134,9 @@ impl Canvas { } } -impl Widget for Canvas { +impl> Widget + for Canvas +{ fn width(&self) -> Length { self.width } @@ -156,7 +161,7 @@ impl Widget for Canvas { event: iced_native::Event, layout: Layout<'_>, cursor_position: Point, - _messages: &mut Vec, + messages: &mut Vec, _renderer: &Renderer, _clipboard: Option<&dyn Clipboard>, ) { @@ -178,7 +183,11 @@ impl Widget for Canvas { }; if let Some(canvas_event) = canvas_event { - self.state.update(canvas_event, bounds.size()) + if let Some(message) = + self.state.update(canvas_event, bounds.size()) + { + messages.push(message); + } } } @@ -218,12 +227,12 @@ impl Widget for Canvas { } } -impl<'a, Message, S: State + 'a> From> +impl<'a, Message, S: State + 'a> From> for Element<'a, Message, Renderer> where Message: 'static, { - fn from(canvas: Canvas) -> Element<'a, Message, Renderer> { + fn from(canvas: Canvas) -> Element<'a, Message, Renderer> { Element::new(canvas) } } -- cgit From 2539042b71d70afd4d8f262783d441e768811ee9 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 28 Apr 2020 06:24:12 +0200 Subject: Remove `Drawable` and rename `State` to `Program` --- wgpu/src/widget/canvas.rs | 58 ++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 31 deletions(-) (limited to 'wgpu/src/widget/canvas.rs') diff --git a/wgpu/src/widget/canvas.rs b/wgpu/src/widget/canvas.rs index 044bc3ec..c0506cf7 100644 --- a/wgpu/src/widget/canvas.rs +++ b/wgpu/src/widget/canvas.rs @@ -18,34 +18,27 @@ use std::marker::PhantomData; pub mod path; mod cache; -mod drawable; mod event; mod fill; mod frame; mod geometry; -mod state; +mod program; mod stroke; mod text; pub use cache::Cache; -pub use drawable::Drawable; pub use event::Event; pub use fill::Fill; pub use frame::Frame; pub use geometry::Geometry; pub use path::Path; -pub use state::State; +pub use program::Program; pub use stroke::{LineCap, LineJoin, Stroke}; pub use text::Text; /// A widget capable of drawing 2D graphics. /// -/// A [`Canvas`] may contain multiple layers. A [`Layer`] is drawn using the -/// painter's algorithm. In other words, layers will be drawn on top of each -/// other in the same order they are pushed into the [`Canvas`]. -/// /// [`Canvas`]: struct.Canvas.html -/// [`Layer`]: layer/trait.Layer.html /// /// # Examples /// The repository has a couple of [examples] showcasing how to use a @@ -66,10 +59,10 @@ pub use text::Text; /// ```no_run /// # mod iced { /// # pub use iced_wgpu::canvas; -/// # pub use iced_native::Color; +/// # pub use iced_native::{Color, Size}; /// # } -/// use iced::canvas::{self, Cache, Canvas, Drawable, Fill, Frame, Path}; -/// use iced::Color; +/// use iced::canvas::{self, Cache, Canvas, Fill, Frame, Geometry, Path, Program}; +/// use iced::{Color, Size}; /// /// // First, we define the data we need for drawing /// #[derive(Debug)] @@ -77,42 +70,45 @@ pub use text::Text; /// radius: f32, /// } /// -/// // Then, we implement the `Drawable` trait -/// impl Drawable for Circle { -/// fn draw(&self, frame: &mut Frame) { +/// // Then, we implement the `Program` trait +/// impl Program<()> for Circle { +/// fn draw(&self, bounds: Size) -> Vec{ +/// // We prepare a new `Frame` +/// let mut frame = Frame::new(bounds); +/// /// // We create a `Path` representing a simple circle /// let circle = Path::circle(frame.center(), self.radius); /// /// // And fill it with some color /// frame.fill(&circle, Fill::Color(Color::BLACK)); +/// +/// // Finally, we produce the geometry +/// vec![frame.into_geometry()] /// } /// } /// -/// // We can use a `Cache` to avoid unnecessary re-tessellation -/// let cache = Cache::new(); -/// /// // Finally, we simply use our `Cache` to create the `Canvas`! -/// let canvas: Canvas<_, ()> = Canvas::new(cache.with(Circle { radius: 50.0 })); +/// let canvas = Canvas::new(Circle { radius: 50.0 }); /// ``` #[derive(Debug)] -pub struct Canvas, Message> { +pub struct Canvas> { width: Length, height: Length, - state: S, + program: P, phantom: PhantomData, } -impl> Canvas { +impl> Canvas { const DEFAULT_SIZE: u16 = 100; - /// Creates a new [`Canvas`] with no layers. + /// Creates a new [`Canvas`]. /// /// [`Canvas`]: struct.Canvas.html - pub fn new(state: S) -> Self { + pub fn new(program: P) -> Self { Canvas { width: Length::Units(Self::DEFAULT_SIZE), height: Length::Units(Self::DEFAULT_SIZE), - state, + program, phantom: PhantomData, } } @@ -134,8 +130,8 @@ impl> Canvas { } } -impl> Widget - for Canvas +impl> Widget + for Canvas { fn width(&self) -> Length { self.width @@ -184,7 +180,7 @@ impl> Widget if let Some(canvas_event) = canvas_event { if let Some(message) = - self.state.update(canvas_event, bounds.size()) + self.program.update(canvas_event, bounds.size()) { messages.push(message); } @@ -207,7 +203,7 @@ impl> Widget translation, content: Box::new(Primitive::Group { primitives: self - .state + .program .draw(size) .into_iter() .map(Geometry::into_primitive) @@ -227,12 +223,12 @@ impl> Widget } } -impl<'a, Message, S: State + 'a> From> +impl<'a, Message, P: Program + 'a> From> for Element<'a, Message, Renderer> where Message: 'static, { - fn from(canvas: Canvas) -> Element<'a, Message, Renderer> { + fn from(canvas: Canvas) -> Element<'a, Message, Renderer> { Element::new(canvas) } } -- cgit From 52719c7076cafb7b01967edf4df11ea72ae45aff Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 29 Apr 2020 03:16:03 +0200 Subject: Let a `canvas::Program` control the mouse cursor --- wgpu/src/widget/canvas.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'wgpu/src/widget/canvas.rs') diff --git a/wgpu/src/widget/canvas.rs b/wgpu/src/widget/canvas.rs index c0506cf7..0006ca8d 100644 --- a/wgpu/src/widget/canvas.rs +++ b/wgpu/src/widget/canvas.rs @@ -210,7 +210,7 @@ impl> Widget .collect(), }), }, - MouseCursor::Idle, + self.program.mouse_cursor(size), ) } -- cgit From dc51080328caa12d2b1fc02febc72cab70bb9f50 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 29 Apr 2020 04:25:49 +0200 Subject: Introduce `Cursor` type in `canvas` --- wgpu/src/widget/canvas.rs | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) (limited to 'wgpu/src/widget/canvas.rs') diff --git a/wgpu/src/widget/canvas.rs b/wgpu/src/widget/canvas.rs index 0006ca8d..a5834330 100644 --- a/wgpu/src/widget/canvas.rs +++ b/wgpu/src/widget/canvas.rs @@ -9,8 +9,8 @@ use crate::{Defaults, Primitive, Renderer}; use iced_native::{ - input::mouse, layout, Clipboard, Element, Hasher, Layout, Length, - MouseCursor, Point, Size, Vector, Widget, + layout, Clipboard, Element, Hasher, Layout, Length, MouseCursor, Point, + Size, Vector, Widget, }; use std::hash::Hash; use std::marker::PhantomData; @@ -18,6 +18,7 @@ use std::marker::PhantomData; pub mod path; mod cache; +mod cursor; mod event; mod fill; mod frame; @@ -27,6 +28,7 @@ mod stroke; mod text; pub use cache::Cache; +pub use cursor::Cursor; pub use event::Event; pub use fill::Fill; pub use frame::Frame; @@ -59,10 +61,10 @@ pub use text::Text; /// ```no_run /// # mod iced { /// # pub use iced_wgpu::canvas; -/// # pub use iced_native::{Color, Size}; +/// # pub use iced_native::{Color, Rectangle}; /// # } -/// use iced::canvas::{self, Cache, Canvas, Fill, Frame, Geometry, Path, Program}; -/// use iced::{Color, Size}; +/// use iced::canvas::{self, Canvas, Cursor, Fill, Frame, Geometry, Path, Program}; +/// use iced::{Color, Rectangle}; /// /// // First, we define the data we need for drawing /// #[derive(Debug)] @@ -72,9 +74,9 @@ pub use text::Text; /// /// // Then, we implement the `Program` trait /// impl Program<()> for Circle { -/// fn draw(&self, bounds: Size) -> Vec{ +/// fn draw(&self, bounds: Rectangle, _cursor: Cursor) -> Vec{ /// // We prepare a new `Frame` -/// let mut frame = Frame::new(bounds); +/// let mut frame = Frame::new(bounds.size()); /// /// // We create a `Path` representing a simple circle /// let circle = Path::circle(frame.center(), self.radius); @@ -165,22 +167,16 @@ impl> Widget let canvas_event = match event { iced_native::Event::Mouse(mouse_event) => { - Some(Event::Mouse(match mouse_event { - mouse::Event::CursorMoved { .. } => { - mouse::Event::CursorMoved { - x: cursor_position.x - bounds.x, - y: cursor_position.y - bounds.y, - } - } - _ => mouse_event, - })) + Some(Event::Mouse(mouse_event)) } _ => None, }; + let cursor = Cursor::from_window_position(cursor_position); + if let Some(canvas_event) = canvas_event { if let Some(message) = - self.program.update(canvas_event, bounds.size()) + self.program.update(canvas_event, bounds, cursor) { messages.push(message); } @@ -192,11 +188,11 @@ impl> Widget _renderer: &mut Renderer, _defaults: &Defaults, layout: Layout<'_>, - _cursor_position: Point, + cursor_position: Point, ) -> (Primitive, MouseCursor) { let bounds = layout.bounds(); let translation = Vector::new(bounds.x, bounds.y); - let size = Size::new(bounds.width, bounds.height); + let cursor = Cursor::from_window_position(cursor_position); ( Primitive::Translate { @@ -204,13 +200,13 @@ impl> Widget content: Box::new(Primitive::Group { primitives: self .program - .draw(size) + .draw(bounds, cursor) .into_iter() .map(Geometry::into_primitive) .collect(), }), }, - self.program.mouse_cursor(size), + self.program.mouse_cursor(bounds, cursor), ) } -- cgit From d4c4198f7242f168de65146e0ca339e0c1cbfe9b Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 30 Apr 2020 07:38:46 +0200 Subject: Write documentation for the new `canvas` API --- wgpu/src/widget/canvas.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'wgpu/src/widget/canvas.rs') diff --git a/wgpu/src/widget/canvas.rs b/wgpu/src/widget/canvas.rs index a5834330..05306e67 100644 --- a/wgpu/src/widget/canvas.rs +++ b/wgpu/src/widget/canvas.rs @@ -48,12 +48,15 @@ pub use text::Text; /// /// - [`clock`], an application that uses the [`Canvas`] widget to draw a clock /// and its hands to display the current time. +/// - [`game_of_life`], an interactive version of the Game of Life, invented by +/// John Conway. /// - [`solar_system`], an animated solar system drawn using the [`Canvas`] widget /// and showcasing how to compose different transforms. /// -/// [examples]: https://github.com/hecrj/iced/tree/0.1/examples -/// [`clock`]: https://github.com/hecrj/iced/tree/0.1/examples/clock -/// [`solar_system`]: https://github.com/hecrj/iced/tree/0.1/examples/solar_system +/// [examples]: https://github.com/hecrj/iced/tree/master/examples +/// [`clock`]: https://github.com/hecrj/iced/tree/master/examples/clock +/// [`game_of_life`]: https://github.com/hecrj/iced/tree/master/examples/game_of_life +/// [`solar_system`]: https://github.com/hecrj/iced/tree/master/examples/solar_system /// /// ## Drawing a simple circle /// If you want to get a quick overview, here's how we can draw a simple circle: @@ -89,7 +92,7 @@ pub use text::Text; /// } /// } /// -/// // Finally, we simply use our `Cache` to create the `Canvas`! +/// // Finally, we simply use our `Circle` to create the `Canvas`! /// let canvas = Canvas::new(Circle { radius: 50.0 }); /// ``` #[derive(Debug)] -- cgit From 98bc8cf2a7c4944d762a0148ca9f615d6ccc0d6e Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 30 Apr 2020 08:16:38 +0200 Subject: Rename `MouseCursor` to `mouse::Interaction` --- wgpu/src/widget/canvas.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'wgpu/src/widget/canvas.rs') diff --git a/wgpu/src/widget/canvas.rs b/wgpu/src/widget/canvas.rs index 05306e67..2fc10ea0 100644 --- a/wgpu/src/widget/canvas.rs +++ b/wgpu/src/widget/canvas.rs @@ -9,8 +9,8 @@ use crate::{Defaults, Primitive, Renderer}; use iced_native::{ - layout, Clipboard, Element, Hasher, Layout, Length, MouseCursor, Point, - Size, Vector, Widget, + layout, mouse, Clipboard, Element, Hasher, Layout, Length, Point, Size, + Vector, Widget, }; use std::hash::Hash; use std::marker::PhantomData; @@ -192,7 +192,7 @@ impl> Widget _defaults: &Defaults, layout: Layout<'_>, cursor_position: Point, - ) -> (Primitive, MouseCursor) { + ) -> (Primitive, mouse::Interaction) { let bounds = layout.bounds(); let translation = Vector::new(bounds.x, bounds.y); let cursor = Cursor::from_window_position(cursor_position); @@ -209,7 +209,7 @@ impl> Widget .collect(), }), }, - self.program.mouse_cursor(bounds, cursor), + self.program.mouse_interaction(bounds, cursor), ) } -- cgit