Show resize mouse cursor when resizing windows

This commit is contained in:
Emil Ernerfeldt 2020-04-20 10:01:13 +02:00
parent 472e0b9afe
commit 98178e9d69
4 changed files with 31 additions and 2 deletions

View file

@ -4,6 +4,18 @@ use parking_lot::Mutex;
use crate::{layout::align_rect, *};
#[derive(Clone, Copy)]
pub enum CursorIcon {
Default,
ResizeNorthWestSouthEast,
}
impl Default for CursorIcon {
fn default() -> Self {
CursorIcon::Default
}
}
/// Contains the input, style and output of all GUI commands.
pub struct Context {
/// The default style for new regions
@ -13,6 +25,9 @@ pub struct Context {
pub(crate) memory: Mutex<Memory>,
pub(crate) graphics: Mutex<GraphicLayers>,
/// Set each frame to what the mouse cursor should look like.
pub cursor_icon: Mutex<CursorIcon>,
/// Used to debug name clashes of e.g. windows
used_ids: Mutex<HashMap<Id, Pos2>>,
}
@ -26,6 +41,7 @@ impl Clone for Context {
input: self.input,
memory: Mutex::new(self.memory.lock().clone()),
graphics: Mutex::new(self.graphics.lock().clone()),
cursor_icon: Mutex::new(self.cursor_icon.lock().clone()),
used_ids: Mutex::new(self.used_ids.lock().clone()),
}
}
@ -39,6 +55,7 @@ impl Context {
input: Default::default(),
memory: Default::default(),
graphics: Default::default(),
cursor_icon: Default::default(),
used_ids: Default::default(),
}
}
@ -59,6 +76,7 @@ impl Context {
pub fn new_frame(&mut self, gui_input: GuiInput) {
self.used_ids.lock().clear();
self.input = gui_input;
*self.cursor_icon.lock() = CursorIcon::Default;
if !gui_input.mouse_down || gui_input.mouse_pos.is_none() {
self.memory.lock().active_id = None;
}

View file

@ -28,7 +28,7 @@ mod window;
pub use {
crate::emigui::Emigui,
color::Color,
context::Context,
context::{Context, CursorIcon},
fonts::{FontDefinitions, Fonts, TextStyle},
id::Id,
layers::*,

View file

@ -170,6 +170,10 @@ impl Window {
state.rect = state.rect.translate(ctx.input().mouse_move);
}
if corner_interact.hovered || corner_interact.active {
*ctx.cursor_icon.lock() = CursorIcon::ResizeNorthWestSouthEast;
}
let mut memory = ctx.memory.lock();
if win_interact.active || corner_interact.active {
memory.move_window_to_top(id);

View file

@ -8,7 +8,7 @@ use {
label,
math::*,
widgets::{Button, Label},
Align, Emigui, Window,
Align, CursorIcon, Emigui, Window,
},
emigui_glium::Painter,
glium::glutin,
@ -110,5 +110,12 @@ fn main() {
let mesh = emigui.paint();
painter.paint(&display, mesh, emigui.texture());
let cursor = *emigui.ctx.cursor_icon.lock();
let cursor = match cursor {
CursorIcon::Default => glutin::MouseCursor::Default,
CursorIcon::ResizeNorthWestSouthEast => glutin::MouseCursor::NwseResize,
};
display.gl_window().set_cursor(cursor);
}
}