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