Skip to main content

dear_imgui_rs/
input.rs

1//! Input types (mouse, keyboard, cursors)
2//!
3//! Strongly-typed identifiers for mouse buttons, mouse cursors and keyboard
4//! keys used by Dear ImGui. Backends typically translate platform events into
5//! these enums when feeding input into `Io`.
6//!
7//! See [`io`] for the per-frame input state and configuration.
8//!
9#![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/// Mouse button identifier
21#[repr(i32)]
22#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
23#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
24pub enum MouseButton {
25    /// Left mouse button
26    Left = sys::ImGuiMouseButton_Left as i32,
27    /// Right mouse button
28    Right = sys::ImGuiMouseButton_Right as i32,
29    /// Middle mouse button
30    Middle = sys::ImGuiMouseButton_Middle as i32,
31    /// Extra mouse button 1 (typically Back)
32    Extra1 = 3,
33    /// Extra mouse button 2 (typically Forward)
34    Extra2 = 4,
35}
36
37/// Mouse cursor types
38#[repr(i32)]
39#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
40#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
41pub enum MouseCursor {
42    /// No cursor
43    None = sys::ImGuiMouseCursor_None as i32,
44    /// Arrow cursor
45    Arrow = sys::ImGuiMouseCursor_Arrow as i32,
46    /// Text input I-beam cursor
47    TextInput = sys::ImGuiMouseCursor_TextInput as i32,
48    /// Resize all directions cursor
49    ResizeAll = sys::ImGuiMouseCursor_ResizeAll as i32,
50    /// Resize north-south cursor
51    ResizeNS = sys::ImGuiMouseCursor_ResizeNS as i32,
52    /// Resize east-west cursor
53    ResizeEW = sys::ImGuiMouseCursor_ResizeEW as i32,
54    /// Resize northeast-southwest cursor
55    ResizeNESW = sys::ImGuiMouseCursor_ResizeNESW as i32,
56    /// Resize northwest-southeast cursor
57    ResizeNWSE = sys::ImGuiMouseCursor_ResizeNWSE as i32,
58    /// Hand cursor
59    Hand = sys::ImGuiMouseCursor_Hand as i32,
60    /// Not allowed cursor
61    NotAllowed = sys::ImGuiMouseCursor_NotAllowed as i32,
62}
63
64/// Source of mouse-like input events.
65///
66/// Backends can use this to mark whether a mouse event originates from a
67/// physical mouse, a touch screen, or a pen/stylus so Dear ImGui can
68/// correctly handle multiple input sources.
69#[repr(i32)]
70#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
71#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
72pub enum MouseSource {
73    /// Events coming from a physical mouse
74    Mouse = sys::ImGuiMouseSource_Mouse as i32,
75    /// Events coming from a touch screen
76    TouchScreen = sys::ImGuiMouseSource_TouchScreen as i32,
77    /// Events coming from a pen or stylus
78    Pen = sys::ImGuiMouseSource_Pen as i32,
79}
80
81/// Key identifier for keyboard input
82#[repr(i32)]
83#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
84#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
85pub enum Key {
86    /// No key
87    None = sys::ImGuiKey_None as i32,
88    /// Tab key
89    Tab = sys::ImGuiKey_Tab as i32,
90    /// Left arrow key
91    LeftArrow = sys::ImGuiKey_LeftArrow as i32,
92    /// Right arrow key
93    RightArrow = sys::ImGuiKey_RightArrow as i32,
94    /// Up arrow key
95    UpArrow = sys::ImGuiKey_UpArrow as i32,
96    /// Down arrow key
97    DownArrow = sys::ImGuiKey_DownArrow as i32,
98    /// Page up key
99    PageUp = sys::ImGuiKey_PageUp as i32,
100    /// Page down key
101    PageDown = sys::ImGuiKey_PageDown as i32,
102    /// Home key
103    Home = sys::ImGuiKey_Home as i32,
104    /// End key
105    End = sys::ImGuiKey_End as i32,
106    /// Insert key
107    Insert = sys::ImGuiKey_Insert as i32,
108    /// Delete key
109    Delete = sys::ImGuiKey_Delete as i32,
110    /// Backspace key
111    Backspace = sys::ImGuiKey_Backspace as i32,
112    /// Space key
113    Space = sys::ImGuiKey_Space as i32,
114    /// Enter key
115    Enter = sys::ImGuiKey_Enter as i32,
116    /// Escape key
117    Escape = sys::ImGuiKey_Escape as i32,
118    /// Left Ctrl key
119    LeftCtrl = sys::ImGuiKey_LeftCtrl as i32,
120    /// Left Shift key
121    LeftShift = sys::ImGuiKey_LeftShift as i32,
122    /// Left Alt key
123    LeftAlt = sys::ImGuiKey_LeftAlt as i32,
124    /// Left Super key
125    LeftSuper = sys::ImGuiKey_LeftSuper as i32,
126    /// Right Ctrl key
127    RightCtrl = sys::ImGuiKey_RightCtrl as i32,
128    /// Right Shift key
129    RightShift = sys::ImGuiKey_RightShift as i32,
130    /// Right Alt key
131    RightAlt = sys::ImGuiKey_RightAlt as i32,
132    /// Right Super key
133    RightSuper = sys::ImGuiKey_RightSuper as i32,
134    /// Ctrl modifier (for `io.KeyMods` / `io.KeyCtrl`)
135    ModCtrl = sys::ImGuiMod_Ctrl as i32,
136    /// Shift modifier (for `io.KeyMods` / `io.KeyShift`)
137    ModShift = sys::ImGuiMod_Shift as i32,
138    /// Alt modifier (for `io.KeyMods` / `io.KeyAlt`)
139    ModAlt = sys::ImGuiMod_Alt as i32,
140    /// Super/Cmd modifier (for `io.KeyMods` / `io.KeySuper`)
141    ModSuper = sys::ImGuiMod_Super as i32,
142    /// Menu key
143    Menu = sys::ImGuiKey_Menu as i32,
144    /// 0 key
145    Key0 = sys::ImGuiKey_0 as i32,
146    /// 1 key
147    Key1 = sys::ImGuiKey_1 as i32,
148    /// 2 key
149    Key2 = sys::ImGuiKey_2 as i32,
150    /// 3 key
151    Key3 = sys::ImGuiKey_3 as i32,
152    /// 4 key
153    Key4 = sys::ImGuiKey_4 as i32,
154    /// 5 key
155    Key5 = sys::ImGuiKey_5 as i32,
156    /// 6 key
157    Key6 = sys::ImGuiKey_6 as i32,
158    /// 7 key
159    Key7 = sys::ImGuiKey_7 as i32,
160    /// 8 key
161    Key8 = sys::ImGuiKey_8 as i32,
162    /// 9 key
163    Key9 = sys::ImGuiKey_9 as i32,
164    /// A key
165    A = sys::ImGuiKey_A as i32,
166    /// B key
167    B = sys::ImGuiKey_B as i32,
168    /// C key
169    C = sys::ImGuiKey_C as i32,
170    /// D key
171    D = sys::ImGuiKey_D as i32,
172    /// E key
173    E = sys::ImGuiKey_E as i32,
174    /// F key
175    F = sys::ImGuiKey_F as i32,
176    /// G key
177    G = sys::ImGuiKey_G as i32,
178    /// H key
179    H = sys::ImGuiKey_H as i32,
180    /// I key
181    I = sys::ImGuiKey_I as i32,
182    /// J key
183    J = sys::ImGuiKey_J as i32,
184    /// K key
185    K = sys::ImGuiKey_K as i32,
186    /// L key
187    L = sys::ImGuiKey_L as i32,
188    /// M key
189    M = sys::ImGuiKey_M as i32,
190    /// N key
191    N = sys::ImGuiKey_N as i32,
192    /// O key
193    O = sys::ImGuiKey_O as i32,
194    /// P key
195    P = sys::ImGuiKey_P as i32,
196    /// Q key
197    Q = sys::ImGuiKey_Q as i32,
198    /// R key
199    R = sys::ImGuiKey_R as i32,
200    /// S key
201    S = sys::ImGuiKey_S as i32,
202    /// T key
203    T = sys::ImGuiKey_T as i32,
204    /// U key
205    U = sys::ImGuiKey_U as i32,
206    /// V key
207    V = sys::ImGuiKey_V as i32,
208    /// W key
209    W = sys::ImGuiKey_W as i32,
210    /// X key
211    X = sys::ImGuiKey_X as i32,
212    /// Y key
213    Y = sys::ImGuiKey_Y as i32,
214    /// Z key
215    Z = sys::ImGuiKey_Z as i32,
216    /// F1 key
217    F1 = sys::ImGuiKey_F1 as i32,
218    /// F2 key
219    F2 = sys::ImGuiKey_F2 as i32,
220    /// F3 key
221    F3 = sys::ImGuiKey_F3 as i32,
222    /// F4 key
223    F4 = sys::ImGuiKey_F4 as i32,
224    /// F5 key
225    F5 = sys::ImGuiKey_F5 as i32,
226    /// F6 key
227    F6 = sys::ImGuiKey_F6 as i32,
228    /// F7 key
229    F7 = sys::ImGuiKey_F7 as i32,
230    /// F8 key
231    F8 = sys::ImGuiKey_F8 as i32,
232    /// F9 key
233    F9 = sys::ImGuiKey_F9 as i32,
234    /// F10 key
235    F10 = sys::ImGuiKey_F10 as i32,
236    /// F11 key
237    F11 = sys::ImGuiKey_F11 as i32,
238    /// F12 key
239    F12 = sys::ImGuiKey_F12 as i32,
240
241    // --- Punctuation and extra named keys ---
242    /// Apostrophe (') key
243    Apostrophe = sys::ImGuiKey_Apostrophe as i32,
244    /// Comma (,) key
245    Comma = sys::ImGuiKey_Comma as i32,
246    /// Minus (-) key
247    Minus = sys::ImGuiKey_Minus as i32,
248    /// Period (.) key
249    Period = sys::ImGuiKey_Period as i32,
250    /// Slash (/) key
251    Slash = sys::ImGuiKey_Slash as i32,
252    /// Semicolon (;) key
253    Semicolon = sys::ImGuiKey_Semicolon as i32,
254    /// Equal (=) key
255    Equal = sys::ImGuiKey_Equal as i32,
256    /// Left bracket ([) key
257    LeftBracket = sys::ImGuiKey_LeftBracket as i32,
258    /// Backslash (\) key
259    Backslash = sys::ImGuiKey_Backslash as i32,
260    /// Right bracket (]) key
261    RightBracket = sys::ImGuiKey_RightBracket as i32,
262    /// Grave accent (`) key
263    GraveAccent = sys::ImGuiKey_GraveAccent as i32,
264    /// CapsLock key
265    CapsLock = sys::ImGuiKey_CapsLock as i32,
266    /// ScrollLock key
267    ScrollLock = sys::ImGuiKey_ScrollLock as i32,
268    /// NumLock key
269    NumLock = sys::ImGuiKey_NumLock as i32,
270    /// PrintScreen key
271    PrintScreen = sys::ImGuiKey_PrintScreen as i32,
272    /// Pause key
273    Pause = sys::ImGuiKey_Pause as i32,
274
275    // --- Keypad ---
276    /// Numpad 0
277    Keypad0 = sys::ImGuiKey_Keypad0 as i32,
278    /// Numpad 1
279    Keypad1 = sys::ImGuiKey_Keypad1 as i32,
280    /// Numpad 2
281    Keypad2 = sys::ImGuiKey_Keypad2 as i32,
282    /// Numpad 3
283    Keypad3 = sys::ImGuiKey_Keypad3 as i32,
284    /// Numpad 4
285    Keypad4 = sys::ImGuiKey_Keypad4 as i32,
286    /// Numpad 5
287    Keypad5 = sys::ImGuiKey_Keypad5 as i32,
288    /// Numpad 6
289    Keypad6 = sys::ImGuiKey_Keypad6 as i32,
290    /// Numpad 7
291    Keypad7 = sys::ImGuiKey_Keypad7 as i32,
292    /// Numpad 8
293    Keypad8 = sys::ImGuiKey_Keypad8 as i32,
294    /// Numpad 9
295    Keypad9 = sys::ImGuiKey_Keypad9 as i32,
296    /// Numpad decimal
297    KeypadDecimal = sys::ImGuiKey_KeypadDecimal as i32,
298    /// Numpad divide
299    KeypadDivide = sys::ImGuiKey_KeypadDivide as i32,
300    /// Numpad multiply
301    KeypadMultiply = sys::ImGuiKey_KeypadMultiply as i32,
302    /// Numpad subtract
303    KeypadSubtract = sys::ImGuiKey_KeypadSubtract as i32,
304    /// Numpad add
305    KeypadAdd = sys::ImGuiKey_KeypadAdd as i32,
306    /// Numpad enter
307    KeypadEnter = sys::ImGuiKey_KeypadEnter as i32,
308    /// Numpad equal
309    KeypadEqual = sys::ImGuiKey_KeypadEqual as i32,
310
311    /// OEM 102 key (ISO < > |)
312    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
336// Key modifier flags are available via io.KeyCtrl/KeyShift/KeyAlt/KeySuper.
337// Backends should submit modifier state via `Key::ModCtrl`/`ModShift`/`ModAlt`/`ModSuper` using `Io::add_key_event`.
338
339bitflags! {
340    /// Modifier flags for building an ImGui key chord.
341    #[repr(transparent)]
342    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
343    pub struct KeyMods: i32 {
344        /// Ctrl modifier
345        const CTRL = sys::ImGuiMod_Ctrl as i32;
346        /// Shift modifier
347        const SHIFT = sys::ImGuiMod_Shift as i32;
348        /// Alt modifier
349        const ALT = sys::ImGuiMod_Alt as i32;
350        /// Super/Cmd modifier
351        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/// A key chord (key + optional modifier flags), used by ImGui shortcut routing APIs.
369///
370/// This is a thin wrapper over `sys::ImGuiKeyChord` (an `int`).
371#[repr(transparent)]
372#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
373pub struct KeyChord(sys::ImGuiKeyChord);
374
375impl KeyChord {
376    /// Create a chord from a key (no modifiers).
377    pub fn new(key: Key) -> Self {
378        Self(key as sys::ImGuiKeyChord)
379    }
380
381    /// Add modifier flags to the chord.
382    pub fn with_mods(self, mods: KeyMods) -> Self {
383        Self(self.0 | mods.raw())
384    }
385
386    /// Returns the raw `ImGuiKeyChord` value.
387    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    /// Input flags for shortcut routing APIs.
400    ///
401    /// This corresponds to public `ImGuiInputFlags_*` values (not the private/internal ones).
402    #[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    /// Input text flags for text input widgets
437    #[repr(transparent)]
438    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
439    pub struct InputTextFlags: i32 {
440        /// No flags
441        const NONE = sys::ImGuiInputTextFlags_None as i32;
442        /// Allow 0123456789.+-*/
443        const CHARS_DECIMAL = sys::ImGuiInputTextFlags_CharsDecimal as i32;
444        /// Allow 0123456789ABCDEFabcdef
445        const CHARS_HEXADECIMAL = sys::ImGuiInputTextFlags_CharsHexadecimal as i32;
446        /// Turn a..z into A..Z
447        const CHARS_UPPERCASE = sys::ImGuiInputTextFlags_CharsUppercase as i32;
448        /// Filter out spaces, tabs
449        const CHARS_NO_BLANK = sys::ImGuiInputTextFlags_CharsNoBlank as i32;
450        /// Select entire text when first taking mouse focus
451        const AUTO_SELECT_ALL = sys::ImGuiInputTextFlags_AutoSelectAll as i32;
452        /// Return 'true' when Enter is pressed (as opposed to every time the value was modified)
453        const ENTER_RETURNS_TRUE = sys::ImGuiInputTextFlags_EnterReturnsTrue as i32;
454        /// Callback on pressing TAB (for completion handling)
455        const CALLBACK_COMPLETION = sys::ImGuiInputTextFlags_CallbackCompletion as i32;
456        /// Callback on pressing Up/Down arrows (for history handling)
457        const CALLBACK_HISTORY = sys::ImGuiInputTextFlags_CallbackHistory as i32;
458        /// Callback on each iteration (user can query cursor and modify text)
459        const CALLBACK_ALWAYS = sys::ImGuiInputTextFlags_CallbackAlways as i32;
460        /// Callback on character inputs to replace or discard them
461        const CALLBACK_CHAR_FILTER = sys::ImGuiInputTextFlags_CallbackCharFilter as i32;
462        /// Pressing TAB input a '\t' character into the text field
463        const ALLOW_TAB_INPUT = sys::ImGuiInputTextFlags_AllowTabInput as i32;
464        /// In multi-line mode, unfocus with Enter, add new line with Ctrl+Enter
465        const CTRL_ENTER_FOR_NEW_LINE = sys::ImGuiInputTextFlags_CtrlEnterForNewLine as i32;
466        /// Disable following the cursor horizontally
467        const NO_HORIZONTAL_SCROLL = sys::ImGuiInputTextFlags_NoHorizontalScroll as i32;
468        /// Overwrite mode
469        const ALWAYS_OVERWRITE = sys::ImGuiInputTextFlags_AlwaysOverwrite as i32;
470        /// Read-only mode
471        const READ_ONLY = sys::ImGuiInputTextFlags_ReadOnly as i32;
472        /// Password mode, display all characters as '*'
473        const PASSWORD = sys::ImGuiInputTextFlags_Password as i32;
474        /// Disable undo/redo
475        const NO_UNDO_REDO = sys::ImGuiInputTextFlags_NoUndoRedo as i32;
476        /// Allow 0123456789.+-*/eE (Scientific notation input)
477        const CHARS_SCIENTIFIC = sys::ImGuiInputTextFlags_CharsScientific as i32;
478        /// Callback on buffer capacity changes request
479        const CALLBACK_RESIZE = sys::ImGuiInputTextFlags_CallbackResize as i32;
480        /// Callback on any edit (note that InputText() already returns true on edit)
481        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
513// TODO: Add NavInput enum once we have proper constants in sys crate
514
515impl crate::Ui {
516    /// Check if a key is being held down
517    #[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    /// Check if a key was pressed (went from !Down to Down)
523    #[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    /// Check if a key was pressed (went from !Down to Down), with repeat
529    #[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    /// Check if a key was released (went from Down to !Down)
535    #[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    /// Check if a key chord was pressed (e.g. `Ctrl+S`).
541    #[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    /// Call ImGui shortcut routing with default flags.
547    #[doc(alias = "Shortcut")]
548    pub fn shortcut(&self, key_chord: KeyChord) -> bool {
549        self.shortcut_with_flags(key_chord, InputFlags::NONE)
550    }
551
552    /// Call ImGui shortcut routing with explicit input flags.
553    #[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    /// Set the next item's shortcut with default flags.
559    #[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    /// Set the next item's shortcut with explicit input flags.
565    #[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    /// Overrides `io.WantCaptureKeyboard` for the next frame.
571    #[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    /// Overrides `io.WantCaptureMouse` for the next frame.
577    #[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    /// Check if a mouse button is being held down
583    #[doc(alias = "IsMouseDown")]
584    pub fn is_mouse_down(&self, button: MouseButton) -> bool {
585        unsafe { sys::igIsMouseDown_Nil(button.into()) }
586    }
587
588    /// Check if a mouse button was clicked (went from !Down to Down)
589    #[doc(alias = "IsMouseClicked")]
590    pub fn is_mouse_clicked(&self, button: MouseButton) -> bool {
591        unsafe { sys::igIsMouseClicked_Bool(button.into(), false) }
592    }
593
594    /// Check if a mouse button was clicked, with repeat
595    #[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    /// Check if a mouse button was released (went from Down to !Down)
601    #[doc(alias = "IsMouseReleased")]
602    pub fn is_mouse_released(&self, button: MouseButton) -> bool {
603        unsafe { sys::igIsMouseReleased_Nil(button.into()) }
604    }
605
606    /// Check if a mouse button was double-clicked
607    #[doc(alias = "IsMouseDoubleClicked")]
608    pub fn is_mouse_double_clicked(&self, button: MouseButton) -> bool {
609        unsafe { sys::igIsMouseDoubleClicked_Nil(button.into()) }
610    }
611
612    /// Returns `true` if the mouse position is valid (not NaN).
613    ///
614    /// This checks the current mouse position as known by Dear ImGui.
615    #[doc(alias = "IsMousePosValid")]
616    pub fn is_mouse_pos_valid(&self) -> bool {
617        unsafe { sys::igIsMousePosValid(std::ptr::null()) }
618    }
619
620    /// Returns `true` if the provided mouse position is valid (not NaN).
621    #[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    /// Returns `true` if the mouse button was released and the given delay has passed.
631    #[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    /// Get mouse position in screen coordinates
637    #[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    /// Get mouse position when a specific button was clicked
644    #[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    /// Check if mouse is hovering given rectangle
651    #[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    /// Check if mouse is hovering given rectangle (with clipping test)
663    #[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    /// Check if mouse is dragging
680    #[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    /// Check if mouse is dragging with threshold
686    #[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    /// Get mouse drag delta
696    #[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    /// Get mouse drag delta with threshold
703    #[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    /// Reset mouse drag delta for a specific button
714    #[doc(alias = "ResetMouseDragDelta")]
715    pub fn reset_mouse_drag_delta(&self, button: MouseButton) {
716        unsafe { sys::igResetMouseDragDelta(button as i32) }
717    }
718
719    /// Returns true if the last item toggled its selection state in a multi-select scope.
720    ///
721    /// This only makes sense when used between `BeginMultiSelect()` /
722    /// `EndMultiSelect()` (or helpers built on top of them).
723    #[doc(alias = "IsItemToggledSelection")]
724    pub fn is_item_toggled_selection(&self) -> bool {
725        unsafe { sys::igIsItemToggledSelection() }
726    }
727}