1#![allow(
10 clippy::cast_possible_truncation,
11 clippy::cast_sign_loss,
12 clippy::as_conversions
13)]
14use crate::sys;
15use bitflags::bitflags;
16#[cfg(feature = "serde")]
17use serde::{Deserialize, Serialize};
18
19#[repr(i32)]
21#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
22#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
23pub enum MouseButton {
24 Left = sys::ImGuiMouseButton_Left as i32,
26 Right = sys::ImGuiMouseButton_Right as i32,
28 Middle = sys::ImGuiMouseButton_Middle as i32,
30 Extra1 = 3,
32 Extra2 = 4,
34}
35
36#[repr(i32)]
38#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
39#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
40pub enum MouseCursor {
41 None = sys::ImGuiMouseCursor_None,
43 Arrow = sys::ImGuiMouseCursor_Arrow,
45 TextInput = sys::ImGuiMouseCursor_TextInput,
47 ResizeAll = sys::ImGuiMouseCursor_ResizeAll,
49 ResizeNS = sys::ImGuiMouseCursor_ResizeNS,
51 ResizeEW = sys::ImGuiMouseCursor_ResizeEW,
53 ResizeNESW = sys::ImGuiMouseCursor_ResizeNESW,
55 ResizeNWSE = sys::ImGuiMouseCursor_ResizeNWSE,
57 Hand = sys::ImGuiMouseCursor_Hand,
59 NotAllowed = sys::ImGuiMouseCursor_NotAllowed,
61}
62
63#[repr(i32)]
69#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
70#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
71pub enum MouseSource {
72 Mouse = sys::ImGuiMouseSource_Mouse as i32,
74 TouchScreen = sys::ImGuiMouseSource_TouchScreen as i32,
76 Pen = sys::ImGuiMouseSource_Pen as i32,
78}
79
80#[repr(i32)]
82#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
83#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
84pub enum Key {
85 None = sys::ImGuiKey_None as i32,
87 Tab = sys::ImGuiKey_Tab as i32,
89 LeftArrow = sys::ImGuiKey_LeftArrow as i32,
91 RightArrow = sys::ImGuiKey_RightArrow as i32,
93 UpArrow = sys::ImGuiKey_UpArrow as i32,
95 DownArrow = sys::ImGuiKey_DownArrow as i32,
97 PageUp = sys::ImGuiKey_PageUp as i32,
99 PageDown = sys::ImGuiKey_PageDown as i32,
101 Home = sys::ImGuiKey_Home as i32,
103 End = sys::ImGuiKey_End as i32,
105 Insert = sys::ImGuiKey_Insert as i32,
107 Delete = sys::ImGuiKey_Delete as i32,
109 Backspace = sys::ImGuiKey_Backspace as i32,
111 Space = sys::ImGuiKey_Space as i32,
113 Enter = sys::ImGuiKey_Enter as i32,
115 Escape = sys::ImGuiKey_Escape as i32,
117 LeftCtrl = sys::ImGuiKey_LeftCtrl as i32,
119 LeftShift = sys::ImGuiKey_LeftShift as i32,
121 LeftAlt = sys::ImGuiKey_LeftAlt as i32,
123 LeftSuper = sys::ImGuiKey_LeftSuper as i32,
125 RightCtrl = sys::ImGuiKey_RightCtrl as i32,
127 RightShift = sys::ImGuiKey_RightShift as i32,
129 RightAlt = sys::ImGuiKey_RightAlt as i32,
131 RightSuper = sys::ImGuiKey_RightSuper as i32,
133 ModCtrl = sys::ImGuiMod_Ctrl as i32,
135 ModShift = sys::ImGuiMod_Shift as i32,
137 ModAlt = sys::ImGuiMod_Alt as i32,
139 ModSuper = sys::ImGuiMod_Super as i32,
141 Menu = sys::ImGuiKey_Menu as i32,
143 Key0 = sys::ImGuiKey_0 as i32,
145 Key1 = sys::ImGuiKey_1 as i32,
147 Key2 = sys::ImGuiKey_2 as i32,
149 Key3 = sys::ImGuiKey_3 as i32,
151 Key4 = sys::ImGuiKey_4 as i32,
153 Key5 = sys::ImGuiKey_5 as i32,
155 Key6 = sys::ImGuiKey_6 as i32,
157 Key7 = sys::ImGuiKey_7 as i32,
159 Key8 = sys::ImGuiKey_8 as i32,
161 Key9 = sys::ImGuiKey_9 as i32,
163 A = sys::ImGuiKey_A as i32,
165 B = sys::ImGuiKey_B as i32,
167 C = sys::ImGuiKey_C as i32,
169 D = sys::ImGuiKey_D as i32,
171 E = sys::ImGuiKey_E as i32,
173 F = sys::ImGuiKey_F as i32,
175 G = sys::ImGuiKey_G as i32,
177 H = sys::ImGuiKey_H as i32,
179 I = sys::ImGuiKey_I as i32,
181 J = sys::ImGuiKey_J as i32,
183 K = sys::ImGuiKey_K as i32,
185 L = sys::ImGuiKey_L as i32,
187 M = sys::ImGuiKey_M as i32,
189 N = sys::ImGuiKey_N as i32,
191 O = sys::ImGuiKey_O as i32,
193 P = sys::ImGuiKey_P as i32,
195 Q = sys::ImGuiKey_Q as i32,
197 R = sys::ImGuiKey_R as i32,
199 S = sys::ImGuiKey_S as i32,
201 T = sys::ImGuiKey_T as i32,
203 U = sys::ImGuiKey_U as i32,
205 V = sys::ImGuiKey_V as i32,
207 W = sys::ImGuiKey_W as i32,
209 X = sys::ImGuiKey_X as i32,
211 Y = sys::ImGuiKey_Y as i32,
213 Z = sys::ImGuiKey_Z as i32,
215 F1 = sys::ImGuiKey_F1 as i32,
217 F2 = sys::ImGuiKey_F2 as i32,
219 F3 = sys::ImGuiKey_F3 as i32,
221 F4 = sys::ImGuiKey_F4 as i32,
223 F5 = sys::ImGuiKey_F5 as i32,
225 F6 = sys::ImGuiKey_F6 as i32,
227 F7 = sys::ImGuiKey_F7 as i32,
229 F8 = sys::ImGuiKey_F8 as i32,
231 F9 = sys::ImGuiKey_F9 as i32,
233 F10 = sys::ImGuiKey_F10 as i32,
235 F11 = sys::ImGuiKey_F11 as i32,
237 F12 = sys::ImGuiKey_F12 as i32,
239
240 Apostrophe = sys::ImGuiKey_Apostrophe as i32,
243 Comma = sys::ImGuiKey_Comma as i32,
245 Minus = sys::ImGuiKey_Minus as i32,
247 Period = sys::ImGuiKey_Period as i32,
249 Slash = sys::ImGuiKey_Slash as i32,
251 Semicolon = sys::ImGuiKey_Semicolon as i32,
253 Equal = sys::ImGuiKey_Equal as i32,
255 LeftBracket = sys::ImGuiKey_LeftBracket as i32,
257 Backslash = sys::ImGuiKey_Backslash as i32,
259 RightBracket = sys::ImGuiKey_RightBracket as i32,
261 GraveAccent = sys::ImGuiKey_GraveAccent as i32,
263 CapsLock = sys::ImGuiKey_CapsLock as i32,
265 ScrollLock = sys::ImGuiKey_ScrollLock as i32,
267 NumLock = sys::ImGuiKey_NumLock as i32,
269 PrintScreen = sys::ImGuiKey_PrintScreen as i32,
271 Pause = sys::ImGuiKey_Pause as i32,
273
274 Keypad0 = sys::ImGuiKey_Keypad0 as i32,
277 Keypad1 = sys::ImGuiKey_Keypad1 as i32,
279 Keypad2 = sys::ImGuiKey_Keypad2 as i32,
281 Keypad3 = sys::ImGuiKey_Keypad3 as i32,
283 Keypad4 = sys::ImGuiKey_Keypad4 as i32,
285 Keypad5 = sys::ImGuiKey_Keypad5 as i32,
287 Keypad6 = sys::ImGuiKey_Keypad6 as i32,
289 Keypad7 = sys::ImGuiKey_Keypad7 as i32,
291 Keypad8 = sys::ImGuiKey_Keypad8 as i32,
293 Keypad9 = sys::ImGuiKey_Keypad9 as i32,
295 KeypadDecimal = sys::ImGuiKey_KeypadDecimal as i32,
297 KeypadDivide = sys::ImGuiKey_KeypadDivide as i32,
299 KeypadMultiply = sys::ImGuiKey_KeypadMultiply as i32,
301 KeypadSubtract = sys::ImGuiKey_KeypadSubtract as i32,
303 KeypadAdd = sys::ImGuiKey_KeypadAdd as i32,
305 KeypadEnter = sys::ImGuiKey_KeypadEnter as i32,
307 KeypadEqual = sys::ImGuiKey_KeypadEqual as i32,
309
310 Oem102 = sys::ImGuiKey_Oem102 as i32,
312}
313
314impl From<MouseButton> for sys::ImGuiMouseButton {
315 #[inline]
316 fn from(value: MouseButton) -> sys::ImGuiMouseButton {
317 value as sys::ImGuiMouseButton
318 }
319}
320
321impl From<MouseSource> for sys::ImGuiMouseSource {
322 #[inline]
323 fn from(value: MouseSource) -> sys::ImGuiMouseSource {
324 value as sys::ImGuiMouseSource
325 }
326}
327
328impl From<Key> for sys::ImGuiKey {
329 #[inline]
330 fn from(value: Key) -> sys::ImGuiKey {
331 value as sys::ImGuiKey
332 }
333}
334
335bitflags! {
339 #[repr(transparent)]
341 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
342 pub struct InputTextFlags: i32 {
343 const NONE = sys::ImGuiInputTextFlags_None as i32;
345 const CHARS_DECIMAL = sys::ImGuiInputTextFlags_CharsDecimal as i32;
347 const CHARS_HEXADECIMAL = sys::ImGuiInputTextFlags_CharsHexadecimal as i32;
349 const CHARS_UPPERCASE = sys::ImGuiInputTextFlags_CharsUppercase as i32;
351 const CHARS_NO_BLANK = sys::ImGuiInputTextFlags_CharsNoBlank as i32;
353 const AUTO_SELECT_ALL = sys::ImGuiInputTextFlags_AutoSelectAll as i32;
355 const ENTER_RETURNS_TRUE = sys::ImGuiInputTextFlags_EnterReturnsTrue as i32;
357 const CALLBACK_COMPLETION = sys::ImGuiInputTextFlags_CallbackCompletion as i32;
359 const CALLBACK_HISTORY = sys::ImGuiInputTextFlags_CallbackHistory as i32;
361 const CALLBACK_ALWAYS = sys::ImGuiInputTextFlags_CallbackAlways as i32;
363 const CALLBACK_CHAR_FILTER = sys::ImGuiInputTextFlags_CallbackCharFilter as i32;
365 const ALLOW_TAB_INPUT = sys::ImGuiInputTextFlags_AllowTabInput as i32;
367 const CTRL_ENTER_FOR_NEW_LINE = sys::ImGuiInputTextFlags_CtrlEnterForNewLine as i32;
369 const NO_HORIZONTAL_SCROLL = sys::ImGuiInputTextFlags_NoHorizontalScroll as i32;
371 const ALWAYS_OVERWRITE = sys::ImGuiInputTextFlags_AlwaysOverwrite as i32;
373 const READ_ONLY = sys::ImGuiInputTextFlags_ReadOnly as i32;
375 const PASSWORD = sys::ImGuiInputTextFlags_Password as i32;
377 const NO_UNDO_REDO = sys::ImGuiInputTextFlags_NoUndoRedo as i32;
379 const CHARS_SCIENTIFIC = sys::ImGuiInputTextFlags_CharsScientific as i32;
381 const CALLBACK_RESIZE = sys::ImGuiInputTextFlags_CallbackResize as i32;
383 const CALLBACK_EDIT = sys::ImGuiInputTextFlags_CallbackEdit as i32;
385 }
386}
387
388#[cfg(feature = "serde")]
389impl Serialize for InputTextFlags {
390 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
391 where
392 S: serde::Serializer,
393 {
394 serializer.serialize_i32(self.bits())
395 }
396}
397
398#[cfg(feature = "serde")]
399impl<'de> Deserialize<'de> for InputTextFlags {
400 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
401 where
402 D: serde::Deserializer<'de>,
403 {
404 let bits = i32::deserialize(deserializer)?;
405 Ok(InputTextFlags::from_bits_truncate(bits))
406 }
407}
408
409impl crate::Ui {
412 #[doc(alias = "IsKeyDown")]
414 pub fn is_key_down(&self, key: Key) -> bool {
415 unsafe { sys::igIsKeyDown_Nil(key as sys::ImGuiKey) }
416 }
417
418 #[doc(alias = "IsKeyPressed")]
420 pub fn is_key_pressed(&self, key: Key) -> bool {
421 unsafe { sys::igIsKeyPressed_Bool(key as sys::ImGuiKey, true) }
422 }
423
424 #[doc(alias = "IsKeyPressed")]
426 pub fn is_key_pressed_with_repeat(&self, key: Key, repeat: bool) -> bool {
427 unsafe { sys::igIsKeyPressed_Bool(key as sys::ImGuiKey, repeat) }
428 }
429
430 #[doc(alias = "IsKeyReleased")]
432 pub fn is_key_released(&self, key: Key) -> bool {
433 unsafe { sys::igIsKeyReleased_Nil(key as sys::ImGuiKey) }
434 }
435
436 #[doc(alias = "IsMouseDown")]
438 pub fn is_mouse_down(&self, button: MouseButton) -> bool {
439 unsafe { sys::igIsMouseDown_Nil(button.into()) }
440 }
441
442 #[doc(alias = "IsMouseClicked")]
444 pub fn is_mouse_clicked(&self, button: MouseButton) -> bool {
445 unsafe { sys::igIsMouseClicked_Bool(button.into(), false) }
446 }
447
448 #[doc(alias = "IsMouseClicked")]
450 pub fn is_mouse_clicked_with_repeat(&self, button: MouseButton, repeat: bool) -> bool {
451 unsafe { sys::igIsMouseClicked_Bool(button.into(), repeat) }
452 }
453
454 #[doc(alias = "IsMouseReleased")]
456 pub fn is_mouse_released(&self, button: MouseButton) -> bool {
457 unsafe { sys::igIsMouseReleased_Nil(button.into()) }
458 }
459
460 #[doc(alias = "IsMouseDoubleClicked")]
462 pub fn is_mouse_double_clicked(&self, button: MouseButton) -> bool {
463 unsafe { sys::igIsMouseDoubleClicked_Nil(button.into()) }
464 }
465
466 #[doc(alias = "GetMousePos")]
468 pub fn mouse_pos(&self) -> [f32; 2] {
469 let pos = unsafe { sys::igGetMousePos() };
470 [pos.x, pos.y]
471 }
472
473 #[doc(alias = "GetMousePosOnOpeningCurrentPopup")]
475 pub fn mouse_pos_on_opening_current_popup(&self) -> [f32; 2] {
476 let pos = unsafe { sys::igGetMousePosOnOpeningCurrentPopup() };
477 [pos.x, pos.y]
478 }
479
480 #[doc(alias = "IsMouseHoveringRect")]
482 pub fn is_mouse_hovering_rect(&self, r_min: [f32; 2], r_max: [f32; 2]) -> bool {
483 unsafe {
484 sys::igIsMouseHoveringRect(
485 sys::ImVec2::new(r_min[0], r_min[1]),
486 sys::ImVec2::new(r_max[0], r_max[1]),
487 true,
488 )
489 }
490 }
491
492 #[doc(alias = "IsMouseHoveringRect")]
494 pub fn is_mouse_hovering_rect_with_clip(
495 &self,
496 r_min: [f32; 2],
497 r_max: [f32; 2],
498 clip: bool,
499 ) -> bool {
500 unsafe {
501 sys::igIsMouseHoveringRect(
502 sys::ImVec2::new(r_min[0], r_min[1]),
503 sys::ImVec2::new(r_max[0], r_max[1]),
504 clip,
505 )
506 }
507 }
508
509 #[doc(alias = "IsMouseDragging")]
511 pub fn is_mouse_dragging(&self, button: MouseButton) -> bool {
512 unsafe { sys::igIsMouseDragging(button as i32, -1.0) }
513 }
514
515 #[doc(alias = "IsMouseDragging")]
517 pub fn is_mouse_dragging_with_threshold(
518 &self,
519 button: MouseButton,
520 lock_threshold: f32,
521 ) -> bool {
522 unsafe { sys::igIsMouseDragging(button as i32, lock_threshold) }
523 }
524
525 #[doc(alias = "GetMouseDragDelta")]
527 pub fn mouse_drag_delta(&self, button: MouseButton) -> [f32; 2] {
528 let delta = unsafe { sys::igGetMouseDragDelta(button as i32, -1.0) };
529 [delta.x, delta.y]
530 }
531
532 #[doc(alias = "GetMouseDragDelta")]
534 pub fn mouse_drag_delta_with_threshold(
535 &self,
536 button: MouseButton,
537 lock_threshold: f32,
538 ) -> [f32; 2] {
539 let delta = unsafe { sys::igGetMouseDragDelta(button as i32, lock_threshold) };
540 [delta.x, delta.y]
541 }
542
543 #[doc(alias = "ResetMouseDragDelta")]
545 pub fn reset_mouse_drag_delta(&self, button: MouseButton) {
546 unsafe { sys::igResetMouseDragDelta(button as i32) }
547 }
548
549 #[doc(alias = "IsItemToggledSelection")]
554 pub fn is_item_toggled_selection(&self) -> bool {
555 unsafe { sys::igIsItemToggledSelection() }
556 }
557}