diff options
Diffstat (limited to 'graphics/src/widget/canvas.rs')
-rw-r--r-- | graphics/src/widget/canvas.rs | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/graphics/src/widget/canvas.rs b/graphics/src/widget/canvas.rs index bc0802e5..7897c8ec 100644 --- a/graphics/src/widget/canvas.rs +++ b/graphics/src/widget/canvas.rs @@ -3,22 +3,21 @@ //! A [`Canvas`] widget can be used to draw different kinds of 2D shapes in a //! [`Frame`]. It can be used for animation, data visualization, game graphics, //! and more! -//! -//! [`Canvas`]: struct.Canvas.html -//! [`Frame`]: struct.Frame.html use crate::{Backend, Defaults, Primitive, Renderer}; +use iced_native::layout; +use iced_native::mouse; use iced_native::{ - layout, mouse, Clipboard, Element, Hasher, Layout, Length, Point, Size, - Vector, Widget, + Clipboard, Element, Hasher, Layout, Length, Point, Rectangle, Size, Vector, + Widget, }; use std::hash::Hash; use std::marker::PhantomData; +pub mod event; pub mod path; mod cache; mod cursor; -mod event; mod fill; mod frame; mod geometry; @@ -39,8 +38,6 @@ pub use text::Text; /// A widget capable of drawing 2D graphics. /// -/// [`Canvas`]: struct.Canvas.html -/// /// # Examples /// The repository has a couple of [examples] showcasing how to use a /// [`Canvas`]: @@ -106,8 +103,6 @@ impl<Message, P: Program<Message>> Canvas<Message, P> { const DEFAULT_SIZE: u16 = 100; /// Creates a new [`Canvas`]. - /// - /// [`Canvas`]: struct.Canvas.html pub fn new(program: P) -> Self { Canvas { width: Length::Units(Self::DEFAULT_SIZE), @@ -118,16 +113,12 @@ impl<Message, P: Program<Message>> Canvas<Message, P> { } /// Sets the width of the [`Canvas`]. - /// - /// [`Canvas`]: struct.Canvas.html pub fn width(mut self, width: Length) -> Self { self.width = width; self } /// Sets the height of the [`Canvas`]. - /// - /// [`Canvas`]: struct.Canvas.html pub fn height(mut self, height: Length) -> Self { self.height = height; self @@ -163,10 +154,10 @@ where event: iced_native::Event, layout: Layout<'_>, cursor_position: Point, - messages: &mut Vec<Message>, _renderer: &Renderer<B>, - _clipboard: Option<&dyn Clipboard>, - ) { + _clipboard: &mut dyn Clipboard, + messages: &mut Vec<Message>, + ) -> event::Status { let bounds = layout.bounds(); let canvas_event = match event { @@ -182,12 +173,17 @@ where 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, cursor) - { + let (event_status, message) = + self.program.update(canvas_event, bounds, cursor); + + if let Some(message) = message { messages.push(message); } + + return event_status; } + + event::Status::Ignored } fn draw( @@ -196,6 +192,7 @@ where _defaults: &Defaults, layout: Layout<'_>, cursor_position: Point, + _viewport: &Rectangle, ) -> (Primitive, mouse::Interaction) { let bounds = layout.bounds(); let translation = Vector::new(bounds.x, bounds.y); |