Implement event capturing for Canvas
This commit is contained in:
parent
bf6c65b5ad
commit
3aca177132
5 changed files with 98 additions and 66 deletions
|
|
@ -16,11 +16,11 @@ use iced_native::{
|
|||
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;
|
||||
|
|
@ -184,11 +184,14 @@ 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
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
//! Handle events of a canvas.
|
||||
use iced_native::keyboard;
|
||||
use iced_native::mouse;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use crate::canvas::{Cursor, Event, Geometry};
|
||||
use crate::canvas::event::{self, Event};
|
||||
use crate::canvas::{Cursor, Geometry};
|
||||
use iced_native::{mouse, Rectangle};
|
||||
|
||||
/// The state and logic of a [`Canvas`].
|
||||
|
|
@ -27,8 +28,8 @@ pub trait Program<Message> {
|
|||
_event: Event,
|
||||
_bounds: Rectangle,
|
||||
_cursor: Cursor,
|
||||
) -> Option<Message> {
|
||||
None
|
||||
) -> (event::Status, Option<Message>) {
|
||||
(event::Status::Ignored, None)
|
||||
}
|
||||
|
||||
/// Draws the state of the [`Program`], producing a bunch of [`Geometry`].
|
||||
|
|
@ -67,7 +68,7 @@ where
|
|||
event: Event,
|
||||
bounds: Rectangle,
|
||||
cursor: Cursor,
|
||||
) -> Option<Message> {
|
||||
) -> (event::Status, Option<Message>) {
|
||||
T::update(self, event, bounds, cursor)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue