summaryrefslogtreecommitdiffstats
path: root/examples/integration
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-06-08 20:45:48 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-06-08 20:45:48 +0200
commit733c2bd9f594a21ce20444e8edcb4c5f88118e0a (patch)
tree15c54a5e6a6a9f991d8c67a090bac4275cf963bd /examples/integration
parentaba98e49654852281ed17bedd1becac6f9db8700 (diff)
downloadiced-733c2bd9f594a21ce20444e8edcb4c5f88118e0a.tar.gz
iced-733c2bd9f594a21ce20444e8edcb4c5f88118e0a.tar.bz2
iced-733c2bd9f594a21ce20444e8edcb4c5f88118e0a.zip
Use `mouse::Cursor` in `integration` example
Diffstat (limited to 'examples/integration')
-rw-r--r--examples/integration/src/main.rs42
1 files changed, 27 insertions, 15 deletions
diff --git a/examples/integration/src/main.rs b/examples/integration/src/main.rs
index daecfeb2..342d4c69 100644
--- a/examples/integration/src/main.rs
+++ b/examples/integration/src/main.rs
@@ -15,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},
};
@@ -40,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();
@@ -59,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);
@@ -166,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;
@@ -195,13 +195,20 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
// We update iced
let _ = state.update(
viewport.logical_size(),
- mouse::Cursor::Available(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,
);
@@ -243,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
@@ -276,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.