Rename `MouseCursor` to `mouse::Interaction`

This commit is contained in:
Héctor Ramón Jiménez 2020-04-30 08:16:38 +02:00
parent d4c4198f72
commit 98bc8cf2a7
35 changed files with 170 additions and 171 deletions

View File

@ -22,7 +22,6 @@ mod background;
mod color; mod color;
mod font; mod font;
mod length; mod length;
mod mouse_cursor;
mod point; mod point;
mod rectangle; mod rectangle;
mod size; mod size;
@ -33,7 +32,6 @@ pub use background::Background;
pub use color::Color; pub use color::Color;
pub use font::Font; pub use font::Font;
pub use length::Length; pub use length::Length;
pub use mouse_cursor::MouseCursor;
pub use point::Point; pub use point::Point;
pub use rectangle::Rectangle; pub use rectangle::Rectangle;
pub use size::Size; pub use size::Size;

View File

@ -1,6 +1,8 @@
//! Reuse basic mouse types. //! Reuse basic mouse types.
mod button; mod button;
mod event; mod event;
mod interaction;
pub use button::Button; pub use button::Button;
pub use event::{Event, ScrollDelta}; pub use event::{Event, ScrollDelta};
pub use interaction::Interaction;

View File

@ -0,0 +1,20 @@
/// The interaction of a mouse cursor.
#[derive(Debug, Eq, PartialEq, Clone, Copy, PartialOrd, Ord)]
#[allow(missing_docs)]
pub enum Interaction {
Idle,
Pointer,
Grab,
Text,
Crosshair,
Working,
Grabbing,
ResizingHorizontally,
ResizingVertically,
}
impl Default for Interaction {
fn default() -> Interaction {
Interaction::Idle
}
}

View File

@ -1,36 +0,0 @@
/// The state of the mouse cursor.
#[derive(Debug, Eq, PartialEq, Clone, Copy, PartialOrd, Ord)]
pub enum MouseCursor {
/// The cursor is over a non-interactive widget.
Idle,
/// The cursor is over a clickable widget.
Pointer,
/// The cursor is over a busy widget.
Working,
/// The cursor is over a grabbable widget.
Grab,
/// The cursor is over a text widget.
Text,
/// The cursor is over a widget that requires precision.
Crosshair,
/// The cursor is grabbing a widget.
Grabbing,
/// The cursor is resizing a widget horizontally.
ResizingHorizontally,
/// The cursor is resizing a widget vertically.
ResizingVertically,
}
impl Default for MouseCursor {
fn default() -> MouseCursor {
MouseCursor::Idle
}
}

View File

@ -70,7 +70,7 @@ impl Sandbox for Example {
mod bezier { mod bezier {
use iced::{ use iced::{
canvas::{self, Canvas, Cursor, Event, Frame, Geometry, Path, Stroke}, canvas::{self, Canvas, Cursor, Event, Frame, Geometry, Path, Stroke},
mouse, Element, Length, MouseCursor, Point, Rectangle, mouse, Element, Length, Point, Rectangle,
}; };
#[derive(Default)] #[derive(Default)]
@ -166,15 +166,15 @@ mod bezier {
} }
} }
fn mouse_cursor( fn mouse_interaction(
&self, &self,
bounds: Rectangle, bounds: Rectangle,
cursor: Cursor, cursor: Cursor,
) -> MouseCursor { ) -> mouse::Interaction {
if cursor.is_over(&bounds) { if cursor.is_over(&bounds) {
MouseCursor::Crosshair mouse::Interaction::Crosshair
} else { } else {
MouseCursor::default() mouse::Interaction::default()
} }
} }
} }

View File

@ -10,8 +10,8 @@ mod circle {
// if you wish to, by creating your own `Renderer` trait, which could be // if you wish to, by creating your own `Renderer` trait, which could be
// implemented by `iced_wgpu` and other renderers. // implemented by `iced_wgpu` and other renderers.
use iced_native::{ use iced_native::{
layout, Background, Color, Element, Hasher, Layout, Length, layout, mouse, Background, Color, Element, Hasher, Layout, Length,
MouseCursor, Point, Size, Widget, Point, Size, Widget,
}; };
use iced_wgpu::{Defaults, Primitive, Renderer}; use iced_wgpu::{Defaults, Primitive, Renderer};
@ -57,7 +57,7 @@ mod circle {
_defaults: &Defaults, _defaults: &Defaults,
layout: Layout<'_>, layout: Layout<'_>,
_cursor_position: Point, _cursor_position: Point,
) -> (Primitive, MouseCursor) { ) -> (Primitive, mouse::Interaction) {
( (
Primitive::Quad { Primitive::Quad {
bounds: layout.bounds(), bounds: layout.bounds(),
@ -66,7 +66,7 @@ mod circle {
border_width: 0, border_width: 0,
border_color: Color::TRANSPARENT, border_color: Color::TRANSPARENT,
}, },
MouseCursor::default(), mouse::Interaction::default(),
) )
} }
} }

View File

@ -157,8 +157,7 @@ impl Application for GameOfLife {
mod grid { mod grid {
use iced::{ use iced::{
canvas::{self, Canvas, Cursor, Event, Frame, Geometry, Path}, canvas::{self, Canvas, Cursor, Event, Frame, Geometry, Path},
mouse, Color, Element, Length, MouseCursor, Point, Rectangle, Size, mouse, Color, Element, Length, Point, Rectangle, Size, Vector,
Vector,
}; };
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
@ -397,16 +396,20 @@ mod grid {
vec![life, hovered_cell] vec![life, hovered_cell]
} }
fn mouse_cursor( fn mouse_interaction(
&self, &self,
bounds: Rectangle, bounds: Rectangle,
cursor: Cursor, cursor: Cursor,
) -> MouseCursor { ) -> mouse::Interaction {
match self.interaction { match self.interaction {
Some(Interaction::Drawing) => MouseCursor::Crosshair, Some(Interaction::Drawing) => mouse::Interaction::Crosshair,
Some(Interaction::Panning { .. }) => MouseCursor::Grabbing, Some(Interaction::Panning { .. }) => {
None if cursor.is_over(&bounds) => MouseCursor::Crosshair, mouse::Interaction::Grabbing
_ => MouseCursor::default(), }
None if cursor.is_over(&bounds) => {
mouse::Interaction::Crosshair
}
_ => mouse::Interaction::default(),
} }
} }
} }

View File

@ -11,8 +11,8 @@ mod rainbow {
// if you wish to, by creating your own `Renderer` trait, which could be // if you wish to, by creating your own `Renderer` trait, which could be
// implemented by `iced_wgpu` and other renderers. // implemented by `iced_wgpu` and other renderers.
use iced_native::{ use iced_native::{
layout, Element, Hasher, Layout, Length, MouseCursor, Point, Size, layout, mouse, Element, Hasher, Layout, Length, Point, Size, Vector,
Vector, Widget, Widget,
}; };
use iced_wgpu::{ use iced_wgpu::{
triangle::{Mesh2D, Vertex2D}, triangle::{Mesh2D, Vertex2D},
@ -54,7 +54,7 @@ mod rainbow {
_defaults: &Defaults, _defaults: &Defaults,
layout: Layout<'_>, layout: Layout<'_>,
cursor_position: Point, cursor_position: Point,
) -> (Primitive, MouseCursor) { ) -> (Primitive, mouse::Interaction) {
let b = layout.bounds(); let b = layout.bounds();
// R O Y G B I V // R O Y G B I V
@ -141,7 +141,7 @@ mod rainbow {
}, },
}), }),
}, },
MouseCursor::default(), mouse::Interaction::default(),
) )
} }
} }

View File

@ -8,7 +8,7 @@ use iced_wgpu::{
wgpu, window::SwapChain, Primitive, Renderer, Settings, Target, wgpu, window::SwapChain, Primitive, Renderer, Settings, Target,
}; };
use iced_winit::{ use iced_winit::{
futures, winit, Cache, Clipboard, MouseCursor, Size, UserInterface, futures, mouse, winit, Cache, Clipboard, Size, UserInterface,
}; };
use winit::{ use winit::{
@ -63,7 +63,7 @@ pub fn main() {
let mut events = Vec::new(); let mut events = Vec::new();
let mut cache = Some(Cache::default()); let mut cache = Some(Cache::default());
let mut renderer = Renderer::new(&mut device, Settings::default()); let mut renderer = Renderer::new(&mut device, Settings::default());
let mut output = (Primitive::None, MouseCursor::default()); let mut output = (Primitive::None, mouse::Interaction::default());
let clipboard = Clipboard::new(&window); let clipboard = Clipboard::new(&window);
// Initialize scene and GUI controls // Initialize scene and GUI controls
@ -189,7 +189,7 @@ pub fn main() {
scene.draw(&mut encoder, &frame.view); scene.draw(&mut encoder, &frame.view);
// And then iced on top // And then iced on top
let mouse_cursor = renderer.draw( let mouse_interaction = renderer.draw(
&mut device, &mut device,
&mut encoder, &mut encoder,
Target { Target {
@ -205,9 +205,11 @@ pub fn main() {
queue.submit(&[encoder.finish()]); queue.submit(&[encoder.finish()]);
// And update the mouse cursor // And update the mouse cursor
window.set_cursor_icon(iced_winit::conversion::mouse_cursor( window.set_cursor_icon(
mouse_cursor, iced_winit::conversion::mouse_interaction(
)); mouse_interaction,
),
);
} }
_ => {} _ => {}
} }

View File

@ -55,8 +55,8 @@ mod runtime;
mod user_interface; mod user_interface;
pub use iced_core::{ pub use iced_core::{
Align, Background, Color, Font, HorizontalAlignment, Length, MouseCursor, Align, Background, Color, Font, HorizontalAlignment, Length, Point,
Point, Rectangle, Size, Vector, VerticalAlignment, Rectangle, Size, Vector, VerticalAlignment,
}; };
pub use iced_futures::{executor, futures, Command}; pub use iced_futures::{executor, futures, Command};

View File

@ -1,4 +1,4 @@
use crate::MouseCursor; use crate::mouse;
use raw_window_handle::HasRawWindowHandle; use raw_window_handle::HasRawWindowHandle;
@ -51,5 +51,5 @@ pub trait Backend: Sized {
output: &<Self::Renderer as crate::Renderer>::Output, output: &<Self::Renderer as crate::Renderer>::Output,
scale_factor: f64, scale_factor: f64,
overlay: &[T], overlay: &[T],
) -> MouseCursor; ) -> mouse::Interaction;
} }

View File

@ -214,6 +214,5 @@ use iced_web as runtime;
pub use runtime::{ pub use runtime::{
futures, Align, Background, Color, Command, Font, HorizontalAlignment, futures, Align, Background, Color, Command, Font, HorizontalAlignment,
Length, MouseCursor, Point, Rectangle, Size, Subscription, Vector, Length, Point, Rectangle, Size, Subscription, Vector, VerticalAlignment,
VerticalAlignment,
}; };

View File

@ -1,2 +1,2 @@
//! Listen and react to mouse events. //! Listen and react to mouse events.
pub use crate::runtime::mouse::{Button, Event, ScrollDelta}; pub use crate::runtime::mouse::{Button, Event, Interaction, ScrollDelta};

View File

@ -75,7 +75,7 @@ pub use element::Element;
pub use hasher::Hasher; pub use hasher::Hasher;
pub use iced_core::{ pub use iced_core::{
keyboard, mouse, Align, Background, Color, Font, HorizontalAlignment, keyboard, mouse, Align, Background, Color, Font, HorizontalAlignment,
Length, MouseCursor, Point, Rectangle, Size, Vector, VerticalAlignment, Length, Point, Rectangle, Size, Vector, VerticalAlignment,
}; };
pub use iced_futures::{executor, futures, Command}; pub use iced_futures::{executor, futures, Command};
pub use subscription::Subscription; pub use subscription::Subscription;

View File

@ -7,8 +7,7 @@ use crate::{
use crate::image::{self, Image}; use crate::image::{self, Image};
use iced_native::{ use iced_native::{
layout, Background, Color, Layout, MouseCursor, Point, Rectangle, Vector, layout, mouse, Background, Color, Layout, Point, Rectangle, Vector, Widget,
Widget,
}; };
mod widget; mod widget;
@ -94,10 +93,10 @@ impl Renderer {
device: &wgpu::Device, device: &wgpu::Device,
encoder: &mut wgpu::CommandEncoder, encoder: &mut wgpu::CommandEncoder,
target: Target<'_>, target: Target<'_>,
(primitive, mouse_cursor): &(Primitive, MouseCursor), (primitive, mouse_interaction): &(Primitive, mouse::Interaction),
scale_factor: f64, scale_factor: f64,
overlay: &[T], overlay: &[T],
) -> MouseCursor { ) -> mouse::Interaction {
log::debug!("Drawing"); log::debug!("Drawing");
let (width, height) = target.viewport.dimensions(); let (width, height) = target.viewport.dimensions();
@ -132,7 +131,7 @@ impl Renderer {
#[cfg(any(feature = "image", feature = "svg"))] #[cfg(any(feature = "image", feature = "svg"))]
self.image_pipeline.trim_cache(); self.image_pipeline.trim_cache();
*mouse_cursor *mouse_interaction
} }
fn draw_primitive<'a>( fn draw_primitive<'a>(
@ -453,7 +452,7 @@ impl Renderer {
} }
impl iced_native::Renderer for Renderer { impl iced_native::Renderer for Renderer {
type Output = (Primitive, MouseCursor); type Output = (Primitive, mouse::Interaction);
type Defaults = Defaults; type Defaults = Defaults;
fn layout<'a, Message>( fn layout<'a, Message>(

View File

@ -1,6 +1,6 @@
use crate::{button::StyleSheet, defaults, Defaults, Primitive, Renderer}; use crate::{button::StyleSheet, defaults, Defaults, Primitive, Renderer};
use iced_native::{ use iced_native::{
Background, Color, Element, Layout, MouseCursor, Point, Rectangle, Vector, mouse, Background, Color, Element, Layout, Point, Rectangle, Vector,
}; };
impl iced_native::button::Renderer for Renderer { impl iced_native::button::Renderer for Renderer {
@ -84,9 +84,9 @@ impl iced_native::button::Renderer for Renderer {
content content
}, },
if is_mouse_over { if is_mouse_over {
MouseCursor::Pointer mouse::Interaction::Pointer
} else { } else {
MouseCursor::default() mouse::Interaction::default()
}, },
) )
} }

View File

@ -1,6 +1,6 @@
use crate::{checkbox::StyleSheet, Primitive, Renderer}; use crate::{checkbox::StyleSheet, Primitive, Renderer};
use iced_native::{ use iced_native::{
checkbox, HorizontalAlignment, MouseCursor, Rectangle, VerticalAlignment, checkbox, mouse, HorizontalAlignment, Rectangle, VerticalAlignment,
}; };
impl checkbox::Renderer for Renderer { impl checkbox::Renderer for Renderer {
@ -54,9 +54,9 @@ impl checkbox::Renderer for Renderer {
}, },
}, },
if is_mouse_over { if is_mouse_over {
MouseCursor::Pointer mouse::Interaction::Pointer
} else { } else {
MouseCursor::default() mouse::Interaction::default()
}, },
) )
} }

View File

@ -1,5 +1,5 @@
use crate::{Primitive, Renderer}; use crate::{Primitive, Renderer};
use iced_native::{column, Element, Layout, MouseCursor, Point}; use iced_native::{column, mouse, Element, Layout, Point};
impl column::Renderer for Renderer { impl column::Renderer for Renderer {
fn draw<Message>( fn draw<Message>(
@ -9,7 +9,7 @@ impl column::Renderer for Renderer {
layout: Layout<'_>, layout: Layout<'_>,
cursor_position: Point, cursor_position: Point,
) -> Self::Output { ) -> Self::Output {
let mut mouse_cursor = MouseCursor::default(); let mut mouse_interaction = mouse::Interaction::default();
( (
Primitive::Group { Primitive::Group {
@ -17,18 +17,18 @@ impl column::Renderer for Renderer {
.iter() .iter()
.zip(layout.children()) .zip(layout.children())
.map(|(child, layout)| { .map(|(child, layout)| {
let (primitive, new_mouse_cursor) = let (primitive, new_mouse_interaction) =
child.draw(self, defaults, layout, cursor_position); child.draw(self, defaults, layout, cursor_position);
if new_mouse_cursor > mouse_cursor { if new_mouse_interaction > mouse_interaction {
mouse_cursor = new_mouse_cursor; mouse_interaction = new_mouse_interaction;
} }
primitive primitive
}) })
.collect(), .collect(),
}, },
mouse_cursor, mouse_interaction,
) )
} }
} }

View File

@ -21,7 +21,7 @@ impl iced_native::container::Renderer for Renderer {
}, },
}; };
let (content, mouse_cursor) = let (content, mouse_interaction) =
content.draw(self, &defaults, content_layout, cursor_position); content.draw(self, &defaults, content_layout, cursor_position);
if style.background.is_some() || style.border_width > 0 { if style.background.is_some() || style.border_width > 0 {
@ -39,10 +39,10 @@ impl iced_native::container::Renderer for Renderer {
Primitive::Group { Primitive::Group {
primitives: vec![quad, content], primitives: vec![quad, content],
}, },
mouse_cursor, mouse_interaction,
) )
} else { } else {
(content, mouse_cursor) (content, mouse_interaction)
} }
} }
} }

View File

@ -1,5 +1,5 @@
use crate::{Primitive, Renderer}; use crate::{Primitive, Renderer};
use iced_native::{image, Layout, MouseCursor}; use iced_native::{image, mouse, Layout};
impl image::Renderer for Renderer { impl image::Renderer for Renderer {
fn dimensions(&self, handle: &image::Handle) -> (u32, u32) { fn dimensions(&self, handle: &image::Handle) -> (u32, u32) {
@ -16,7 +16,7 @@ impl image::Renderer for Renderer {
handle, handle,
bounds: layout.bounds(), bounds: layout.bounds(),
}, },
MouseCursor::default(), mouse::Interaction::default(),
) )
} }
} }

View File

@ -1,7 +1,8 @@
use crate::{Primitive, Renderer}; use crate::{Primitive, Renderer};
use iced_native::{ use iced_native::{
mouse,
pane_grid::{self, Axis, Pane}, pane_grid::{self, Axis, Pane},
Element, Layout, MouseCursor, Point, Rectangle, Vector, Element, Layout, Point, Rectangle, Vector,
}; };
impl pane_grid::Renderer for Renderer { impl pane_grid::Renderer for Renderer {
@ -22,7 +23,7 @@ impl pane_grid::Renderer for Renderer {
cursor_position cursor_position
}; };
let mut mouse_cursor = MouseCursor::default(); let mut mouse_interaction = mouse::Interaction::default();
let mut dragged_pane = None; let mut dragged_pane = None;
let mut panes: Vec<_> = content let mut panes: Vec<_> = content
@ -30,11 +31,11 @@ impl pane_grid::Renderer for Renderer {
.zip(layout.children()) .zip(layout.children())
.enumerate() .enumerate()
.map(|(i, ((id, pane), layout))| { .map(|(i, ((id, pane), layout))| {
let (primitive, new_mouse_cursor) = let (primitive, new_mouse_interaction) =
pane.draw(self, defaults, layout, pane_cursor_position); pane.draw(self, defaults, layout, pane_cursor_position);
if new_mouse_cursor > mouse_cursor { if new_mouse_interaction > mouse_interaction {
mouse_cursor = new_mouse_cursor; mouse_interaction = new_mouse_interaction;
} }
if Some(*id) == dragging { if Some(*id) == dragging {
@ -78,14 +79,14 @@ impl pane_grid::Renderer for Renderer {
( (
Primitive::Group { primitives }, Primitive::Group { primitives },
if dragging.is_some() { if dragging.is_some() {
MouseCursor::Grabbing mouse::Interaction::Grabbing
} else if let Some(axis) = resizing { } else if let Some(axis) = resizing {
match axis { match axis {
Axis::Horizontal => MouseCursor::ResizingVertically, Axis::Horizontal => mouse::Interaction::ResizingVertically,
Axis::Vertical => MouseCursor::ResizingHorizontally, Axis::Vertical => mouse::Interaction::ResizingHorizontally,
} }
} else { } else {
mouse_cursor mouse_interaction
}, },
) )
} }

View File

@ -1,5 +1,5 @@
use crate::{progress_bar::StyleSheet, Primitive, Renderer}; use crate::{progress_bar::StyleSheet, Primitive, Renderer};
use iced_native::{progress_bar, Color, MouseCursor, Rectangle}; use iced_native::{mouse, progress_bar, Color, Rectangle};
impl progress_bar::Renderer for Renderer { impl progress_bar::Renderer for Renderer {
type Style = Box<dyn StyleSheet>; type Style = Box<dyn StyleSheet>;
@ -48,7 +48,7 @@ impl progress_bar::Renderer for Renderer {
} else { } else {
background background
}, },
MouseCursor::default(), mouse::Interaction::default(),
) )
} }
} }

View File

@ -1,5 +1,5 @@
use crate::{radio::StyleSheet, Primitive, Renderer}; use crate::{radio::StyleSheet, Primitive, Renderer};
use iced_native::{radio, Background, Color, MouseCursor, Rectangle}; use iced_native::{mouse, radio, Background, Color, Rectangle};
const SIZE: f32 = 28.0; const SIZE: f32 = 28.0;
const DOT_SIZE: f32 = SIZE / 2.0; const DOT_SIZE: f32 = SIZE / 2.0;
@ -55,9 +55,9 @@ impl radio::Renderer for Renderer {
}, },
}, },
if is_mouse_over { if is_mouse_over {
MouseCursor::Pointer mouse::Interaction::Pointer
} else { } else {
MouseCursor::default() mouse::Interaction::default()
}, },
) )
} }

View File

@ -1,5 +1,5 @@
use crate::{Primitive, Renderer}; use crate::{Primitive, Renderer};
use iced_native::{row, Element, Layout, MouseCursor, Point}; use iced_native::{mouse, row, Element, Layout, Point};
impl row::Renderer for Renderer { impl row::Renderer for Renderer {
fn draw<Message>( fn draw<Message>(
@ -9,7 +9,7 @@ impl row::Renderer for Renderer {
layout: Layout<'_>, layout: Layout<'_>,
cursor_position: Point, cursor_position: Point,
) -> Self::Output { ) -> Self::Output {
let mut mouse_cursor = MouseCursor::default(); let mut mouse_interaction = mouse::Interaction::default();
( (
Primitive::Group { Primitive::Group {
@ -17,18 +17,18 @@ impl row::Renderer for Renderer {
.iter() .iter()
.zip(layout.children()) .zip(layout.children())
.map(|(child, layout)| { .map(|(child, layout)| {
let (primitive, new_mouse_cursor) = let (primitive, new_mouse_interaction) =
child.draw(self, defaults, layout, cursor_position); child.draw(self, defaults, layout, cursor_position);
if new_mouse_cursor > mouse_cursor { if new_mouse_interaction > mouse_interaction {
mouse_cursor = new_mouse_cursor; mouse_interaction = new_mouse_interaction;
} }
primitive primitive
}) })
.collect(), .collect(),
}, },
mouse_cursor, mouse_interaction,
) )
} }
} }

View File

@ -1,7 +1,5 @@
use crate::{Primitive, Renderer}; use crate::{Primitive, Renderer};
use iced_native::{ use iced_native::{mouse, scrollable, Background, Color, Rectangle, Vector};
scrollable, Background, Color, MouseCursor, Rectangle, Vector,
};
const SCROLLBAR_WIDTH: u16 = 10; const SCROLLBAR_WIDTH: u16 = 10;
const SCROLLBAR_MARGIN: u16 = 2; const SCROLLBAR_MARGIN: u16 = 2;
@ -56,7 +54,7 @@ impl scrollable::Renderer for Renderer {
scrollbar: Option<scrollable::Scrollbar>, scrollbar: Option<scrollable::Scrollbar>,
offset: u32, offset: u32,
style_sheet: &Self::Style, style_sheet: &Self::Style,
(content, mouse_cursor): Self::Output, (content, mouse_interaction): Self::Output,
) -> Self::Output { ) -> Self::Output {
( (
if let Some(scrollbar) = scrollbar { if let Some(scrollbar) = scrollbar {
@ -118,9 +116,9 @@ impl scrollable::Renderer for Renderer {
content content
}, },
if is_mouse_over_scrollbar || state.is_scroller_grabbed() { if is_mouse_over_scrollbar || state.is_scroller_grabbed() {
MouseCursor::Idle mouse::Interaction::Idle
} else { } else {
mouse_cursor mouse_interaction
}, },
) )
} }

View File

@ -2,7 +2,7 @@ use crate::{
slider::{HandleShape, StyleSheet}, slider::{HandleShape, StyleSheet},
Primitive, Renderer, Primitive, Renderer,
}; };
use iced_native::{slider, Background, Color, MouseCursor, Point, Rectangle}; use iced_native::{mouse, slider, Background, Color, Point, Rectangle};
const HANDLE_HEIGHT: f32 = 22.0; const HANDLE_HEIGHT: f32 = 22.0;
@ -95,11 +95,11 @@ impl slider::Renderer for Renderer {
primitives: vec![rail_top, rail_bottom, handle], primitives: vec![rail_top, rail_bottom, handle],
}, },
if is_dragging { if is_dragging {
MouseCursor::Grabbing mouse::Interaction::Grabbing
} else if is_mouse_over { } else if is_mouse_over {
MouseCursor::Grab mouse::Interaction::Grab
} else { } else {
MouseCursor::default() mouse::Interaction::default()
}, },
) )
} }

View File

@ -1,8 +1,8 @@
use crate::{Primitive, Renderer}; use crate::{Primitive, Renderer};
use iced_native::{space, MouseCursor, Rectangle}; use iced_native::{mouse, space, Rectangle};
impl space::Renderer for Renderer { impl space::Renderer for Renderer {
fn draw(&mut self, _bounds: Rectangle) -> Self::Output { fn draw(&mut self, _bounds: Rectangle) -> Self::Output {
(Primitive::None, MouseCursor::default()) (Primitive::None, mouse::Interaction::default())
} }
} }

View File

@ -1,5 +1,5 @@
use crate::{Primitive, Renderer}; use crate::{Primitive, Renderer};
use iced_native::{svg, Layout, MouseCursor}; use iced_native::{mouse, svg, Layout};
impl svg::Renderer for Renderer { impl svg::Renderer for Renderer {
fn dimensions(&self, handle: &svg::Handle) -> (u32, u32) { fn dimensions(&self, handle: &svg::Handle) -> (u32, u32) {
@ -16,7 +16,7 @@ impl svg::Renderer for Renderer {
handle, handle,
bounds: layout.bounds(), bounds: layout.bounds(),
}, },
MouseCursor::default(), mouse::Interaction::default(),
) )
} }
} }

View File

@ -1,6 +1,6 @@
use crate::{Primitive, Renderer}; use crate::{Primitive, Renderer};
use iced_native::{ use iced_native::{
text, Color, Font, HorizontalAlignment, MouseCursor, Rectangle, Size, mouse, text, Color, Font, HorizontalAlignment, Rectangle, Size,
VerticalAlignment, VerticalAlignment,
}; };
@ -55,7 +55,7 @@ impl text::Renderer for Renderer {
horizontal_alignment, horizontal_alignment,
vertical_alignment, vertical_alignment,
}, },
MouseCursor::default(), mouse::Interaction::default(),
) )
} }
} }

View File

@ -1,9 +1,10 @@
use crate::{text_input::StyleSheet, Primitive, Renderer}; use crate::{text_input::StyleSheet, Primitive, Renderer};
use iced_native::{ use iced_native::{
mouse,
text_input::{self, cursor}, text_input::{self, cursor},
Background, Color, Font, HorizontalAlignment, MouseCursor, Point, Background, Color, Font, HorizontalAlignment, Point, Rectangle, Size,
Rectangle, Size, Vector, VerticalAlignment, Vector, VerticalAlignment,
}; };
use std::f32; use std::f32;
@ -232,9 +233,9 @@ impl text_input::Renderer for Renderer {
primitives: vec![input, contents], primitives: vec![input, contents],
}, },
if is_mouse_over { if is_mouse_over {
MouseCursor::Text mouse::Interaction::Text
} else { } else {
MouseCursor::default() mouse::Interaction::default()
}, },
) )
} }

View File

@ -9,8 +9,8 @@
use crate::{Defaults, Primitive, Renderer}; use crate::{Defaults, Primitive, Renderer};
use iced_native::{ use iced_native::{
layout, Clipboard, Element, Hasher, Layout, Length, MouseCursor, Point, layout, mouse, Clipboard, Element, Hasher, Layout, Length, Point, Size,
Size, Vector, Widget, Vector, Widget,
}; };
use std::hash::Hash; use std::hash::Hash;
use std::marker::PhantomData; use std::marker::PhantomData;
@ -192,7 +192,7 @@ impl<Message, P: Program<Message>> Widget<Message, Renderer>
_defaults: &Defaults, _defaults: &Defaults,
layout: Layout<'_>, layout: Layout<'_>,
cursor_position: Point, cursor_position: Point,
) -> (Primitive, MouseCursor) { ) -> (Primitive, mouse::Interaction) {
let bounds = layout.bounds(); let bounds = layout.bounds();
let translation = Vector::new(bounds.x, bounds.y); let translation = Vector::new(bounds.x, bounds.y);
let cursor = Cursor::from_window_position(cursor_position); let cursor = Cursor::from_window_position(cursor_position);
@ -209,7 +209,7 @@ impl<Message, P: Program<Message>> Widget<Message, Renderer>
.collect(), .collect(),
}), }),
}, },
self.program.mouse_cursor(bounds, cursor), self.program.mouse_interaction(bounds, cursor),
) )
} }

View File

@ -1,5 +1,5 @@
use crate::canvas::{Cursor, Event, Geometry}; use crate::canvas::{Cursor, Event, Geometry};
use iced_native::{MouseCursor, Rectangle}; use iced_native::{mouse, Rectangle};
/// The state and logic of a [`Canvas`]. /// The state and logic of a [`Canvas`].
/// ///
@ -42,15 +42,19 @@ pub trait Program<Message> {
/// [`Cache`]: struct.Cache.html /// [`Cache`]: struct.Cache.html
fn draw(&self, bounds: Rectangle, cursor: Cursor) -> Vec<Geometry>; fn draw(&self, bounds: Rectangle, cursor: Cursor) -> Vec<Geometry>;
/// Returns the mouse cursor state of the [`Program`]. /// Returns the current mouse interaction of the [`Program`].
/// ///
/// The mouse cursor returned will be in effect even if the cursor position /// The interaction returned will be in effect even if the cursor position
/// is out of bounds of the program's [`Canvas`]. /// is out of bounds of the program's [`Canvas`].
/// ///
/// [`Program`]: trait.Program.html /// [`Program`]: trait.Program.html
/// [`Canvas`]: struct.Canvas.html /// [`Canvas`]: struct.Canvas.html
fn mouse_cursor(&self, _bounds: Rectangle, _cursor: Cursor) -> MouseCursor { fn mouse_interaction(
MouseCursor::default() &self,
_bounds: Rectangle,
_cursor: Cursor,
) -> mouse::Interaction {
mouse::Interaction::default()
} }
} }
@ -71,7 +75,11 @@ where
T::draw(self, bounds, cursor) T::draw(self, bounds, cursor)
} }
fn mouse_cursor(&self, bounds: Rectangle, cursor: Cursor) -> MouseCursor { fn mouse_interaction(
T::mouse_cursor(self, bounds, cursor) &self,
bounds: Rectangle,
cursor: Cursor,
) -> mouse::Interaction {
T::mouse_interaction(self, bounds, cursor)
} }
} }

View File

@ -1,6 +1,6 @@
use crate::{window::SwapChain, Renderer, Settings, Target}; use crate::{window::SwapChain, Renderer, Settings, Target};
use iced_native::{futures, MouseCursor}; use iced_native::{futures, mouse};
use raw_window_handle::HasRawWindowHandle; use raw_window_handle::HasRawWindowHandle;
/// A window graphics backend for iced powered by `wgpu`. /// A window graphics backend for iced powered by `wgpu`.
@ -78,7 +78,7 @@ impl iced_native::window::Backend for Backend {
output: &<Self::Renderer as iced_native::Renderer>::Output, output: &<Self::Renderer as iced_native::Renderer>::Output,
scale_factor: f64, scale_factor: f64,
overlay: &[T], overlay: &[T],
) -> MouseCursor { ) -> mouse::Interaction {
let (frame, viewport) = swap_chain.next_frame().expect("Next frame"); let (frame, viewport) = swap_chain.next_frame().expect("Next frame");
let mut encoder = self.device.create_command_encoder( let mut encoder = self.device.create_command_encoder(
@ -101,7 +101,7 @@ impl iced_native::window::Backend for Backend {
depth_stencil_attachment: None, depth_stencil_attachment: None,
}); });
let mouse_cursor = renderer.draw( let mouse_interaction = renderer.draw(
&mut self.device, &mut self.device,
&mut encoder, &mut encoder,
Target { Target {
@ -115,6 +115,6 @@ impl iced_native::window::Backend for Backend {
self.queue.submit(&[encoder.finish()]); self.queue.submit(&[encoder.finish()]);
mouse_cursor mouse_interaction
} }
} }

View File

@ -1,6 +1,6 @@
use crate::{ use crate::{
conversion, size::Size, window, Cache, Clipboard, Command, Debug, Element, conversion, mouse, size::Size, window, Cache, Clipboard, Command, Debug,
Executor, Mode, MouseCursor, Proxy, Runtime, Settings, Subscription, Element, Executor, Mode, Proxy, Runtime, Settings, Subscription,
UserInterface, UserInterface,
}; };
@ -205,7 +205,7 @@ pub trait Application: Sized {
let mut cache = Some(user_interface.into_cache()); let mut cache = Some(user_interface.into_cache());
let mut events = Vec::new(); let mut events = Vec::new();
let mut mouse_cursor = MouseCursor::default(); let mut mouse_interaction = mouse::Interaction::default();
let mut modifiers = winit::event::ModifiersState::default(); let mut modifiers = winit::event::ModifiersState::default();
debug.startup_finished(); debug.startup_finished();
@ -328,7 +328,7 @@ pub trait Application: Sized {
resized = false; resized = false;
} }
let new_mouse_cursor = backend.draw( let new_mouse_interaction = backend.draw(
&mut renderer, &mut renderer,
&mut swap_chain, &mut swap_chain,
&primitive, &primitive,
@ -338,12 +338,12 @@ pub trait Application: Sized {
debug.render_finished(); debug.render_finished();
if new_mouse_cursor != mouse_cursor { if new_mouse_interaction != mouse_interaction {
window.set_cursor_icon(conversion::mouse_cursor( window.set_cursor_icon(conversion::mouse_interaction(
new_mouse_cursor, new_mouse_interaction,
)); ));
mouse_cursor = new_mouse_cursor; mouse_interaction = new_mouse_interaction;
} }
// TODO: Handle animations! // TODO: Handle animations!

View File

@ -4,7 +4,7 @@
//! [`iced_native`]: https://github.com/hecrj/iced/tree/master/native //! [`iced_native`]: https://github.com/hecrj/iced/tree/master/native
use crate::{ use crate::{
keyboard::{self, KeyCode, ModifiersState}, keyboard::{self, KeyCode, ModifiersState},
mouse, window, Event, Mode, MouseCursor, mouse, window, Event, Mode,
}; };
/// Converts a winit window event into an iced event. /// Converts a winit window event into an iced event.
@ -125,19 +125,23 @@ pub fn fullscreen(
/// ///
/// [`winit`]: https://github.com/rust-windowing/winit /// [`winit`]: https://github.com/rust-windowing/winit
/// [`iced_native`]: https://github.com/hecrj/iced/tree/master/native /// [`iced_native`]: https://github.com/hecrj/iced/tree/master/native
pub fn mouse_cursor(mouse_cursor: MouseCursor) -> winit::window::CursorIcon { pub fn mouse_interaction(
match mouse_cursor { interaction: mouse::Interaction,
MouseCursor::Idle => winit::window::CursorIcon::Default, ) -> winit::window::CursorIcon {
MouseCursor::Pointer => winit::window::CursorIcon::Hand, use mouse::Interaction;
MouseCursor::Working => winit::window::CursorIcon::Progress,
MouseCursor::Grab => winit::window::CursorIcon::Grab, match interaction {
MouseCursor::Grabbing => winit::window::CursorIcon::Grabbing, Interaction::Idle => winit::window::CursorIcon::Default,
MouseCursor::Crosshair => winit::window::CursorIcon::Crosshair, Interaction::Pointer => winit::window::CursorIcon::Hand,
MouseCursor::Text => winit::window::CursorIcon::Text, Interaction::Working => winit::window::CursorIcon::Progress,
MouseCursor::ResizingHorizontally => { Interaction::Grab => winit::window::CursorIcon::Grab,
Interaction::Grabbing => winit::window::CursorIcon::Grabbing,
Interaction::Crosshair => winit::window::CursorIcon::Crosshair,
Interaction::Text => winit::window::CursorIcon::Text,
Interaction::ResizingHorizontally => {
winit::window::CursorIcon::EwResize winit::window::CursorIcon::EwResize
} }
MouseCursor::ResizingVertically => winit::window::CursorIcon::NsResize, Interaction::ResizingVertically => winit::window::CursorIcon::NsResize,
} }
} }