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

@ -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
}
}