Let a canvas::Program control the mouse cursor

This commit is contained in:
Héctor Ramón Jiménez 2020-04-29 03:16:03 +02:00
parent 0509710cc5
commit 52719c7076
2 changed files with 10 additions and 1 deletions

View File

@ -210,7 +210,7 @@ impl<Message, P: Program<Message>> Widget<Message, Renderer>
.collect(), .collect(),
}), }),
}, },
MouseCursor::Idle, self.program.mouse_cursor(size),
) )
} }

View File

@ -1,4 +1,5 @@
use crate::canvas::{Event, Geometry, Size}; use crate::canvas::{Event, Geometry, Size};
use iced_native::MouseCursor;
pub trait Program<Message> { pub trait Program<Message> {
fn update(&mut self, _event: Event, _bounds: Size) -> Option<Message> { fn update(&mut self, _event: Event, _bounds: Size) -> Option<Message> {
@ -6,6 +7,10 @@ pub trait Program<Message> {
} }
fn draw(&self, bounds: Size) -> Vec<Geometry>; fn draw(&self, bounds: Size) -> Vec<Geometry>;
fn mouse_cursor(&self, _bounds: Size) -> MouseCursor {
MouseCursor::default()
}
} }
impl<T, Message> Program<Message> for &mut T impl<T, Message> Program<Message> for &mut T
@ -19,4 +24,8 @@ where
fn draw(&self, bounds: Size) -> Vec<Geometry> { fn draw(&self, bounds: Size) -> Vec<Geometry> {
T::draw(self, bounds) T::draw(self, bounds)
} }
fn mouse_cursor(&self, bounds: Size) -> MouseCursor {
T::mouse_cursor(self, bounds)
}
} }