Skip to content

Commit

Permalink
feat: add Hide variant to mouse Interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
wash2 committed Oct 7, 2024
1 parent 423ad32 commit 255e7f7
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 15 deletions.
1 change: 1 addition & 0 deletions core/src/mouse/interaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ pub enum Interaction {
Move,
Copy,
Help,
Hide,
}
9 changes: 6 additions & 3 deletions winit/src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,10 +437,10 @@ pub fn mode(mode: Option<winit::window::Fullscreen>) -> window::Mode {
/// [`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 {
Some(match interaction {
Interaction::None | Interaction::Idle => {
winit::window::CursorIcon::Default
}
Expand All @@ -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.
Expand Down
49 changes: 37 additions & 12 deletions winit/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 255e7f7

Please sign in to comment.