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 3032cec
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 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
23 changes: 20 additions & 3 deletions winit/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,22 @@ where
compositor.load_font(font);
}

let hide_cursor = winit::window::CustomCursor::from_rgba(
[0, 0, 0, 0],
1,
1,
0,
0,
)
.unwrap();
let hide_cursor =
event_loop.create_custom_cursor(hide_cursor).unwrap();

sender
.send(Boot {
compositor,
is_wayland,
hide_cursor: winit::window::Cursor::Custom(hide_cursor),
})
.ok()
.expect("Send boot event");
Expand Down Expand Up @@ -639,6 +651,7 @@ where
struct Boot<C> {
compositor: C,
is_wayland: bool,
hide_cursor: winit::window::Cursor,
}

pub(crate) enum Event<Message: 'static> {
Expand Down Expand Up @@ -705,6 +718,7 @@ async fn run_instance<'a, P, C>(
let Boot {
mut compositor,
is_wayland,
hide_cursor,
} = boot.await.expect("Receive boot");

let mut platform_specific_handler =
Expand Down Expand Up @@ -1173,7 +1187,8 @@ async fn run_instance<'a, P, C>(
conversion::mouse_interaction(
new_mouse_interaction,
)
.into(),
.map(|c| c.into())
.unwrap_or_else(|| hide_cursor.clone()),
);

window.mouse_interaction = new_mouse_interaction;
Expand Down Expand Up @@ -1342,7 +1357,8 @@ async fn run_instance<'a, P, C>(
conversion::mouse_interaction(
new_mouse_interaction,
)
.into(),
.map(|c| c.into())
.unwrap_or_else(|| hide_cursor.clone()),
);

window.mouse_interaction =
Expand Down Expand Up @@ -1677,7 +1693,8 @@ async fn run_instance<'a, P, C>(
conversion::mouse_interaction(
new_mouse_interaction,
)
.into(),
.map(|c| c.into())
.unwrap_or_else(|| hide_cursor.clone()),
);

window.mouse_interaction = new_mouse_interaction;
Expand Down

0 comments on commit 3032cec

Please sign in to comment.