Merge pull request #2685 from thorn132/interaction_hidden
Mouse interaction to hide system cursor
This commit is contained in:
commit
80a3ca7af4
4 changed files with 28 additions and 9 deletions
|
|
@ -4,6 +4,7 @@
|
|||
pub enum Interaction {
|
||||
#[default]
|
||||
None,
|
||||
Hidden,
|
||||
Idle,
|
||||
Pointer,
|
||||
Grab,
|
||||
|
|
|
|||
|
|
@ -286,11 +286,17 @@ pub fn main() -> Result<(), winit::error::EventLoopError> {
|
|||
..
|
||||
} = state
|
||||
{
|
||||
window.set_cursor(
|
||||
conversion::mouse_interaction(
|
||||
// Update the mouse cursor
|
||||
if let Some(icon) =
|
||||
iced_winit::conversion::mouse_interaction(
|
||||
mouse_interaction,
|
||||
),
|
||||
);
|
||||
)
|
||||
{
|
||||
window.set_cursor(icon);
|
||||
window.set_cursor_visible(true);
|
||||
} else {
|
||||
window.set_cursor_visible(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Draw the interface
|
||||
|
|
|
|||
|
|
@ -467,10 +467,13 @@ pub fn window_theme(mode: theme::Mode) -> Option<winit::window::Theme> {
|
|||
/// [`winit`]: https://github.com/rust-windowing/winit
|
||||
pub fn mouse_interaction(
|
||||
interaction: mouse::Interaction,
|
||||
) -> winit::window::CursorIcon {
|
||||
) -> Option<winit::window::CursorIcon> {
|
||||
use mouse::Interaction;
|
||||
|
||||
match interaction {
|
||||
let icon = match interaction {
|
||||
Interaction::Hidden => {
|
||||
return None;
|
||||
}
|
||||
Interaction::None | Interaction::Idle => {
|
||||
winit::window::CursorIcon::Default
|
||||
}
|
||||
|
|
@ -497,7 +500,9 @@ pub fn mouse_interaction(
|
|||
Interaction::Move => winit::window::CursorIcon::Move,
|
||||
Interaction::Copy => winit::window::CursorIcon::Copy,
|
||||
Interaction::Help => winit::window::CursorIcon::Help,
|
||||
}
|
||||
};
|
||||
|
||||
Some(icon)
|
||||
}
|
||||
|
||||
/// Converts a `MouseButton` from [`winit`] to an [`iced`] mouse button.
|
||||
|
|
|
|||
|
|
@ -245,8 +245,15 @@ where
|
|||
|
||||
pub fn update_mouse(&mut self, interaction: mouse::Interaction) {
|
||||
if interaction != self.mouse_interaction {
|
||||
self.raw
|
||||
.set_cursor(conversion::mouse_interaction(interaction));
|
||||
if let Some(icon) = conversion::mouse_interaction(interaction) {
|
||||
self.raw.set_cursor(icon);
|
||||
|
||||
if self.mouse_interaction == mouse::Interaction::Hidden {
|
||||
self.raw.set_cursor_visible(true);
|
||||
}
|
||||
} else {
|
||||
self.raw.set_cursor_visible(false);
|
||||
}
|
||||
|
||||
self.mouse_interaction = interaction;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue