diff options
author | 2020-04-30 08:16:38 +0200 | |
---|---|---|
committer | 2020-04-30 08:16:38 +0200 | |
commit | 98bc8cf2a7c4944d762a0148ca9f615d6ccc0d6e (patch) | |
tree | 9e22665e41793517b7ba0b48d7315d3283dfde91 | |
parent | d4c4198f7242f168de65146e0ca339e0c1cbfe9b (diff) | |
download | iced-98bc8cf2a7c4944d762a0148ca9f615d6ccc0d6e.tar.gz iced-98bc8cf2a7c4944d762a0148ca9f615d6ccc0d6e.tar.bz2 iced-98bc8cf2a7c4944d762a0148ca9f615d6ccc0d6e.zip |
Rename `MouseCursor` to `mouse::Interaction`
Diffstat (limited to '')
35 files changed, 170 insertions, 171 deletions
diff --git a/core/src/lib.rs b/core/src/lib.rs index ec1e185a..6b9e612e 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -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; diff --git a/core/src/mouse.rs b/core/src/mouse.rs index 101e04d5..25ce6ac3 100644 --- a/core/src/mouse.rs +++ b/core/src/mouse.rs @@ -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; diff --git a/core/src/mouse/interaction.rs b/core/src/mouse/interaction.rs new file mode 100644 index 00000000..664147a7 --- /dev/null +++ b/core/src/mouse/interaction.rs @@ -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 + } +} diff --git a/core/src/mouse_cursor.rs b/core/src/mouse_cursor.rs deleted file mode 100644 index 78ddb0ae..00000000 --- a/core/src/mouse_cursor.rs +++ /dev/null @@ -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 - } -} diff --git a/examples/bezier_tool/src/main.rs b/examples/bezier_tool/src/main.rs index fe4136b4..fe41e1b2 100644 --- a/examples/bezier_tool/src/main.rs +++ b/examples/bezier_tool/src/main.rs @@ -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() } } } diff --git a/examples/custom_widget/src/main.rs b/examples/custom_widget/src/main.rs index d0bceb73..f096fb54 100644 --- a/examples/custom_widget/src/main.rs +++ b/examples/custom_widget/src/main.rs @@ -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(), ) } } diff --git a/examples/game_of_life/src/main.rs b/examples/game_of_life/src/main.rs index 5a58a8cb..f0891db1 100644 --- a/examples/game_of_life/src/main.rs +++ b/examples/game_of_life/src/main.rs @@ -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(), } } } diff --git a/examples/geometry/src/main.rs b/examples/geometry/src/main.rs index 2a3efd4a..aabe6b21 100644 --- a/examples/geometry/src/main.rs +++ b/examples/geometry/src/main.rs @@ -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(), ) } } diff --git a/examples/integration/src/main.rs b/examples/integration/src/main.rs index da571ed1..92d2fa8d 100644 --- a/examples/integration/src/main.rs +++ b/examples/integration/src/main.rs @@ -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, + ), + ); } _ => {} } diff --git a/native/src/lib.rs b/native/src/lib.rs index 88bf4423..9882803f 100644 --- a/native/src/lib.rs +++ b/native/src/lib.rs @@ -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}; diff --git a/native/src/window/backend.rs b/native/src/window/backend.rs index 3bc691cd..892d4bb9 100644 --- a/native/src/window/backend.rs +++ b/native/src/window/backend.rs @@ -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; } @@ -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, }; diff --git a/src/mouse.rs b/src/mouse.rs index c511399b..d61ed09a 100644 --- a/src/mouse.rs +++ b/src/mouse.rs @@ -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}; diff --git a/web/src/lib.rs b/web/src/lib.rs index 3fe98dfb..53b54b7e 100644 --- a/web/src/lib.rs +++ b/web/src/lib.rs @@ -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; diff --git a/wgpu/src/renderer.rs b/wgpu/src/renderer.rs index dccd0d82..71b4af38 100644 --- a/wgpu/src/renderer.rs +++ b/wgpu/src/renderer.rs @@ -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>( diff --git a/wgpu/src/renderer/widget/button.rs b/wgpu/src/renderer/widget/button.rs index 5e55873a..eb225038 100644 --- a/wgpu/src/renderer/widget/button.rs +++ b/wgpu/src/renderer/widget/button.rs @@ -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() }, ) } diff --git a/wgpu/src/renderer/widget/checkbox.rs b/wgpu/src/renderer/widget/checkbox.rs index 7f7f6de3..0340bf62 100644 --- a/wgpu/src/renderer/widget/checkbox.rs +++ b/wgpu/src/renderer/widget/checkbox.rs @@ -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() }, ) } diff --git a/wgpu/src/renderer/widget/column.rs b/wgpu/src/renderer/widget/column.rs index e6a9d8f0..b853276d 100644 --- a/wgpu/src/renderer/widget/column.rs +++ b/wgpu/src/renderer/widget/column.rs @@ -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, ) } } diff --git a/wgpu/src/renderer/widget/container.rs b/wgpu/src/renderer/widget/container.rs index dda7dc8a..30cc3f07 100644 --- a/wgpu/src/renderer/widget/container.rs +++ b/wgpu/src/renderer/widget/container.rs @@ -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) } } } diff --git a/wgpu/src/renderer/widget/image.rs b/wgpu/src/renderer/widget/image.rs index 6b7f1c60..c4c04984 100644 --- a/wgpu/src/renderer/widget/image.rs +++ b/wgpu/src/renderer/widget/image.rs @@ -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(), ) } } diff --git a/wgpu/src/renderer/widget/pane_grid.rs b/wgpu/src/renderer/widget/pane_grid.rs index 80e2471f..2253e4af 100644 --- a/wgpu/src/renderer/widget/pane_grid.rs +++ b/wgpu/src/renderer/widget/pane_grid.rs @@ -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 }, ) } diff --git a/wgpu/src/renderer/widget/progress_bar.rs b/wgpu/src/renderer/widget/progress_bar.rs index fe032fbf..2baeeb14 100644 --- a/wgpu/src/renderer/widget/progress_bar.rs +++ b/wgpu/src/renderer/widget/progress_bar.rs @@ -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(), ) } } diff --git a/wgpu/src/renderer/widget/radio.rs b/wgpu/src/renderer/widget/radio.rs index 551700c8..2f1461db 100644 --- a/wgpu/src/renderer/widget/radio.rs +++ b/wgpu/src/renderer/widget/radio.rs @@ -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() }, ) } diff --git a/wgpu/src/renderer/widget/row.rs b/wgpu/src/renderer/widget/row.rs index c6a10c07..d0b7ef09 100644 --- a/wgpu/src/renderer/widget/row.rs +++ b/wgpu/src/renderer/widget/row.rs @@ -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, ) } } diff --git a/wgpu/src/renderer/widget/scrollable.rs b/wgpu/src/renderer/widget/scrollable.rs index 732523e3..8a400b82 100644 --- a/wgpu/src/renderer/widget/scrollable.rs +++ b/wgpu/src/renderer/widget/scrollable.rs @@ -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 }, ) } diff --git a/wgpu/src/renderer/widget/slider.rs b/wgpu/src/renderer/widget/slider.rs index 335e1b92..220feace 100644 --- a/wgpu/src/renderer/widget/slider.rs +++ b/wgpu/src/renderer/widget/slider.rs @@ -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() }, ) } diff --git a/wgpu/src/renderer/widget/space.rs b/wgpu/src/renderer/widget/space.rs index 9ec0ed6d..225f7e6c 100644 --- a/wgpu/src/renderer/widget/space.rs +++ b/wgpu/src/renderer/widget/space.rs @@ -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()) } } diff --git a/wgpu/src/renderer/widget/svg.rs b/wgpu/src/renderer/widget/svg.rs index 4ee983ea..f6d6d0ba 100644 --- a/wgpu/src/renderer/widget/svg.rs +++ b/wgpu/src/renderer/widget/svg.rs @@ -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(), ) } } diff --git a/wgpu/src/renderer/widget/text.rs b/wgpu/src/renderer/widget/text.rs index 4a4ecef4..4605ed06 100644 --- a/wgpu/src/renderer/widget/text.rs +++ b/wgpu/src/renderer/widget/text.rs @@ -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(), ) } } diff --git a/wgpu/src/renderer/widget/text_input.rs b/wgpu/src/renderer/widget/text_input.rs index 97eb0114..57be6692 100644 --- a/wgpu/src/renderer/widget/text_input.rs +++ b/wgpu/src/renderer/widget/text_input.rs @@ -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() }, ) } diff --git a/wgpu/src/widget/canvas.rs b/wgpu/src/widget/canvas.rs index 05306e67..2fc10ea0 100644 --- a/wgpu/src/widget/canvas.rs +++ b/wgpu/src/widget/canvas.rs @@ -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), ) } diff --git a/wgpu/src/widget/canvas/program.rs b/wgpu/src/widget/canvas/program.rs index 5b995bfa..725d9d72 100644 --- a/wgpu/src/widget/canvas/program.rs +++ b/wgpu/src/widget/canvas/program.rs @@ -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) } } diff --git a/wgpu/src/window/backend.rs b/wgpu/src/window/backend.rs index e1b77700..7e40ae0c 100644 --- a/wgpu/src/window/backend.rs +++ b/wgpu/src/window/backend.rs @@ -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 } } diff --git a/winit/src/application.rs b/winit/src/application.rs index ae9775f7..f6bc8fcc 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -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! diff --git a/winit/src/conversion.rs b/winit/src/conversion.rs index 93827e37..b887db6e 100644 --- a/winit/src/conversion.rs +++ b/winit/src/conversion.rs @@ -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, } } |