change the mouse cursor based on context [rebuild]

This commit is contained in:
Dustin Carlino 2020-04-01 10:23:28 -07:00
parent 93227a138b
commit 199b175319
6 changed files with 41 additions and 0 deletions

View File

@ -233,6 +233,10 @@ impl PrerenderInnards {
self.display.gl_window().window().request_redraw(); self.display.gl_window().window().request_redraw();
} }
pub fn set_cursor_icon(&self, icon: winit::window::CursorIcon) {
self.display.gl_window().window().set_cursor_icon(icon);
}
pub fn draw_new_frame<'a>(&self) -> GfxCtxInnards<'a> { pub fn draw_new_frame<'a>(&self) -> GfxCtxInnards<'a> {
GfxCtxInnards { GfxCtxInnards {
target: self.display.draw(), target: self.display.draw(),

View File

@ -287,6 +287,10 @@ impl PrerenderInnards {
self.windowed_context.window().request_redraw(); self.windowed_context.window().request_redraw();
} }
pub fn set_cursor_icon(&self, icon: winit::window::CursorIcon) {
self.windowed_context.window().set_cursor_icon(icon);
}
pub fn draw_new_frame(&self) -> GfxCtxInnards { pub fn draw_new_frame(&self) -> GfxCtxInnards {
GfxCtxInnards { GfxCtxInnards {
gl: &self.gl, gl: &self.gl,

View File

@ -305,6 +305,10 @@ impl PrerenderInnards {
self.window.request_redraw(); self.window.request_redraw();
} }
pub fn set_cursor_icon(&self, icon: winit::window::CursorIcon) {
self.window.set_cursor_icon(icon);
}
pub fn draw_new_frame(&self) -> GfxCtxInnards { pub fn draw_new_frame(&self) -> GfxCtxInnards {
GfxCtxInnards { GfxCtxInnards {
gl: &self.gl, gl: &self.gl,

View File

@ -100,6 +100,12 @@ impl<'a> EventCtx<'a> {
pub fn monitor_scale_factor(&self) -> f64 { pub fn monitor_scale_factor(&self) -> f64 {
self.prerender.inner.monitor_scale_factor() self.prerender.inner.monitor_scale_factor()
} }
pub(crate) fn cursor_clickable(&mut self) {
self.prerender
.inner
.set_cursor_icon(winit::window::CursorIcon::Hand);
}
} }
pub struct LoadingScreen<'a> { pub struct LoadingScreen<'a> {

View File

@ -44,6 +44,25 @@ impl<G: GUI> State<G> {
} }
} }
// Always reset the cursor, unless we're handling an update event. If we're hovering on a
// button, we'll discover that by plumbing through the event.
if let Event::Update(_) = ev {
} else {
prerender
.inner
.set_cursor_icon(if self.canvas.drag_canvas_from.is_some() {
// We haven't run canvas_movement() yet, so we don't know if the button has been
// released. Bit of a hack to check this here, but better behavior.
if ev == Event::LeftMouseButtonUp {
winit::window::CursorIcon::Default
} else {
winit::window::CursorIcon::Grabbing
}
} else {
winit::window::CursorIcon::Default
});
}
// It's impossible / very unlikey we'll grab the cursor in map space before the very first // It's impossible / very unlikey we'll grab the cursor in map space before the very first
// start_drawing call. // start_drawing call.
let input = UserInput::new(ev, &self.canvas); let input = UserInput::new(ev, &self.canvas);

View File

@ -91,6 +91,10 @@ impl WidgetImpl for Button {
} }
} }
if self.hovering {
ctx.cursor_clickable();
}
None None
} }