1#![allow(
10 clippy::cast_possible_truncation,
11 clippy::cast_sign_loss,
12 clippy::as_conversions
13)]
14use crate::sys;
15use bitflags::bitflags;
16
17#[repr(i32)]
19#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
20pub enum MouseButton {
21 Left = sys::ImGuiMouseButton_Left as i32,
23 Right = sys::ImGuiMouseButton_Right as i32,
25 Middle = sys::ImGuiMouseButton_Middle as i32,
27 Extra1 = 3,
29 Extra2 = 4,
31}
32
33#[repr(i32)]
35#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
36pub enum MouseCursor {
37 None = sys::ImGuiMouseCursor_None,
39 Arrow = sys::ImGuiMouseCursor_Arrow,
41 TextInput = sys::ImGuiMouseCursor_TextInput,
43 ResizeAll = sys::ImGuiMouseCursor_ResizeAll,
45 ResizeNS = sys::ImGuiMouseCursor_ResizeNS,
47 ResizeEW = sys::ImGuiMouseCursor_ResizeEW,
49 ResizeNESW = sys::ImGuiMouseCursor_ResizeNESW,
51 ResizeNWSE = sys::ImGuiMouseCursor_ResizeNWSE,
53 Hand = sys::ImGuiMouseCursor_Hand,
55 NotAllowed = sys::ImGuiMouseCursor_NotAllowed,
57}
58
59#[repr(i32)]
61#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
62pub enum Key {
63 None = sys::ImGuiKey_None as i32,
65 Tab = sys::ImGuiKey_Tab as i32,
67 LeftArrow = sys::ImGuiKey_LeftArrow as i32,
69 RightArrow = sys::ImGuiKey_RightArrow as i32,
71 UpArrow = sys::ImGuiKey_UpArrow as i32,
73 DownArrow = sys::ImGuiKey_DownArrow as i32,
75 PageUp = sys::ImGuiKey_PageUp as i32,
77 PageDown = sys::ImGuiKey_PageDown as i32,
79 Home = sys::ImGuiKey_Home as i32,
81 End = sys::ImGuiKey_End as i32,
83 Insert = sys::ImGuiKey_Insert as i32,
85 Delete = sys::ImGuiKey_Delete as i32,
87 Backspace = sys::ImGuiKey_Backspace as i32,
89 Space = sys::ImGuiKey_Space as i32,
91 Enter = sys::ImGuiKey_Enter as i32,
93 Escape = sys::ImGuiKey_Escape as i32,
95 LeftCtrl = sys::ImGuiKey_LeftCtrl as i32,
97 LeftShift = sys::ImGuiKey_LeftShift as i32,
99 LeftAlt = sys::ImGuiKey_LeftAlt as i32,
101 LeftSuper = sys::ImGuiKey_LeftSuper as i32,
103 RightCtrl = sys::ImGuiKey_RightCtrl as i32,
105 RightShift = sys::ImGuiKey_RightShift as i32,
107 RightAlt = sys::ImGuiKey_RightAlt as i32,
109 RightSuper = sys::ImGuiKey_RightSuper as i32,
111 Menu = sys::ImGuiKey_Menu as i32,
113 Key0 = sys::ImGuiKey_0 as i32,
115 Key1 = sys::ImGuiKey_1 as i32,
117 Key2 = sys::ImGuiKey_2 as i32,
119 Key3 = sys::ImGuiKey_3 as i32,
121 Key4 = sys::ImGuiKey_4 as i32,
123 Key5 = sys::ImGuiKey_5 as i32,
125 Key6 = sys::ImGuiKey_6 as i32,
127 Key7 = sys::ImGuiKey_7 as i32,
129 Key8 = sys::ImGuiKey_8 as i32,
131 Key9 = sys::ImGuiKey_9 as i32,
133 A = sys::ImGuiKey_A as i32,
135 B = sys::ImGuiKey_B as i32,
137 C = sys::ImGuiKey_C as i32,
139 D = sys::ImGuiKey_D as i32,
141 E = sys::ImGuiKey_E as i32,
143 F = sys::ImGuiKey_F as i32,
145 G = sys::ImGuiKey_G as i32,
147 H = sys::ImGuiKey_H as i32,
149 I = sys::ImGuiKey_I as i32,
151 J = sys::ImGuiKey_J as i32,
153 K = sys::ImGuiKey_K as i32,
155 L = sys::ImGuiKey_L as i32,
157 M = sys::ImGuiKey_M as i32,
159 N = sys::ImGuiKey_N as i32,
161 O = sys::ImGuiKey_O as i32,
163 P = sys::ImGuiKey_P as i32,
165 Q = sys::ImGuiKey_Q as i32,
167 R = sys::ImGuiKey_R as i32,
169 S = sys::ImGuiKey_S as i32,
171 T = sys::ImGuiKey_T as i32,
173 U = sys::ImGuiKey_U as i32,
175 V = sys::ImGuiKey_V as i32,
177 W = sys::ImGuiKey_W as i32,
179 X = sys::ImGuiKey_X as i32,
181 Y = sys::ImGuiKey_Y as i32,
183 Z = sys::ImGuiKey_Z as i32,
185 F1 = sys::ImGuiKey_F1 as i32,
187 F2 = sys::ImGuiKey_F2 as i32,
189 F3 = sys::ImGuiKey_F3 as i32,
191 F4 = sys::ImGuiKey_F4 as i32,
193 F5 = sys::ImGuiKey_F5 as i32,
195 F6 = sys::ImGuiKey_F6 as i32,
197 F7 = sys::ImGuiKey_F7 as i32,
199 F8 = sys::ImGuiKey_F8 as i32,
201 F9 = sys::ImGuiKey_F9 as i32,
203 F10 = sys::ImGuiKey_F10 as i32,
205 F11 = sys::ImGuiKey_F11 as i32,
207 F12 = sys::ImGuiKey_F12 as i32,
209
210 Apostrophe = sys::ImGuiKey_Apostrophe as i32,
213 Comma = sys::ImGuiKey_Comma as i32,
215 Minus = sys::ImGuiKey_Minus as i32,
217 Period = sys::ImGuiKey_Period as i32,
219 Slash = sys::ImGuiKey_Slash as i32,
221 Semicolon = sys::ImGuiKey_Semicolon as i32,
223 Equal = sys::ImGuiKey_Equal as i32,
225 LeftBracket = sys::ImGuiKey_LeftBracket as i32,
227 Backslash = sys::ImGuiKey_Backslash as i32,
229 RightBracket = sys::ImGuiKey_RightBracket as i32,
231 GraveAccent = sys::ImGuiKey_GraveAccent as i32,
233 CapsLock = sys::ImGuiKey_CapsLock as i32,
235 ScrollLock = sys::ImGuiKey_ScrollLock as i32,
237 NumLock = sys::ImGuiKey_NumLock as i32,
239 PrintScreen = sys::ImGuiKey_PrintScreen as i32,
241 Pause = sys::ImGuiKey_Pause as i32,
243
244 Keypad0 = sys::ImGuiKey_Keypad0 as i32,
247 Keypad1 = sys::ImGuiKey_Keypad1 as i32,
249 Keypad2 = sys::ImGuiKey_Keypad2 as i32,
251 Keypad3 = sys::ImGuiKey_Keypad3 as i32,
253 Keypad4 = sys::ImGuiKey_Keypad4 as i32,
255 Keypad5 = sys::ImGuiKey_Keypad5 as i32,
257 Keypad6 = sys::ImGuiKey_Keypad6 as i32,
259 Keypad7 = sys::ImGuiKey_Keypad7 as i32,
261 Keypad8 = sys::ImGuiKey_Keypad8 as i32,
263 Keypad9 = sys::ImGuiKey_Keypad9 as i32,
265 KeypadDecimal = sys::ImGuiKey_KeypadDecimal as i32,
267 KeypadDivide = sys::ImGuiKey_KeypadDivide as i32,
269 KeypadMultiply = sys::ImGuiKey_KeypadMultiply as i32,
271 KeypadSubtract = sys::ImGuiKey_KeypadSubtract as i32,
273 KeypadAdd = sys::ImGuiKey_KeypadAdd as i32,
275 KeypadEnter = sys::ImGuiKey_KeypadEnter as i32,
277 KeypadEqual = sys::ImGuiKey_KeypadEqual as i32,
279
280 Oem102 = sys::ImGuiKey_Oem102 as i32,
282}
283
284impl From<MouseButton> for sys::ImGuiMouseButton {
285 #[inline]
286 fn from(value: MouseButton) -> sys::ImGuiMouseButton {
287 value as sys::ImGuiMouseButton
288 }
289}
290
291impl From<Key> for sys::ImGuiKey {
292 #[inline]
293 fn from(value: Key) -> sys::ImGuiKey {
294 value as sys::ImGuiKey
295 }
296}
297
298bitflags! {
301 #[repr(transparent)]
303 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
304 pub struct InputTextFlags: i32 {
305 const NONE = sys::ImGuiInputTextFlags_None as i32;
307 const CHARS_DECIMAL = sys::ImGuiInputTextFlags_CharsDecimal as i32;
309 const CHARS_HEXADECIMAL = sys::ImGuiInputTextFlags_CharsHexadecimal as i32;
311 const CHARS_UPPERCASE = sys::ImGuiInputTextFlags_CharsUppercase as i32;
313 const CHARS_NO_BLANK = sys::ImGuiInputTextFlags_CharsNoBlank as i32;
315 const AUTO_SELECT_ALL = sys::ImGuiInputTextFlags_AutoSelectAll as i32;
317 const ENTER_RETURNS_TRUE = sys::ImGuiInputTextFlags_EnterReturnsTrue as i32;
319 const CALLBACK_COMPLETION = sys::ImGuiInputTextFlags_CallbackCompletion as i32;
321 const CALLBACK_HISTORY = sys::ImGuiInputTextFlags_CallbackHistory as i32;
323 const CALLBACK_ALWAYS = sys::ImGuiInputTextFlags_CallbackAlways as i32;
325 const CALLBACK_CHAR_FILTER = sys::ImGuiInputTextFlags_CallbackCharFilter as i32;
327 const ALLOW_TAB_INPUT = sys::ImGuiInputTextFlags_AllowTabInput as i32;
329 const CTRL_ENTER_FOR_NEW_LINE = sys::ImGuiInputTextFlags_CtrlEnterForNewLine as i32;
331 const NO_HORIZONTAL_SCROLL = sys::ImGuiInputTextFlags_NoHorizontalScroll as i32;
333 const ALWAYS_OVERWRITE = sys::ImGuiInputTextFlags_AlwaysOverwrite as i32;
335 const READ_ONLY = sys::ImGuiInputTextFlags_ReadOnly as i32;
337 const PASSWORD = sys::ImGuiInputTextFlags_Password as i32;
339 const NO_UNDO_REDO = sys::ImGuiInputTextFlags_NoUndoRedo as i32;
341 const CHARS_SCIENTIFIC = sys::ImGuiInputTextFlags_CharsScientific as i32;
343 const CALLBACK_RESIZE = sys::ImGuiInputTextFlags_CallbackResize as i32;
345 const CALLBACK_EDIT = sys::ImGuiInputTextFlags_CallbackEdit as i32;
347 }
348}
349
350impl crate::Ui {
353 #[doc(alias = "IsKeyDown")]
355 pub fn is_key_down(&self, key: Key) -> bool {
356 unsafe { sys::igIsKeyDown_Nil(key as sys::ImGuiKey) }
357 }
358
359 #[doc(alias = "IsKeyPressed")]
361 pub fn is_key_pressed(&self, key: Key) -> bool {
362 unsafe { sys::igIsKeyPressed_Bool(key as sys::ImGuiKey, true) }
363 }
364
365 #[doc(alias = "IsKeyPressed")]
367 pub fn is_key_pressed_with_repeat(&self, key: Key, repeat: bool) -> bool {
368 unsafe { sys::igIsKeyPressed_Bool(key as sys::ImGuiKey, repeat) }
369 }
370
371 #[doc(alias = "IsKeyReleased")]
373 pub fn is_key_released(&self, key: Key) -> bool {
374 unsafe { sys::igIsKeyReleased_Nil(key as sys::ImGuiKey) }
375 }
376
377 #[doc(alias = "IsMouseDown")]
379 pub fn is_mouse_down(&self, button: MouseButton) -> bool {
380 unsafe { sys::igIsMouseDown_Nil(button.into()) }
381 }
382
383 #[doc(alias = "IsMouseClicked")]
385 pub fn is_mouse_clicked(&self, button: MouseButton) -> bool {
386 unsafe { sys::igIsMouseClicked_Bool(button.into(), false) }
387 }
388
389 #[doc(alias = "IsMouseClicked")]
391 pub fn is_mouse_clicked_with_repeat(&self, button: MouseButton, repeat: bool) -> bool {
392 unsafe { sys::igIsMouseClicked_Bool(button.into(), repeat) }
393 }
394
395 #[doc(alias = "IsMouseReleased")]
397 pub fn is_mouse_released(&self, button: MouseButton) -> bool {
398 unsafe { sys::igIsMouseReleased_Nil(button.into()) }
399 }
400
401 #[doc(alias = "IsMouseDoubleClicked")]
403 pub fn is_mouse_double_clicked(&self, button: MouseButton) -> bool {
404 unsafe { sys::igIsMouseDoubleClicked_Nil(button.into()) }
405 }
406
407 #[doc(alias = "GetMousePos")]
409 pub fn mouse_pos(&self) -> [f32; 2] {
410 let pos = unsafe { sys::igGetMousePos() };
411 [pos.x, pos.y]
412 }
413
414 #[doc(alias = "GetMousePosOnOpeningCurrentPopup")]
416 pub fn mouse_pos_on_opening_current_popup(&self) -> [f32; 2] {
417 let pos = unsafe { sys::igGetMousePosOnOpeningCurrentPopup() };
418 [pos.x, pos.y]
419 }
420
421 #[doc(alias = "IsMouseHoveringRect")]
423 pub fn is_mouse_hovering_rect(&self, r_min: [f32; 2], r_max: [f32; 2]) -> bool {
424 unsafe {
425 sys::igIsMouseHoveringRect(
426 sys::ImVec2::new(r_min[0], r_min[1]),
427 sys::ImVec2::new(r_max[0], r_max[1]),
428 true,
429 )
430 }
431 }
432
433 #[doc(alias = "IsMouseHoveringRect")]
435 pub fn is_mouse_hovering_rect_with_clip(
436 &self,
437 r_min: [f32; 2],
438 r_max: [f32; 2],
439 clip: bool,
440 ) -> bool {
441 unsafe {
442 sys::igIsMouseHoveringRect(
443 sys::ImVec2::new(r_min[0], r_min[1]),
444 sys::ImVec2::new(r_max[0], r_max[1]),
445 clip,
446 )
447 }
448 }
449
450 #[doc(alias = "IsMouseDragging")]
452 pub fn is_mouse_dragging(&self, button: MouseButton) -> bool {
453 unsafe { sys::igIsMouseDragging(button as i32, -1.0) }
454 }
455
456 #[doc(alias = "IsMouseDragging")]
458 pub fn is_mouse_dragging_with_threshold(
459 &self,
460 button: MouseButton,
461 lock_threshold: f32,
462 ) -> bool {
463 unsafe { sys::igIsMouseDragging(button as i32, lock_threshold) }
464 }
465
466 #[doc(alias = "GetMouseDragDelta")]
468 pub fn mouse_drag_delta(&self, button: MouseButton) -> [f32; 2] {
469 let delta = unsafe { sys::igGetMouseDragDelta(button as i32, -1.0) };
470 [delta.x, delta.y]
471 }
472
473 #[doc(alias = "GetMouseDragDelta")]
475 pub fn mouse_drag_delta_with_threshold(
476 &self,
477 button: MouseButton,
478 lock_threshold: f32,
479 ) -> [f32; 2] {
480 let delta = unsafe { sys::igGetMouseDragDelta(button as i32, lock_threshold) };
481 [delta.x, delta.y]
482 }
483
484 #[doc(alias = "ResetMouseDragDelta")]
486 pub fn reset_mouse_drag_delta(&self, button: MouseButton) {
487 unsafe { sys::igResetMouseDragDelta(button as i32) }
488 }
489}