diff options
author | 2020-04-29 03:23:27 +0200 | |
---|---|---|
committer | 2020-04-29 03:23:27 +0200 | |
commit | 5586034d6626e013cdd718aca1c4f19f6a060ff3 (patch) | |
tree | f29b57e8b412b1fc2e12bf4168c066b0d684a8d0 /examples/bezier_tool | |
parent | 475a2779a7a420ed6c1567a8dbc623114e2b7ec0 (diff) | |
download | iced-5586034d6626e013cdd718aca1c4f19f6a060ff3.tar.gz iced-5586034d6626e013cdd718aca1c4f19f6a060ff3.tar.bz2 iced-5586034d6626e013cdd718aca1c4f19f6a060ff3.zip |
Display crosshair cursor in `bezier_tool` example
Diffstat (limited to 'examples/bezier_tool')
-rw-r--r-- | examples/bezier_tool/src/main.rs | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/examples/bezier_tool/src/main.rs b/examples/bezier_tool/src/main.rs index 2112f662..8c9ebd75 100644 --- a/examples/bezier_tool/src/main.rs +++ b/examples/bezier_tool/src/main.rs @@ -70,7 +70,8 @@ impl Sandbox for Example { mod bezier { use iced::{ canvas::{self, Canvas, Event, Frame, Geometry, Path, Stroke}, - mouse, ButtonState, Element, Length, Point, Rectangle, Size, + mouse, ButtonState, Element, Length, MouseCursor, Point, Rectangle, + Size, }; #[derive(Default)] @@ -106,8 +107,6 @@ mod bezier { impl<'a> canvas::Program<Curve> for Bezier<'a> { fn update(&mut self, event: Event, bounds: Size) -> Option<Curve> { - let bounds = Rectangle::new(Point::ORIGIN, bounds); - match event { Event::Mouse(mouse_event) => match mouse_event { mouse::Event::CursorMoved { x, y } => { @@ -118,7 +117,9 @@ mod bezier { mouse::Event::Input { button: mouse::Button::Left, state: ButtonState::Pressed, - } if bounds.contains(self.state.cursor_position) => { + } if Rectangle::with_size(bounds) + .contains(self.state.cursor_position) => + { match self.state.pending { None => { self.state.pending = Some(Pending::One { @@ -169,6 +170,15 @@ mod bezier { vec![content] } } + + fn mouse_cursor(&self, bounds: Size) -> MouseCursor { + if Rectangle::with_size(bounds).contains(self.state.cursor_position) + { + MouseCursor::Crosshair + } else { + MouseCursor::default() + } + } } #[derive(Debug, Clone, Copy)] |