summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2023-06-09 21:53:54 +0200
committerLibravatar GitHub <noreply@github.com>2023-06-09 21:53:54 +0200
commit60cd864d43be877a5eaee4f5ca32f41b9fb70b79 (patch)
tree01a7758d3b8a4d2434bba113df85c6cb2c3e2ca2 /examples
parentc15f1b5f6575792cc89bb5fba2e613428397e46a (diff)
parent27639c4ce6161fa07986c2f1d472a8a259ae2129 (diff)
downloadiced-60cd864d43be877a5eaee4f5ca32f41b9fb70b79.tar.gz
iced-60cd864d43be877a5eaee4f5ca32f41b9fb70b79.tar.bz2
iced-60cd864d43be877a5eaee4f5ca32f41b9fb70b79.zip
Merge pull request #1904 from iced-rs/cursor-availability
Cursor availability
Diffstat (limited to 'examples')
-rw-r--r--examples/arc/src/main.rs5
-rw-r--r--examples/bezier_tool/src/main.rs18
-rw-r--r--examples/clock/src/main.rs7
-rw-r--r--examples/color_palette/src/main.rs10
-rw-r--r--examples/custom_quad/src/main.rs5
-rw-r--r--examples/custom_widget/src/main.rs5
-rw-r--r--examples/game_of_life/src/main.rs26
-rw-r--r--examples/geometry/src/main.rs40
-rw-r--r--examples/integration/src/main.rs43
-rw-r--r--examples/modal/src/main.rs35
-rw-r--r--examples/multitouch/src/main.rs7
-rw-r--r--examples/pane_grid/src/main.rs2
-rw-r--r--examples/sierpinski_triangle/src/main.rs17
-rw-r--r--examples/solar_system/src/main.rs5
-rw-r--r--examples/toast/src/main.rs42
15 files changed, 138 insertions, 129 deletions
diff --git a/examples/arc/src/main.rs b/examples/arc/src/main.rs
index 80ad0b5b..df565859 100644
--- a/examples/arc/src/main.rs
+++ b/examples/arc/src/main.rs
@@ -1,8 +1,9 @@
use std::{f32::consts::PI, time::Instant};
use iced::executor;
+use iced::mouse;
use iced::widget::canvas::{
- self, stroke, Cache, Canvas, Cursor, Geometry, Path, Stroke,
+ self, stroke, Cache, Canvas, Geometry, Path, Stroke,
};
use iced::{
Application, Command, Element, Length, Point, Rectangle, Renderer,
@@ -78,7 +79,7 @@ impl<Message> canvas::Program<Message> for Arc {
renderer: &Renderer,
theme: &Theme,
bounds: Rectangle,
- _cursor: Cursor,
+ _cursor: mouse::Cursor,
) -> Vec<Geometry> {
let geometry = self.cache.draw(renderer, bounds.size(), |frame| {
let palette = theme.palette();
diff --git a/examples/bezier_tool/src/main.rs b/examples/bezier_tool/src/main.rs
index f1c83a16..310be28f 100644
--- a/examples/bezier_tool/src/main.rs
+++ b/examples/bezier_tool/src/main.rs
@@ -61,9 +61,7 @@ impl Sandbox for Example {
mod bezier {
use iced::mouse;
use iced::widget::canvas::event::{self, Event};
- use iced::widget::canvas::{
- self, Canvas, Cursor, Frame, Geometry, Path, Stroke,
- };
+ use iced::widget::canvas::{self, Canvas, Frame, Geometry, Path, Stroke};
use iced::{Element, Length, Point, Rectangle, Renderer, Theme};
#[derive(Default)]
@@ -100,10 +98,10 @@ mod bezier {
state: &mut Self::State,
event: Event,
bounds: Rectangle,
- cursor: Cursor,
+ cursor: mouse::Cursor,
) -> (event::Status, Option<Curve>) {
let cursor_position =
- if let Some(position) = cursor.position_in(&bounds) {
+ if let Some(position) = cursor.position_in(bounds) {
position
} else {
return (event::Status::Ignored, None);
@@ -155,7 +153,7 @@ mod bezier {
renderer: &Renderer,
_theme: &Theme,
bounds: Rectangle,
- cursor: Cursor,
+ cursor: mouse::Cursor,
) -> Vec<Geometry> {
let content = self.state.cache.draw(
renderer,
@@ -183,9 +181,9 @@ mod bezier {
&self,
_state: &Self::State,
bounds: Rectangle,
- cursor: Cursor,
+ cursor: mouse::Cursor,
) -> mouse::Interaction {
- if cursor.is_over(&bounds) {
+ if cursor.is_over(bounds) {
mouse::Interaction::Crosshair
} else {
mouse::Interaction::default()
@@ -224,11 +222,11 @@ mod bezier {
&self,
renderer: &Renderer,
bounds: Rectangle,
- cursor: Cursor,
+ cursor: mouse::Cursor,
) -> Geometry {
let mut frame = Frame::new(renderer, bounds.size());
- if let Some(cursor_position) = cursor.position_in(&bounds) {
+ if let Some(cursor_position) = cursor.position_in(bounds) {
match *self {
Pending::One { from } => {
let line = Path::line(from, cursor_position);
diff --git a/examples/clock/src/main.rs b/examples/clock/src/main.rs
index 6425e2da..fae77bc0 100644
--- a/examples/clock/src/main.rs
+++ b/examples/clock/src/main.rs
@@ -1,7 +1,6 @@
use iced::executor;
-use iced::widget::canvas::{
- stroke, Cache, Cursor, Geometry, LineCap, Path, Stroke,
-};
+use iced::mouse;
+use iced::widget::canvas::{stroke, Cache, Geometry, LineCap, Path, Stroke};
use iced::widget::{canvas, container};
use iced::{
Application, Color, Command, Element, Length, Point, Rectangle, Renderer,
@@ -92,7 +91,7 @@ impl<Message> canvas::Program<Message, Renderer> for Clock {
renderer: &Renderer,
_theme: &Theme,
bounds: Rectangle,
- _cursor: Cursor,
+ _cursor: mouse::Cursor,
) -> Vec<Geometry> {
let clock = self.clock.draw(renderer, bounds.size(), |frame| {
let center = frame.center();
diff --git a/examples/color_palette/src/main.rs b/examples/color_palette/src/main.rs
index de01099e..736a9d53 100644
--- a/examples/color_palette/src/main.rs
+++ b/examples/color_palette/src/main.rs
@@ -1,8 +1,10 @@
-use iced::widget::canvas::{self, Canvas, Cursor, Frame, Geometry, Path};
+use iced::alignment::{self, Alignment};
+use iced::mouse;
+use iced::widget::canvas::{self, Canvas, Frame, Geometry, Path};
use iced::widget::{column, row, text, Slider};
use iced::{
- alignment, Alignment, Color, Element, Length, Point, Rectangle, Renderer,
- Sandbox, Settings, Size, Vector,
+ Color, Element, Length, Point, Rectangle, Renderer, Sandbox, Settings,
+ Size, Vector,
};
use palette::{
self, convert::FromColor, rgb::Rgb, Darken, Hsl, Lighten, ShiftHue,
@@ -246,7 +248,7 @@ impl<Message> canvas::Program<Message> for Theme {
renderer: &Renderer,
_theme: &iced::Theme,
bounds: Rectangle,
- _cursor: Cursor,
+ _cursor: mouse::Cursor,
) -> Vec<Geometry> {
let theme = self.canvas_cache.draw(renderer, bounds.size(), |frame| {
self.draw(frame);
diff --git a/examples/custom_quad/src/main.rs b/examples/custom_quad/src/main.rs
index b07f42ce..4b300116 100644
--- a/examples/custom_quad/src/main.rs
+++ b/examples/custom_quad/src/main.rs
@@ -3,7 +3,8 @@ mod quad {
use iced::advanced::layout::{self, Layout};
use iced::advanced::renderer;
use iced::advanced::widget::{self, Widget};
- use iced::{Color, Element, Length, Point, Rectangle, Size};
+ use iced::mouse;
+ use iced::{Color, Element, Length, Rectangle, Size};
pub struct CustomQuad {
size: f32,
@@ -48,7 +49,7 @@ mod quad {
_theme: &Renderer::Theme,
_style: &renderer::Style,
layout: Layout<'_>,
- _cursor_position: Point,
+ _cursor: mouse::Cursor,
_viewport: &Rectangle,
) {
renderer.fill_quad(
diff --git a/examples/custom_widget/src/main.rs b/examples/custom_widget/src/main.rs
index 7854548c..713bc62d 100644
--- a/examples/custom_widget/src/main.rs
+++ b/examples/custom_widget/src/main.rs
@@ -12,7 +12,8 @@ mod circle {
use iced::advanced::layout::{self, Layout};
use iced::advanced::renderer;
use iced::advanced::widget::{self, Widget};
- use iced::{Color, Element, Length, Point, Rectangle, Size};
+ use iced::mouse;
+ use iced::{Color, Element, Length, Rectangle, Size};
pub struct Circle {
radius: f32,
@@ -55,7 +56,7 @@ mod circle {
_theme: &Renderer::Theme,
_style: &renderer::Style,
layout: Layout<'_>,
- _cursor_position: Point,
+ _cursor: mouse::Cursor,
_viewport: &Rectangle,
) {
renderer.fill_quad(
diff --git a/examples/game_of_life/src/main.rs b/examples/game_of_life/src/main.rs
index eab8908b..e951d734 100644
--- a/examples/game_of_life/src/main.rs
+++ b/examples/game_of_life/src/main.rs
@@ -204,15 +204,14 @@ fn view_controls<'a>(
mod grid {
use crate::Preset;
+ use iced::alignment;
+ use iced::mouse;
use iced::touch;
use iced::widget::canvas;
use iced::widget::canvas::event::{self, Event};
- use iced::widget::canvas::{
- Cache, Canvas, Cursor, Frame, Geometry, Path, Text,
- };
+ use iced::widget::canvas::{Cache, Canvas, Frame, Geometry, Path, Text};
use iced::{
- alignment, mouse, Color, Element, Length, Point, Rectangle, Renderer,
- Size, Theme, Vector,
+ Color, Element, Length, Point, Rectangle, Renderer, Size, Theme, Vector,
};
use rustc_hash::{FxHashMap, FxHashSet};
use std::future::Future;
@@ -401,14 +400,14 @@ mod grid {
interaction: &mut Interaction,
event: Event,
bounds: Rectangle,
- cursor: Cursor,
+ cursor: mouse::Cursor,
) -> (event::Status, Option<Message>) {
if let Event::Mouse(mouse::Event::ButtonReleased(_)) = event {
*interaction = Interaction::None;
}
let cursor_position =
- if let Some(position) = cursor.position_in(&bounds) {
+ if let Some(position) = cursor.position_in(bounds) {
position
} else {
return (event::Status::Ignored, None);
@@ -539,7 +538,7 @@ mod grid {
renderer: &Renderer,
_theme: &Theme,
bounds: Rectangle,
- cursor: Cursor,
+ cursor: mouse::Cursor,
) -> Vec<Geometry> {
let center = Vector::new(bounds.width / 2.0, bounds.height / 2.0);
@@ -568,10 +567,9 @@ mod grid {
let overlay = {
let mut frame = Frame::new(renderer, bounds.size());
- let hovered_cell =
- cursor.position_in(&bounds).map(|position| {
- Cell::at(self.project(position, frame.size()))
- });
+ let hovered_cell = cursor.position_in(bounds).map(|position| {
+ Cell::at(self.project(position, frame.size()))
+ });
if let Some(cell) = hovered_cell {
frame.with_save(|frame| {
@@ -670,13 +668,13 @@ mod grid {
&self,
interaction: &Interaction,
bounds: Rectangle,
- cursor: Cursor,
+ cursor: mouse::Cursor,
) -> mouse::Interaction {
match interaction {
Interaction::Drawing => mouse::Interaction::Crosshair,
Interaction::Erasing => mouse::Interaction::Crosshair,
Interaction::Panning { .. } => mouse::Interaction::Grabbing,
- Interaction::None if cursor.is_over(&bounds) => {
+ Interaction::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 a4183db9..29f78ea1 100644
--- a/examples/geometry/src/main.rs
+++ b/examples/geometry/src/main.rs
@@ -7,9 +7,8 @@ mod rainbow {
use iced::advanced::layout::{self, Layout};
use iced::advanced::renderer;
use iced::advanced::widget::{self, Widget};
- use iced::{
- Element, Length, Point, Rectangle, Renderer, Size, Theme, Vector,
- };
+ use iced::mouse;
+ use iced::{Element, Length, Rectangle, Renderer, Size, Theme, Vector};
#[derive(Debug, Clone, Copy, Default)]
pub struct Rainbow;
@@ -44,13 +43,13 @@ mod rainbow {
_theme: &Theme,
_style: &renderer::Style,
layout: Layout<'_>,
- cursor_position: Point,
+ cursor: mouse::Cursor,
_viewport: &Rectangle,
) {
use iced::advanced::Renderer as _;
use iced_graphics::primitive::Mesh2D;
- let b = layout.bounds();
+ let bounds = layout.bounds();
// R O Y G B I V
let color_r = [1.0, 0.0, 0.0, 1.0];
@@ -63,24 +62,24 @@ mod rainbow {
let color_v = [0.75, 0.0, 0.5, 1.0];
let posn_center = {
- if b.contains(cursor_position) {
- [cursor_position.x - b.x, cursor_position.y - b.y]
+ if let Some(cursor_position) = cursor.position_in(bounds) {
+ [cursor_position.x, cursor_position.y]
} else {
- [b.width / 2.0, b.height / 2.0]
+ [bounds.width / 2.0, bounds.height / 2.0]
}
};
let posn_tl = [0.0, 0.0];
- let posn_t = [b.width / 2.0, 0.0];
- let posn_tr = [b.width, 0.0];
- let posn_r = [b.width, b.height / 2.0];
- let posn_br = [b.width, b.height];
- let posn_b = [(b.width / 2.0), b.height];
- let posn_bl = [0.0, b.height];
- let posn_l = [0.0, b.height / 2.0];
+ let posn_t = [bounds.width / 2.0, 0.0];
+ let posn_tr = [bounds.width, 0.0];
+ let posn_r = [bounds.width, bounds.height / 2.0];
+ let posn_br = [bounds.width, bounds.height];
+ let posn_b = [(bounds.width / 2.0), bounds.height];
+ let posn_bl = [0.0, bounds.height];
+ let posn_l = [0.0, bounds.height / 2.0];
let mesh = Primitive::SolidMesh {
- size: b.size(),
+ size: bounds.size(),
buffers: Mesh2D {
vertices: vec![
ColoredVertex2D {
@@ -133,9 +132,12 @@ mod rainbow {
},
};
- renderer.with_translation(Vector::new(b.x, b.y), |renderer| {
- renderer.draw_primitive(mesh);
- });
+ renderer.with_translation(
+ Vector::new(bounds.x, bounds.y),
+ |renderer| {
+ renderer.draw_primitive(mesh);
+ },
+ );
}
}
diff --git a/examples/integration/src/main.rs b/examples/integration/src/main.rs
index c935aca7..342d4c69 100644
--- a/examples/integration/src/main.rs
+++ b/examples/integration/src/main.rs
@@ -6,6 +6,7 @@ use scene::Scene;
use iced_wgpu::graphics::Viewport;
use iced_wgpu::{wgpu, Backend, Renderer, Settings};
+use iced_winit::core::mouse;
use iced_winit::core::renderer;
use iced_winit::core::{Color, Size};
use iced_winit::runtime::program;
@@ -14,7 +15,6 @@ use iced_winit::style::Theme;
use iced_winit::{conversion, futures, winit, Clipboard};
use winit::{
- dpi::PhysicalPosition,
event::{Event, ModifiersState, WindowEvent},
event_loop::{ControlFlow, EventLoop},
};
@@ -39,6 +39,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
.and_then(|element| element.dyn_into::<HtmlCanvasElement>().ok())
.expect("Get canvas element")
};
+
#[cfg(not(target_arch = "wasm32"))]
env_logger::init();
@@ -58,7 +59,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
Size::new(physical_size.width, physical_size.height),
window.scale_factor(),
);
- let mut cursor_position = PhysicalPosition::new(-1.0, -1.0);
+ let mut cursor_position = None;
let mut modifiers = ModifiersState::default();
let mut clipboard = Clipboard::connect(&window);
@@ -165,7 +166,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
Event::WindowEvent { event, .. } => {
match event {
WindowEvent::CursorMoved { position, .. } => {
- cursor_position = position;
+ cursor_position = Some(position);
}
WindowEvent::ModifiersChanged(new_modifiers) => {
modifiers = new_modifiers;
@@ -194,13 +195,20 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
// We update iced
let _ = state.update(
viewport.logical_size(),
- conversion::cursor_position(
- cursor_position,
- viewport.scale_factor(),
- ),
+ cursor_position
+ .map(|p| {
+ conversion::cursor_position(
+ p,
+ viewport.scale_factor(),
+ )
+ })
+ .map(mouse::Cursor::Available)
+ .unwrap_or(mouse::Cursor::Unavailable),
&mut renderer,
&Theme::Dark,
- &renderer::Style { text_color: Color::WHITE },
+ &renderer::Style {
+ text_color: Color::WHITE,
+ },
&mut clipboard,
&mut debug,
);
@@ -242,7 +250,9 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let program = state.program();
- let view = frame.texture.create_view(&wgpu::TextureViewDescriptor::default());
+ let view = frame.texture.create_view(
+ &wgpu::TextureViewDescriptor::default(),
+ );
{
// We clear the frame
@@ -275,15 +285,18 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
frame.present();
// Update the mouse cursor
- window.set_cursor_icon(
- iced_winit::conversion::mouse_interaction(
- state.mouse_interaction(),
- ),
- );
+ window.set_cursor_icon(
+ iced_winit::conversion::mouse_interaction(
+ state.mouse_interaction(),
+ ),
+ );
}
Err(error) => match error {
wgpu::SurfaceError::OutOfMemory => {
- panic!("Swapchain error: {error}. Rendering cannot continue.")
+ panic!(
+ "Swapchain error: {error}. \
+ Rendering cannot continue."
+ )
}
_ => {
// Try rendering again next frame.
diff --git a/examples/modal/src/main.rs b/examples/modal/src/main.rs
index 9e1e4c2f..5c43c203 100644
--- a/examples/modal/src/main.rs
+++ b/examples/modal/src/main.rs
@@ -1,10 +1,11 @@
+use iced::executor;
+use iced::keyboard;
+use iced::subscription::{self, Subscription};
+use iced::theme;
use iced::widget::{
self, button, column, container, horizontal_space, row, text, text_input,
};
-use iced::{
- executor, keyboard, subscription, theme, Alignment, Application, Command,
- Element, Event, Length, Settings, Subscription,
-};
+use iced::{Alignment, Application, Command, Element, Event, Length, Settings};
use self::modal::Modal;
@@ -254,7 +255,7 @@ mod modal {
state: &mut widget::Tree,
event: Event,
layout: Layout<'_>,
- cursor_position: Point,
+ cursor: mouse::Cursor,
renderer: &Renderer,
clipboard: &mut dyn Clipboard,
shell: &mut Shell<'_, Message>,
@@ -263,7 +264,7 @@ mod modal {
&mut state.children[0],
event,
layout,
- cursor_position,
+ cursor,
renderer,
clipboard,
shell,
@@ -277,7 +278,7 @@ mod modal {
theme: &<Renderer as advanced::Renderer>::Theme,
style: &renderer::Style,
layout: Layout<'_>,
- cursor_position: Point,
+ cursor: mouse::Cursor,
viewport: &Rectangle,
) {
self.base.as_widget().draw(
@@ -286,7 +287,7 @@ mod modal {
theme,
style,
layout,
- cursor_position,
+ cursor,
viewport,
);
}
@@ -312,14 +313,14 @@ mod modal {
&self,
state: &widget::Tree,
layout: Layout<'_>,
- cursor_position: Point,
+ cursor: mouse::Cursor,
viewport: &Rectangle,
renderer: &Renderer,
) -> mouse::Interaction {
self.base.as_widget().mouse_interaction(
&state.children[0],
layout,
- cursor_position,
+ cursor,
viewport,
renderer,
)
@@ -377,7 +378,7 @@ mod modal {
&mut self,
event: Event,
layout: Layout<'_>,
- cursor_position: Point,
+ cursor: mouse::Cursor,
renderer: &Renderer,
clipboard: &mut dyn Clipboard,
shell: &mut Shell<'_, Message>,
@@ -389,7 +390,7 @@ mod modal {
mouse::Button::Left,
)) = &event
{
- if !content_bounds.contains(cursor_position) {
+ if !cursor.is_over(content_bounds) {
shell.publish(message.clone());
return event::Status::Captured;
}
@@ -400,7 +401,7 @@ mod modal {
self.tree,
event,
layout.children().next().unwrap(),
- cursor_position,
+ cursor,
renderer,
clipboard,
shell,
@@ -413,7 +414,7 @@ mod modal {
theme: &Renderer::Theme,
style: &renderer::Style,
layout: Layout<'_>,
- cursor_position: Point,
+ cursor: mouse::Cursor,
) {
renderer.fill_quad(
renderer::Quad {
@@ -434,7 +435,7 @@ mod modal {
theme,
style,
layout.children().next().unwrap(),
- cursor_position,
+ cursor,
&layout.bounds(),
);
}
@@ -456,14 +457,14 @@ mod modal {
fn mouse_interaction(
&self,
layout: Layout<'_>,
- cursor_position: Point,
+ cursor: mouse::Cursor,
viewport: &Rectangle,
renderer: &Renderer,
) -> mouse::Interaction {
self.content.as_widget().mouse_interaction(
self.tree,
layout.children().next().unwrap(),
- cursor_position,
+ cursor,
viewport,
renderer,
)
diff --git a/examples/multitouch/src/main.rs b/examples/multitouch/src/main.rs
index 7df6c929..2830b78d 100644
--- a/examples/multitouch/src/main.rs
+++ b/examples/multitouch/src/main.rs
@@ -1,9 +1,10 @@
//! This example shows how to use touch events in `Canvas` to draw
//! a circle around each fingertip. This only works on touch-enabled
//! computers like Microsoft Surface.
+use iced::mouse;
use iced::widget::canvas::event;
use iced::widget::canvas::stroke::{self, Stroke};
-use iced::widget::canvas::{self, Canvas, Cursor, Geometry};
+use iced::widget::canvas::{self, Canvas, Geometry};
use iced::{
executor, touch, window, Application, Color, Command, Element, Length,
Point, Rectangle, Renderer, Settings, Subscription, Theme,
@@ -103,7 +104,7 @@ impl canvas::Program<Message, Renderer> for State {
_state: &mut Self::State,
event: event::Event,
_bounds: Rectangle,
- _cursor: Cursor,
+ _cursor: mouse::Cursor,
) -> (event::Status, Option<Message>) {
match event {
event::Event::Touch(touch_event) => match touch_event {
@@ -128,7 +129,7 @@ impl canvas::Program<Message, Renderer> for State {
renderer: &Renderer,
_theme: &Theme,
bounds: Rectangle,
- _cursor: Cursor,
+ _cursor: mouse::Cursor,
) -> Vec<Geometry> {
let fingerweb = self.cache.draw(renderer, bounds.size(), |frame| {
if self.fingers.len() < 2 {
diff --git a/examples/pane_grid/src/main.rs b/examples/pane_grid/src/main.rs
index 2ffdcc69..54c36d69 100644
--- a/examples/pane_grid/src/main.rs
+++ b/examples/pane_grid/src/main.rs
@@ -300,7 +300,7 @@ fn view_content<'a>(
)
]
.spacing(5)
- .max_width(150);
+ .max_width(160);
if total_panes > 1 && !is_pinned {
controls = controls.push(
diff --git a/examples/sierpinski_triangle/src/main.rs b/examples/sierpinski_triangle/src/main.rs
index 4faac6d6..885d3c63 100644
--- a/examples/sierpinski_triangle/src/main.rs
+++ b/examples/sierpinski_triangle/src/main.rs
@@ -1,6 +1,7 @@
use std::fmt::Debug;
use iced::executor;
+use iced::mouse;
use iced::widget::canvas::event::{self, Event};
use iced::widget::canvas::{self, Canvas};
use iced::widget::{column, row, slider, text};
@@ -105,14 +106,14 @@ impl canvas::Program<Message> for SierpinskiGraph {
_state: &mut Self::State,
event: Event,
bounds: Rectangle,
- cursor: canvas::Cursor,
+ cursor: mouse::Cursor,
) -> (event::Status, Option<Message>) {
- let cursor_position =
- if let Some(position) = cursor.position_in(&bounds) {
- position
- } else {
- return (event::Status::Ignored, None);
- };
+ let cursor_position = if let Some(position) = cursor.position_in(bounds)
+ {
+ position
+ } else {
+ return (event::Status::Ignored, None);
+ };
match event {
Event::Mouse(mouse_event) => {
@@ -137,7 +138,7 @@ impl canvas::Program<Message> for SierpinskiGraph {
renderer: &Renderer,
_theme: &Theme,
bounds: Rectangle,
- _cursor: canvas::Cursor,
+ _cursor: mouse::Cursor,
) -> Vec<canvas::Geometry> {
let geom = self.cache.draw(renderer, bounds.size(), |frame| {
frame.stroke(
diff --git a/examples/solar_system/src/main.rs b/examples/solar_system/src/main.rs
index d9e660d7..58d06206 100644
--- a/examples/solar_system/src/main.rs
+++ b/examples/solar_system/src/main.rs
@@ -8,11 +8,12 @@
//! [1]: https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Basic_animations#An_animated_solar_system
use iced::application;
use iced::executor;
+use iced::mouse;
use iced::theme::{self, Theme};
use iced::widget::canvas;
use iced::widget::canvas::gradient;
use iced::widget::canvas::stroke::{self, Stroke};
-use iced::widget::canvas::{Cursor, Path};
+use iced::widget::canvas::Path;
use iced::window;
use iced::{
Application, Color, Command, Element, Length, Point, Rectangle, Renderer,
@@ -161,7 +162,7 @@ impl<Message> canvas::Program<Message> for State {
renderer: &Renderer,
_theme: &Theme,
bounds: Rectangle,
- _cursor: Cursor,
+ _cursor: mouse::Cursor,
) -> Vec<canvas::Geometry> {
use std::f32::consts::PI;
diff --git a/examples/toast/src/main.rs b/examples/toast/src/main.rs
index 515218e7..395cbc10 100644
--- a/examples/toast/src/main.rs
+++ b/examples/toast/src/main.rs
@@ -1,10 +1,10 @@
+use iced::executor;
+use iced::keyboard;
+use iced::subscription::{self, Subscription};
use iced::widget::{
self, button, column, container, pick_list, row, slider, text, text_input,
};
-use iced::{
- executor, keyboard, subscription, Alignment, Application, Command, Element,
- Event, Length, Settings, Subscription,
-};
+use iced::{Alignment, Application, Command, Element, Event, Length, Settings};
use toast::{Status, Toast};
@@ -396,7 +396,7 @@ mod toast {
state: &mut Tree,
event: Event,
layout: Layout<'_>,
- cursor_position: Point,
+ cursor: mouse::Cursor,
renderer: &Renderer,
clipboard: &mut dyn Clipboard,
shell: &mut Shell<'_, Message>,
@@ -405,7 +405,7 @@ mod toast {
&mut state.children[0],
event,
layout,
- cursor_position,
+ cursor,
renderer,
clipboard,
shell,
@@ -419,7 +419,7 @@ mod toast {
theme: &Theme,
style: &renderer::Style,
layout: Layout<'_>,
- cursor_position: Point,
+ cursor: mouse::Cursor,
viewport: &Rectangle,
) {
self.content.as_widget().draw(
@@ -428,7 +428,7 @@ mod toast {
theme,
style,
layout,
- cursor_position,
+ cursor,
viewport,
);
}
@@ -437,14 +437,14 @@ mod toast {
&self,
state: &Tree,
layout: Layout<'_>,
- cursor_position: Point,
+ cursor: mouse::Cursor,
viewport: &Rectangle,
renderer: &Renderer,
) -> mouse::Interaction {
self.content.as_widget().mouse_interaction(
&state.children[0],
layout,
- cursor_position,
+ cursor,
viewport,
renderer,
)
@@ -523,7 +523,7 @@ mod toast {
&mut self,
event: Event,
layout: Layout<'_>,
- cursor_position: Point,
+ cursor: mouse::Cursor,
renderer: &Renderer,
clipboard: &mut dyn Clipboard,
shell: &mut Shell<'_, Message>,
@@ -572,7 +572,7 @@ mod toast {
state,
event.clone(),
layout,
- cursor_position,
+ cursor,
renderer,
clipboard,
&mut local_shell,
@@ -595,7 +595,7 @@ mod toast {
theme: &<Renderer as advanced::Renderer>::Theme,
style: &renderer::Style,
layout: Layout<'_>,
- cursor_position: Point,
+ cursor: mouse::Cursor,
) {
let viewport = layout.bounds();
@@ -606,13 +606,7 @@ mod toast {
.zip(layout.children())
{
child.as_widget().draw(
- state,
- renderer,
- theme,
- style,
- layout,
- cursor_position,
- &viewport,
+ state, renderer, theme, style, layout, cursor, &viewport,
);
}
}
@@ -639,7 +633,7 @@ mod toast {
fn mouse_interaction(
&self,
layout: Layout<'_>,
- cursor_position: Point,
+ cursor: mouse::Cursor,
viewport: &Rectangle,
renderer: &Renderer,
) -> mouse::Interaction {
@@ -649,11 +643,7 @@ mod toast {
.zip(layout.children())
.map(|((child, state), layout)| {
child.as_widget().mouse_interaction(
- state,
- layout,
- cursor_position,
- viewport,
- renderer,
+ state, layout, cursor, viewport, renderer,
)
})
.max()