From 255e7f7054967a9cadda746fc18d1eb401c1d860 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Mon, 7 Oct 2024 14:41:08 -0400 Subject: [PATCH] feat: add Hide variant to mouse Interaction --- core/src/mouse/interaction.rs | 1 + winit/src/conversion.rs | 9 ++++--- winit/src/program.rs | 49 ++++++++++++++++++++++++++--------- 3 files changed, 44 insertions(+), 15 deletions(-) diff --git a/core/src/mouse/interaction.rs b/core/src/mouse/interaction.rs index aad6a3ea93..36cf293a1d 100644 --- a/core/src/mouse/interaction.rs +++ b/core/src/mouse/interaction.rs @@ -22,4 +22,5 @@ pub enum Interaction { Move, Copy, Help, + Hide, } diff --git a/winit/src/conversion.rs b/winit/src/conversion.rs index 35bcbdfe01..1ad372a040 100644 --- a/winit/src/conversion.rs +++ b/winit/src/conversion.rs @@ -437,10 +437,10 @@ pub fn mode(mode: Option) -> window::Mode { /// [`winit`]: https://github.com/rust-windowing/winit pub fn mouse_interaction( interaction: mouse::Interaction, -) -> winit::window::CursorIcon { +) -> Option { use mouse::Interaction; - match interaction { + Some(match interaction { Interaction::None | Interaction::Idle => { winit::window::CursorIcon::Default } @@ -467,7 +467,10 @@ pub fn mouse_interaction( Interaction::Move => winit::window::CursorIcon::Move, Interaction::Copy => winit::window::CursorIcon::Copy, Interaction::Help => winit::window::CursorIcon::Help, - } + Interaction::Hide => { + return None; + } + }) } /// Converts a `MouseButton` from [`winit`] to an [`iced`] mouse button. diff --git a/winit/src/program.rs b/winit/src/program.rs index dca20c51c3..0f3660a94b 100644 --- a/winit/src/program.rs +++ b/winit/src/program.rs @@ -1169,12 +1169,21 @@ async fn run_instance<'a, P, C>( debug.draw_finished(); if new_mouse_interaction != window.mouse_interaction { - window.raw.set_cursor( + if let Some(interaction) = conversion::mouse_interaction( new_mouse_interaction, ) - .into(), - ); + { + if matches!( + window.mouse_interaction, + mouse::Interaction::Hide + ) { + window.raw.set_cursor_visible(true); + } + window.raw.set_cursor(interaction.into()) + } else { + window.raw.set_cursor_visible(false); + } window.mouse_interaction = new_mouse_interaction; } @@ -1338,12 +1347,21 @@ async fn run_instance<'a, P, C>( if new_mouse_interaction != window.mouse_interaction { - window.raw.set_cursor( + if let Some(interaction) = conversion::mouse_interaction( new_mouse_interaction, ) - .into(), - ); + { + if matches!( + window.mouse_interaction, + mouse::Interaction::Hide + ) { + window.raw.set_cursor_visible(true); + } + window.raw.set_cursor(interaction.into()) + } else { + window.raw.set_cursor_visible(false); + } window.mouse_interaction = new_mouse_interaction; @@ -1673,12 +1691,19 @@ async fn run_instance<'a, P, C>( }; if new_mouse_interaction != window.mouse_interaction { - window.raw.set_cursor( - conversion::mouse_interaction( - new_mouse_interaction, - ) - .into(), - ); + if let Some(interaction) = + conversion::mouse_interaction(new_mouse_interaction) + { + if matches!( + window.mouse_interaction, + mouse::Interaction::Hide + ) { + window.raw.set_cursor_visible(true); + } + window.raw.set_cursor(interaction.into()) + } else { + window.raw.set_cursor_visible(false); + } window.mouse_interaction = new_mouse_interaction; }