1#![allow(
10 clippy::cast_possible_truncation,
11 clippy::cast_sign_loss,
12 clippy::as_conversions,
13 clippy::unnecessary_cast
14)]
15use crate::sys;
16use bitflags::bitflags;
17#[cfg(feature = "serde")]
18use serde::{Deserialize, Serialize};
19
20#[repr(i32)]
22#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
23#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
24pub enum MouseButton {
25 Left = sys::ImGuiMouseButton_Left as i32,
27 Right = sys::ImGuiMouseButton_Right as i32,
29 Middle = sys::ImGuiMouseButton_Middle as i32,
31 Extra1 = 3,
33 Extra2 = 4,
35}
36
37#[repr(i32)]
39#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
40#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
41pub enum MouseCursor {
42 None = sys::ImGuiMouseCursor_None as i32,
44 Arrow = sys::ImGuiMouseCursor_Arrow as i32,
46 TextInput = sys::ImGuiMouseCursor_TextInput as i32,
48 ResizeAll = sys::ImGuiMouseCursor_ResizeAll as i32,
50 ResizeNS = sys::ImGuiMouseCursor_ResizeNS as i32,
52 ResizeEW = sys::ImGuiMouseCursor_ResizeEW as i32,
54 ResizeNESW = sys::ImGuiMouseCursor_ResizeNESW as i32,
56 ResizeNWSE = sys::ImGuiMouseCursor_ResizeNWSE as i32,
58 Hand = sys::ImGuiMouseCursor_Hand as i32,
60 NotAllowed = sys::ImGuiMouseCursor_NotAllowed as i32,
62}
63
64#[repr(i32)]
70#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
71#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
72pub enum MouseSource {
73 Mouse = sys::ImGuiMouseSource_Mouse as i32,
75 TouchScreen = sys::ImGuiMouseSource_TouchScreen as i32,
77 Pen = sys::ImGuiMouseSource_Pen as i32,
79}
80
81#[repr(i32)]
83#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
84#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
85pub enum Key {
86 None = sys::ImGuiKey_None as i32,
88 Tab = sys::ImGuiKey_Tab as i32,
90 LeftArrow = sys::ImGuiKey_LeftArrow as i32,
92 RightArrow = sys::ImGuiKey_RightArrow as i32,
94 UpArrow = sys::ImGuiKey_UpArrow as i32,
96 DownArrow = sys::ImGuiKey_DownArrow as i32,
98 PageUp = sys::ImGuiKey_PageUp as i32,
100 PageDown = sys::ImGuiKey_PageDown as i32,
102 Home = sys::ImGuiKey_Home as i32,
104 End = sys::ImGuiKey_End as i32,
106 Insert = sys::ImGuiKey_Insert as i32,
108 Delete = sys::ImGuiKey_Delete as i32,
110 Backspace = sys::ImGuiKey_Backspace as i32,
112 Space = sys::ImGuiKey_Space as i32,
114 Enter = sys::ImGuiKey_Enter as i32,
116 Escape = sys::ImGuiKey_Escape as i32,
118 LeftCtrl = sys::ImGuiKey_LeftCtrl as i32,
120 LeftShift = sys::ImGuiKey_LeftShift as i32,
122 LeftAlt = sys::ImGuiKey_LeftAlt as i32,
124 LeftSuper = sys::ImGuiKey_LeftSuper as i32,
126 RightCtrl = sys::ImGuiKey_RightCtrl as i32,
128 RightShift = sys::ImGuiKey_RightShift as i32,
130 RightAlt = sys::ImGuiKey_RightAlt as i32,
132 RightSuper = sys::ImGuiKey_RightSuper as i32,
134 ModCtrl = sys::ImGuiMod_Ctrl as i32,
136 ModShift = sys::ImGuiMod_Shift as i32,
138 ModAlt = sys::ImGuiMod_Alt as i32,
140 ModSuper = sys::ImGuiMod_Super as i32,
142 Menu = sys::ImGuiKey_Menu as i32,
144 Key0 = sys::ImGuiKey_0 as i32,
146 Key1 = sys::ImGuiKey_1 as i32,
148 Key2 = sys::ImGuiKey_2 as i32,
150 Key3 = sys::ImGuiKey_3 as i32,
152 Key4 = sys::ImGuiKey_4 as i32,
154 Key5 = sys::ImGuiKey_5 as i32,
156 Key6 = sys::ImGuiKey_6 as i32,
158 Key7 = sys::ImGuiKey_7 as i32,
160 Key8 = sys::ImGuiKey_8 as i32,
162 Key9 = sys::ImGuiKey_9 as i32,
164 A = sys::ImGuiKey_A as i32,
166 B = sys::ImGuiKey_B as i32,
168 C = sys::ImGuiKey_C as i32,
170 D = sys::ImGuiKey_D as i32,
172 E = sys::ImGuiKey_E as i32,
174 F = sys::ImGuiKey_F as i32,
176 G = sys::ImGuiKey_G as i32,
178 H = sys::ImGuiKey_H as i32,
180 I = sys::ImGuiKey_I as i32,
182 J = sys::ImGuiKey_J as i32,
184 K = sys::ImGuiKey_K as i32,
186 L = sys::ImGuiKey_L as i32,
188 M = sys::ImGuiKey_M as i32,
190 N = sys::ImGuiKey_N as i32,
192 O = sys::ImGuiKey_O as i32,
194 P = sys::ImGuiKey_P as i32,
196 Q = sys::ImGuiKey_Q as i32,
198 R = sys::ImGuiKey_R as i32,
200 S = sys::ImGuiKey_S as i32,
202 T = sys::ImGuiKey_T as i32,
204 U = sys::ImGuiKey_U as i32,
206 V = sys::ImGuiKey_V as i32,
208 W = sys::ImGuiKey_W as i32,
210 X = sys::ImGuiKey_X as i32,
212 Y = sys::ImGuiKey_Y as i32,
214 Z = sys::ImGuiKey_Z as i32,
216 F1 = sys::ImGuiKey_F1 as i32,
218 F2 = sys::ImGuiKey_F2 as i32,
220 F3 = sys::ImGuiKey_F3 as i32,
222 F4 = sys::ImGuiKey_F4 as i32,
224 F5 = sys::ImGuiKey_F5 as i32,
226 F6 = sys::ImGuiKey_F6 as i32,
228 F7 = sys::ImGuiKey_F7 as i32,
230 F8 = sys::ImGuiKey_F8 as i32,
232 F9 = sys::ImGuiKey_F9 as i32,
234 F10 = sys::ImGuiKey_F10 as i32,
236 F11 = sys::ImGuiKey_F11 as i32,
238 F12 = sys::ImGuiKey_F12 as i32,
240
241 Apostrophe = sys::ImGuiKey_Apostrophe as i32,
244 Comma = sys::ImGuiKey_Comma as i32,
246 Minus = sys::ImGuiKey_Minus as i32,
248 Period = sys::ImGuiKey_Period as i32,
250 Slash = sys::ImGuiKey_Slash as i32,
252 Semicolon = sys::ImGuiKey_Semicolon as i32,
254 Equal = sys::ImGuiKey_Equal as i32,
256 LeftBracket = sys::ImGuiKey_LeftBracket as i32,
258 Backslash = sys::ImGuiKey_Backslash as i32,
260 RightBracket = sys::ImGuiKey_RightBracket as i32,
262 GraveAccent = sys::ImGuiKey_GraveAccent as i32,
264 CapsLock = sys::ImGuiKey_CapsLock as i32,
266 ScrollLock = sys::ImGuiKey_ScrollLock as i32,
268 NumLock = sys::ImGuiKey_NumLock as i32,
270 PrintScreen = sys::ImGuiKey_PrintScreen as i32,
272 Pause = sys::ImGuiKey_Pause as i32,
274
275 Keypad0 = sys::ImGuiKey_Keypad0 as i32,
278 Keypad1 = sys::ImGuiKey_Keypad1 as i32,
280 Keypad2 = sys::ImGuiKey_Keypad2 as i32,
282 Keypad3 = sys::ImGuiKey_Keypad3 as i32,
284 Keypad4 = sys::ImGuiKey_Keypad4 as i32,
286 Keypad5 = sys::ImGuiKey_Keypad5 as i32,
288 Keypad6 = sys::ImGuiKey_Keypad6 as i32,
290 Keypad7 = sys::ImGuiKey_Keypad7 as i32,
292 Keypad8 = sys::ImGuiKey_Keypad8 as i32,
294 Keypad9 = sys::ImGuiKey_Keypad9 as i32,
296 KeypadDecimal = sys::ImGuiKey_KeypadDecimal as i32,
298 KeypadDivide = sys::ImGuiKey_KeypadDivide as i32,
300 KeypadMultiply = sys::ImGuiKey_KeypadMultiply as i32,
302 KeypadSubtract = sys::ImGuiKey_KeypadSubtract as i32,
304 KeypadAdd = sys::ImGuiKey_KeypadAdd as i32,
306 KeypadEnter = sys::ImGuiKey_KeypadEnter as i32,
308 KeypadEqual = sys::ImGuiKey_KeypadEqual as i32,
310
311 Oem102 = sys::ImGuiKey_Oem102 as i32,
313}
314
315impl From<MouseButton> for sys::ImGuiMouseButton {
316 #[inline]
317 fn from(value: MouseButton) -> sys::ImGuiMouseButton {
318 value as sys::ImGuiMouseButton
319 }
320}
321
322impl From<MouseSource> for sys::ImGuiMouseSource {
323 #[inline]
324 fn from(value: MouseSource) -> sys::ImGuiMouseSource {
325 value as sys::ImGuiMouseSource
326 }
327}
328
329impl From<Key> for sys::ImGuiKey {
330 #[inline]
331 fn from(value: Key) -> sys::ImGuiKey {
332 value as sys::ImGuiKey
333 }
334}
335
336bitflags! {
340 #[repr(transparent)]
342 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
343 pub struct KeyMods: i32 {
344 const CTRL = sys::ImGuiMod_Ctrl as i32;
346 const SHIFT = sys::ImGuiMod_Shift as i32;
348 const ALT = sys::ImGuiMod_Alt as i32;
350 const SUPER = sys::ImGuiMod_Super as i32;
352 }
353}
354
355impl Default for KeyMods {
356 fn default() -> Self {
357 KeyMods::empty()
358 }
359}
360
361impl KeyMods {
362 #[inline]
363 pub(crate) fn raw(self) -> sys::ImGuiKeyChord {
364 self.bits() as sys::ImGuiKeyChord
365 }
366}
367
368#[repr(transparent)]
372#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
373pub struct KeyChord(sys::ImGuiKeyChord);
374
375impl KeyChord {
376 pub fn new(key: Key) -> Self {
378 Self(key as sys::ImGuiKeyChord)
379 }
380
381 pub fn with_mods(self, mods: KeyMods) -> Self {
383 Self(self.0 | mods.raw())
384 }
385
386 pub fn raw(self) -> sys::ImGuiKeyChord {
388 self.0
389 }
390}
391
392impl From<Key> for KeyChord {
393 fn from(value: Key) -> Self {
394 Self::new(value)
395 }
396}
397
398bitflags! {
399 #[repr(transparent)]
403 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
404 pub struct InputFlags: i32 {
405 const NONE = sys::ImGuiInputFlags_None as i32;
406 const REPEAT = sys::ImGuiInputFlags_Repeat as i32;
407
408 const ROUTE_ACTIVE = sys::ImGuiInputFlags_RouteActive as i32;
409 const ROUTE_FOCUSED = sys::ImGuiInputFlags_RouteFocused as i32;
410 const ROUTE_GLOBAL = sys::ImGuiInputFlags_RouteGlobal as i32;
411 const ROUTE_ALWAYS = sys::ImGuiInputFlags_RouteAlways as i32;
412
413 const ROUTE_OVER_FOCUSED = sys::ImGuiInputFlags_RouteOverFocused as i32;
414 const ROUTE_OVER_ACTIVE = sys::ImGuiInputFlags_RouteOverActive as i32;
415 const ROUTE_UNLESS_BG_FOCUSED = sys::ImGuiInputFlags_RouteUnlessBgFocused as i32;
416 const ROUTE_FROM_ROOT_WINDOW = sys::ImGuiInputFlags_RouteFromRootWindow as i32;
417
418 const TOOLTIP = sys::ImGuiInputFlags_Tooltip as i32;
419 }
420}
421
422impl Default for InputFlags {
423 fn default() -> Self {
424 InputFlags::NONE
425 }
426}
427
428impl InputFlags {
429 #[inline]
430 pub(crate) fn raw(self) -> sys::ImGuiInputFlags {
431 self.bits() as sys::ImGuiInputFlags
432 }
433}
434
435bitflags! {
436 #[repr(transparent)]
438 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
439 pub struct InputTextFlags: i32 {
440 const NONE = sys::ImGuiInputTextFlags_None as i32;
442 const CHARS_DECIMAL = sys::ImGuiInputTextFlags_CharsDecimal as i32;
444 const CHARS_HEXADECIMAL = sys::ImGuiInputTextFlags_CharsHexadecimal as i32;
446 const CHARS_UPPERCASE = sys::ImGuiInputTextFlags_CharsUppercase as i32;
448 const CHARS_NO_BLANK = sys::ImGuiInputTextFlags_CharsNoBlank as i32;
450 const AUTO_SELECT_ALL = sys::ImGuiInputTextFlags_AutoSelectAll as i32;
452 const ENTER_RETURNS_TRUE = sys::ImGuiInputTextFlags_EnterReturnsTrue as i32;
454 const CALLBACK_COMPLETION = sys::ImGuiInputTextFlags_CallbackCompletion as i32;
456 const CALLBACK_HISTORY = sys::ImGuiInputTextFlags_CallbackHistory as i32;
458 const CALLBACK_ALWAYS = sys::ImGuiInputTextFlags_CallbackAlways as i32;
460 const CALLBACK_CHAR_FILTER = sys::ImGuiInputTextFlags_CallbackCharFilter as i32;
462 const ALLOW_TAB_INPUT = sys::ImGuiInputTextFlags_AllowTabInput as i32;
464 const CTRL_ENTER_FOR_NEW_LINE = sys::ImGuiInputTextFlags_CtrlEnterForNewLine as i32;
466 const NO_HORIZONTAL_SCROLL = sys::ImGuiInputTextFlags_NoHorizontalScroll as i32;
468 const ALWAYS_OVERWRITE = sys::ImGuiInputTextFlags_AlwaysOverwrite as i32;
470 const READ_ONLY = sys::ImGuiInputTextFlags_ReadOnly as i32;
472 const PASSWORD = sys::ImGuiInputTextFlags_Password as i32;
474 const NO_UNDO_REDO = sys::ImGuiInputTextFlags_NoUndoRedo as i32;
476 const CHARS_SCIENTIFIC = sys::ImGuiInputTextFlags_CharsScientific as i32;
478 const CALLBACK_RESIZE = sys::ImGuiInputTextFlags_CallbackResize as i32;
480 const CALLBACK_EDIT = sys::ImGuiInputTextFlags_CallbackEdit as i32;
482 }
483}
484
485impl InputTextFlags {
486 #[inline]
487 pub(crate) fn raw(self) -> sys::ImGuiInputTextFlags {
488 self.bits() as sys::ImGuiInputTextFlags
489 }
490}
491
492#[cfg(feature = "serde")]
493impl Serialize for InputTextFlags {
494 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
495 where
496 S: serde::Serializer,
497 {
498 serializer.serialize_i32(self.bits())
499 }
500}
501
502#[cfg(feature = "serde")]
503impl<'de> Deserialize<'de> for InputTextFlags {
504 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
505 where
506 D: serde::Deserializer<'de>,
507 {
508 let bits = i32::deserialize(deserializer)?;
509 Ok(InputTextFlags::from_bits_truncate(bits))
510 }
511}
512
513impl crate::Ui {
516 #[doc(alias = "IsKeyDown")]
518 pub fn is_key_down(&self, key: Key) -> bool {
519 unsafe { sys::igIsKeyDown_Nil(key as sys::ImGuiKey) }
520 }
521
522 #[doc(alias = "IsKeyPressed")]
524 pub fn is_key_pressed(&self, key: Key) -> bool {
525 unsafe { sys::igIsKeyPressed_Bool(key as sys::ImGuiKey, true) }
526 }
527
528 #[doc(alias = "IsKeyPressed")]
530 pub fn is_key_pressed_with_repeat(&self, key: Key, repeat: bool) -> bool {
531 unsafe { sys::igIsKeyPressed_Bool(key as sys::ImGuiKey, repeat) }
532 }
533
534 #[doc(alias = "IsKeyReleased")]
536 pub fn is_key_released(&self, key: Key) -> bool {
537 unsafe { sys::igIsKeyReleased_Nil(key as sys::ImGuiKey) }
538 }
539
540 #[doc(alias = "IsKeyChordPressed")]
542 pub fn is_key_chord_pressed(&self, key_chord: KeyChord) -> bool {
543 unsafe { sys::igIsKeyChordPressed_Nil(key_chord.raw()) }
544 }
545
546 #[doc(alias = "Shortcut")]
548 pub fn shortcut(&self, key_chord: KeyChord) -> bool {
549 self.shortcut_with_flags(key_chord, InputFlags::NONE)
550 }
551
552 #[doc(alias = "Shortcut")]
554 pub fn shortcut_with_flags(&self, key_chord: KeyChord, flags: InputFlags) -> bool {
555 unsafe { sys::igShortcut_Nil(key_chord.raw(), flags.raw()) }
556 }
557
558 #[doc(alias = "SetNextItemShortcut")]
560 pub fn set_next_item_shortcut(&self, key_chord: KeyChord) {
561 self.set_next_item_shortcut_with_flags(key_chord, InputFlags::NONE);
562 }
563
564 #[doc(alias = "SetNextItemShortcut")]
566 pub fn set_next_item_shortcut_with_flags(&self, key_chord: KeyChord, flags: InputFlags) {
567 unsafe { sys::igSetNextItemShortcut(key_chord.raw(), flags.raw()) }
568 }
569
570 #[doc(alias = "SetNextFrameWantCaptureKeyboard")]
572 pub fn set_next_frame_want_capture_keyboard(&self, want_capture_keyboard: bool) {
573 unsafe { sys::igSetNextFrameWantCaptureKeyboard(want_capture_keyboard) }
574 }
575
576 #[doc(alias = "SetNextFrameWantCaptureMouse")]
578 pub fn set_next_frame_want_capture_mouse(&self, want_capture_mouse: bool) {
579 unsafe { sys::igSetNextFrameWantCaptureMouse(want_capture_mouse) }
580 }
581
582 #[doc(alias = "IsMouseDown")]
584 pub fn is_mouse_down(&self, button: MouseButton) -> bool {
585 unsafe { sys::igIsMouseDown_Nil(button.into()) }
586 }
587
588 #[doc(alias = "IsMouseClicked")]
590 pub fn is_mouse_clicked(&self, button: MouseButton) -> bool {
591 unsafe { sys::igIsMouseClicked_Bool(button.into(), false) }
592 }
593
594 #[doc(alias = "IsMouseClicked")]
596 pub fn is_mouse_clicked_with_repeat(&self, button: MouseButton, repeat: bool) -> bool {
597 unsafe { sys::igIsMouseClicked_Bool(button.into(), repeat) }
598 }
599
600 #[doc(alias = "IsMouseReleased")]
602 pub fn is_mouse_released(&self, button: MouseButton) -> bool {
603 unsafe { sys::igIsMouseReleased_Nil(button.into()) }
604 }
605
606 #[doc(alias = "IsMouseDoubleClicked")]
608 pub fn is_mouse_double_clicked(&self, button: MouseButton) -> bool {
609 unsafe { sys::igIsMouseDoubleClicked_Nil(button.into()) }
610 }
611
612 #[doc(alias = "IsMousePosValid")]
616 pub fn is_mouse_pos_valid(&self) -> bool {
617 unsafe { sys::igIsMousePosValid(std::ptr::null()) }
618 }
619
620 #[doc(alias = "IsMousePosValid")]
622 pub fn is_mouse_pos_valid_at(&self, pos: [f32; 2]) -> bool {
623 let v = sys::ImVec2_c {
624 x: pos[0],
625 y: pos[1],
626 };
627 unsafe { sys::igIsMousePosValid(&v as *const sys::ImVec2_c) }
628 }
629
630 #[doc(alias = "IsMouseReleasedWithDelay")]
632 pub fn is_mouse_released_with_delay(&self, button: MouseButton, delay: f32) -> bool {
633 unsafe { sys::igIsMouseReleasedWithDelay(button.into(), delay) }
634 }
635
636 #[doc(alias = "GetMousePos")]
638 pub fn mouse_pos(&self) -> [f32; 2] {
639 let pos = unsafe { sys::igGetMousePos() };
640 [pos.x, pos.y]
641 }
642
643 #[doc(alias = "GetMousePosOnOpeningCurrentPopup")]
645 pub fn mouse_pos_on_opening_current_popup(&self) -> [f32; 2] {
646 let pos = unsafe { sys::igGetMousePosOnOpeningCurrentPopup() };
647 [pos.x, pos.y]
648 }
649
650 #[doc(alias = "IsMouseHoveringRect")]
652 pub fn is_mouse_hovering_rect(&self, r_min: [f32; 2], r_max: [f32; 2]) -> bool {
653 unsafe {
654 sys::igIsMouseHoveringRect(
655 sys::ImVec2::new(r_min[0], r_min[1]),
656 sys::ImVec2::new(r_max[0], r_max[1]),
657 true,
658 )
659 }
660 }
661
662 #[doc(alias = "IsMouseHoveringRect")]
664 pub fn is_mouse_hovering_rect_with_clip(
665 &self,
666 r_min: [f32; 2],
667 r_max: [f32; 2],
668 clip: bool,
669 ) -> bool {
670 unsafe {
671 sys::igIsMouseHoveringRect(
672 sys::ImVec2::new(r_min[0], r_min[1]),
673 sys::ImVec2::new(r_max[0], r_max[1]),
674 clip,
675 )
676 }
677 }
678
679 #[doc(alias = "IsMouseDragging")]
681 pub fn is_mouse_dragging(&self, button: MouseButton) -> bool {
682 unsafe { sys::igIsMouseDragging(button as i32, -1.0) }
683 }
684
685 #[doc(alias = "IsMouseDragging")]
687 pub fn is_mouse_dragging_with_threshold(
688 &self,
689 button: MouseButton,
690 lock_threshold: f32,
691 ) -> bool {
692 unsafe { sys::igIsMouseDragging(button as i32, lock_threshold) }
693 }
694
695 #[doc(alias = "GetMouseDragDelta")]
697 pub fn mouse_drag_delta(&self, button: MouseButton) -> [f32; 2] {
698 let delta = unsafe { sys::igGetMouseDragDelta(button as i32, -1.0) };
699 [delta.x, delta.y]
700 }
701
702 #[doc(alias = "GetMouseDragDelta")]
704 pub fn mouse_drag_delta_with_threshold(
705 &self,
706 button: MouseButton,
707 lock_threshold: f32,
708 ) -> [f32; 2] {
709 let delta = unsafe { sys::igGetMouseDragDelta(button as i32, lock_threshold) };
710 [delta.x, delta.y]
711 }
712
713 #[doc(alias = "ResetMouseDragDelta")]
715 pub fn reset_mouse_drag_delta(&self, button: MouseButton) {
716 unsafe { sys::igResetMouseDragDelta(button as i32) }
717 }
718
719 #[doc(alias = "IsItemToggledSelection")]
724 pub fn is_item_toggled_selection(&self) -> bool {
725 unsafe { sys::igIsItemToggledSelection() }
726 }
727}