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

View File

@ -1,6 +1,8 @@
//! Reuse basic mouse types.
mod button;
mod event;
mod interaction;
pub use button::Button;
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 {
use iced::{
canvas::{self, Canvas, Cursor, Event, Frame, Geometry, Path, Stroke},
mouse, Element, Length, MouseCursor, Point, Rectangle,
mouse, Element, Length, Point, Rectangle,
};
#[derive(Default)]
@ -166,15 +166,15 @@ mod bezier {
}
}
fn mouse_cursor(
fn mouse_interaction(
&self,
bounds: Rectangle,
cursor: Cursor,
) -> MouseCursor {
) -> mouse::Interaction {
if cursor.is_over(&bounds) {
MouseCursor::Crosshair
mouse::Interaction::Crosshair
} 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
// implemented by `iced_wgpu` and other renderers.
use iced_native::{
layout, Background, Color, Element, Hasher, Layout, Length,
MouseCursor, Point, Size, Widget,
layout, mouse, Background, Color, Element, Hasher, Layout, Length,
Point, Size, Widget,
};
use iced_wgpu::{Defaults, Primitive, Renderer};
@ -57,7 +57,7 @@ mod circle {
_defaults: &Defaults,
layout: Layout<'_>,
_cursor_position: Point,
) -> (Primitive, MouseCursor) {
) -> (Primitive, mouse::Interaction) {
(
Primitive::Quad {
bounds: layout.bounds(),
@ -66,7 +66,7 @@ mod circle {
border_width: 0,
border_color: Color::TRANSPARENT,
},
MouseCursor::default(),
mouse::Interaction::default(),
)
}
}

View File

@ -157,8 +157,7 @@ impl Application for GameOfLife {
mod grid {
use iced::{
canvas::{self, Canvas, Cursor, Event, Frame, Geometry, Path},
mouse, Color, Element, Length, MouseCursor, Point, Rectangle, Size,
Vector,
mouse, Color, Element, Length, Point, Rectangle, Size, Vector,
};
use std::collections::{HashMap, HashSet};
@ -397,16 +396,20 @@ mod grid {
vec![life, hovered_cell]
}
fn mouse_cursor(
fn mouse_interaction(
&self,
bounds: Rectangle,
cursor: Cursor,
) -> MouseCursor {
) -> mouse::Interaction {
match self.interaction {
Some(Interaction::Drawing) => MouseCursor::Crosshair,
Some(Interaction::Panning { .. }) => MouseCursor::Grabbing,
None if cursor.is_over(&bounds) => MouseCursor::Crosshair,
_ => MouseCursor::default(),
Some(Interaction::Drawing) => mouse::Interaction::Crosshair,
Some(Interaction::Panning { .. }) => {
mouse::Interaction::Grabbing
}
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
// implemented by `iced_wgpu` and other renderers.
use iced_native::{
layout, Element, Hasher, Layout, Length, MouseCursor, Point, Size,
Vector, Widget,
layout, mouse, Element, Hasher, Layout, Length, Point, Size, Vector,
Widget,
};
use iced_wgpu::{
triangle::{Mesh2D, Vertex2D},
@ -54,7 +54,7 @@ mod rainbow {
_defaults: &Defaults,
layout: Layout<'_>,
cursor_position: Point,
) -> (Primitive, MouseCursor) {
) -> (Primitive, mouse::Interaction) {
let b = layout.bounds();
// 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,
};
use iced_winit::{
futures, winit, Cache, Clipboard, MouseCursor, Size, UserInterface,
futures, mouse, winit, Cache, Clipboard, Size, UserInterface,
};
use winit::{
@ -63,7 +63,7 @@ pub fn main() {
let mut events = Vec::new();
let mut cache = Some(Cache::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);
// Initialize scene and GUI controls
@ -189,7 +189,7 @@ pub fn main() {
scene.draw(&mut encoder, &frame.view);
// And then iced on top
let mouse_cursor = renderer.draw(
let mouse_interaction = renderer.draw(
&mut device,
&mut encoder,
Target {
@ -205,9 +205,11 @@ pub fn main() {
queue.submit(&[encoder.finish()]);
// And update the mouse cursor
window.set_cursor_icon(iced_winit::conversion::mouse_cursor(
mouse_cursor,
));
window.set_cursor_icon(
iced_winit::conversion::mouse_interaction(
mouse_interaction,
),
);
}
_ => {}
}

View File

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

View File

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

View File

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

View File

@ -1,2 +1,2 @@
//! 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 iced_core::{
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 subscription::Subscription;

View File

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

View File

@ -1,6 +1,6 @@
use crate::{button::StyleSheet, defaults, Defaults, Primitive, Renderer};
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 {
@ -84,9 +84,9 @@ impl iced_native::button::Renderer for Renderer {
content
},
if is_mouse_over {
MouseCursor::Pointer
mouse::Interaction::Pointer
} else {
MouseCursor::default()
mouse::Interaction::default()
},
)
}

View File

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

View File

@ -1,5 +1,5 @@
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 {
fn draw<Message>(
@ -9,7 +9,7 @@ impl column::Renderer for Renderer {
layout: Layout<'_>,
cursor_position: Point,
) -> Self::Output {
let mut mouse_cursor = MouseCursor::default();
let mut mouse_interaction = mouse::Interaction::default();
(
Primitive::Group {
@ -17,18 +17,18 @@ impl column::Renderer for Renderer {
.iter()
.zip(layout.children())
.map(|(child, layout)| {
let (primitive, new_mouse_cursor) =
let (primitive, new_mouse_interaction) =
child.draw(self, defaults, layout, cursor_position);
if new_mouse_cursor > mouse_cursor {
mouse_cursor = new_mouse_cursor;
if new_mouse_interaction > mouse_interaction {
mouse_interaction = new_mouse_interaction;
}
primitive
})
.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);
if style.background.is_some() || style.border_width > 0 {
@ -39,10 +39,10 @@ impl iced_native::container::Renderer for Renderer {
Primitive::Group {
primitives: vec![quad, content],
},
mouse_cursor,
mouse_interaction,
)
} else {
(content, mouse_cursor)
(content, mouse_interaction)
}
}
}

View File

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

View File

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

View File

@ -1,5 +1,5 @@
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 {
type Style = Box<dyn StyleSheet>;
@ -48,7 +48,7 @@ impl progress_bar::Renderer for Renderer {
} else {
background
},
MouseCursor::default(),
mouse::Interaction::default(),
)
}
}

View File

@ -1,5 +1,5 @@
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 DOT_SIZE: f32 = SIZE / 2.0;
@ -55,9 +55,9 @@ impl radio::Renderer for Renderer {
},
},
if is_mouse_over {
MouseCursor::Pointer
mouse::Interaction::Pointer
} else {
MouseCursor::default()
mouse::Interaction::default()
},
)
}

View File

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

View File

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

View File

@ -2,7 +2,7 @@ use crate::{
slider::{HandleShape, StyleSheet},
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;
@ -95,11 +95,11 @@ impl slider::Renderer for Renderer {
primitives: vec![rail_top, rail_bottom, handle],
},
if is_dragging {
MouseCursor::Grabbing
mouse::Interaction::Grabbing
} else if is_mouse_over {
MouseCursor::Grab
mouse::Interaction::Grab
} else {
MouseCursor::default()
mouse::Interaction::default()
},
)
}

View File

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

View File

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

View File

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

View File

@ -9,8 +9,8 @@
use crate::{Defaults, Primitive, Renderer};
use iced_native::{
layout, Clipboard, Element, Hasher, Layout, Length, MouseCursor, Point,
Size, Vector, Widget,
layout, mouse, Clipboard, Element, Hasher, Layout, Length, Point, Size,
Vector, Widget,
};
use std::hash::Hash;
use std::marker::PhantomData;
@ -192,7 +192,7 @@ impl<Message, P: Program<Message>> Widget<Message, Renderer>
_defaults: &Defaults,
layout: Layout<'_>,
cursor_position: Point,
) -> (Primitive, MouseCursor) {
) -> (Primitive, mouse::Interaction) {
let bounds = layout.bounds();
let translation = Vector::new(bounds.x, bounds.y);
let cursor = Cursor::from_window_position(cursor_position);
@ -209,7 +209,7 @@ impl<Message, P: Program<Message>> Widget<Message, Renderer>
.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 iced_native::{MouseCursor, Rectangle};
use iced_native::{mouse, Rectangle};
/// The state and logic of a [`Canvas`].
///
@ -42,15 +42,19 @@ pub trait Program<Message> {
/// [`Cache`]: struct.Cache.html
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`].
///
/// [`Program`]: trait.Program.html
/// [`Canvas`]: struct.Canvas.html
fn mouse_cursor(&self, _bounds: Rectangle, _cursor: Cursor) -> MouseCursor {
MouseCursor::default()
fn mouse_interaction(
&self,
_bounds: Rectangle,
_cursor: Cursor,
) -> mouse::Interaction {
mouse::Interaction::default()
}
}
@ -71,7 +75,11 @@ where
T::draw(self, bounds, cursor)
}
fn mouse_cursor(&self, bounds: Rectangle, cursor: Cursor) -> MouseCursor {
T::mouse_cursor(self, bounds, cursor)
fn mouse_interaction(
&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 iced_native::{futures, MouseCursor};
use iced_native::{futures, mouse};
use raw_window_handle::HasRawWindowHandle;
/// 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,
scale_factor: f64,
overlay: &[T],
) -> MouseCursor {
) -> mouse::Interaction {
let (frame, viewport) = swap_chain.next_frame().expect("Next frame");
let mut encoder = self.device.create_command_encoder(
@ -101,7 +101,7 @@ impl iced_native::window::Backend for Backend {
depth_stencil_attachment: None,
});
let mouse_cursor = renderer.draw(
let mouse_interaction = renderer.draw(
&mut self.device,
&mut encoder,
Target {
@ -115,6 +115,6 @@ impl iced_native::window::Backend for Backend {
self.queue.submit(&[encoder.finish()]);
mouse_cursor
mouse_interaction
}
}

View File

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

View File

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