ui: Add mouse helper methods is_mouse_{dragging,down,clicked}

This commit defines a new enum: `ImMouseButton`, which is used in the
public-facing API of mouse-related methods.

The discriminant values of the ImMouseButton enum are the value used
internally by ImGui to represent the buttons of the mouse.
This commit is contained in:
Malik Olivier Boussejra 2018-03-26 15:41:03 +09:00
parent a60465cd40
commit 15048ad698

View File

@ -86,6 +86,15 @@ pub fn get_version() -> &'static str {
}
}
/// Represents one of the buttons of the mouse
pub enum ImMouseButton {
Left = 0,
Right = 1,
Middle = 2,
Extra1 = 3,
Extra2 = 4,
}
impl ImGui {
pub fn init() -> ImGui {
ImGui {
@ -231,6 +240,25 @@ impl ImGui {
sys::igGetMouseCursor()
}
}
/// Returns `true` if mouse is currently dragging with the `button` provided
/// as argument.
pub fn is_mouse_dragging(&self, button: ImMouseButton) -> bool {
unsafe {
sys::igIsMouseDragging(button as c_int, -1.0)
}
}
/// Returns `true` if the `button` provided as argument is currently down.
pub fn is_mouse_down(&self, button: ImMouseButton) -> bool {
unsafe {
sys::igIsMouseDown(button as c_int)
}
}
/// Returns `true` if the `button` provided as argument is being clicked.
pub fn is_mouse_clicked(&self, button: ImMouseButton) -> bool {
unsafe {
sys::igIsMouseClicked(button as c_int, false)
}
}
pub fn key_ctrl(&self) -> bool {
let io = self.io();
io.key_ctrl