From 15048ad6981fa5e696332e649a4d637e43f03891 Mon Sep 17 00:00:00 2001 From: Malik Olivier Boussejra Date: Mon, 26 Mar 2018 15:41:03 +0900 Subject: [PATCH] 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. --- src/lib.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 1e3a119..73a675f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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