dear_imgui_rs/input/
ui.rs1use super::{Key, KeyChord, MouseButton, NextItemShortcutOptions, ShortcutOptions};
2use crate::sys;
3
4impl crate::Ui {
7 #[doc(alias = "IsKeyDown")]
9 pub fn is_key_down(&self, key: Key) -> bool {
10 unsafe { sys::igIsKeyDown_Nil(key as sys::ImGuiKey) }
11 }
12
13 #[doc(alias = "IsKeyPressed")]
15 pub fn is_key_pressed(&self, key: Key) -> bool {
16 unsafe { sys::igIsKeyPressed_Bool(key as sys::ImGuiKey, true) }
17 }
18
19 #[doc(alias = "IsKeyPressed")]
21 pub fn is_key_pressed_with_repeat(&self, key: Key, repeat: bool) -> bool {
22 unsafe { sys::igIsKeyPressed_Bool(key as sys::ImGuiKey, repeat) }
23 }
24
25 #[doc(alias = "IsKeyReleased")]
27 pub fn is_key_released(&self, key: Key) -> bool {
28 unsafe { sys::igIsKeyReleased_Nil(key as sys::ImGuiKey) }
29 }
30
31 #[doc(alias = "IsKeyChordPressed")]
33 pub fn is_key_chord_pressed(&self, key_chord: KeyChord) -> bool {
34 unsafe { sys::igIsKeyChordPressed_Nil(key_chord.raw()) }
35 }
36
37 #[doc(alias = "Shortcut")]
39 pub fn shortcut(&self, key_chord: KeyChord) -> bool {
40 self.shortcut_with_flags(key_chord, ShortcutOptions::new())
41 }
42
43 #[doc(alias = "Shortcut")]
45 pub fn shortcut_with_flags(
46 &self,
47 key_chord: KeyChord,
48 flags: impl Into<ShortcutOptions>,
49 ) -> bool {
50 unsafe { sys::igShortcut_Nil(key_chord.raw(), flags.into().raw()) }
51 }
52
53 #[doc(alias = "SetNextItemShortcut")]
55 pub fn set_next_item_shortcut(&self, key_chord: KeyChord) {
56 self.set_next_item_shortcut_with_flags(key_chord, NextItemShortcutOptions::new());
57 }
58
59 #[doc(alias = "SetNextItemShortcut")]
61 pub fn set_next_item_shortcut_with_flags(
62 &self,
63 key_chord: KeyChord,
64 flags: impl Into<NextItemShortcutOptions>,
65 ) {
66 let flags = flags.into();
67 unsafe { sys::igSetNextItemShortcut(key_chord.raw(), flags.raw()) }
68 }
69
70 #[doc(alias = "SetNextFrameWantCaptureKeyboard")]
72 pub fn set_next_frame_want_capture_keyboard(&self, want_capture_keyboard: bool) {
73 unsafe { sys::igSetNextFrameWantCaptureKeyboard(want_capture_keyboard) }
74 }
75
76 #[doc(alias = "SetNextFrameWantCaptureMouse")]
78 pub fn set_next_frame_want_capture_mouse(&self, want_capture_mouse: bool) {
79 unsafe { sys::igSetNextFrameWantCaptureMouse(want_capture_mouse) }
80 }
81
82 #[doc(alias = "IsMouseDown")]
84 pub fn is_mouse_down(&self, button: MouseButton) -> bool {
85 unsafe { sys::igIsMouseDown_Nil(button.into()) }
86 }
87
88 #[doc(alias = "IsMouseClicked")]
90 pub fn is_mouse_clicked(&self, button: MouseButton) -> bool {
91 unsafe { sys::igIsMouseClicked_Bool(button.into(), false) }
92 }
93
94 #[doc(alias = "IsMouseClicked")]
96 pub fn is_mouse_clicked_with_repeat(&self, button: MouseButton, repeat: bool) -> bool {
97 unsafe { sys::igIsMouseClicked_Bool(button.into(), repeat) }
98 }
99
100 #[doc(alias = "IsMouseReleased")]
102 pub fn is_mouse_released(&self, button: MouseButton) -> bool {
103 unsafe { sys::igIsMouseReleased_Nil(button.into()) }
104 }
105
106 #[doc(alias = "IsMouseDoubleClicked")]
108 pub fn is_mouse_double_clicked(&self, button: MouseButton) -> bool {
109 unsafe { sys::igIsMouseDoubleClicked_Nil(button.into()) }
110 }
111
112 #[doc(alias = "IsMousePosValid")]
116 pub fn is_mouse_pos_valid(&self) -> bool {
117 unsafe { sys::igIsMousePosValid(std::ptr::null()) }
118 }
119
120 #[doc(alias = "IsMousePosValid")]
122 pub fn is_mouse_pos_valid_at(&self, pos: [f32; 2]) -> bool {
123 let v = sys::ImVec2_c {
124 x: pos[0],
125 y: pos[1],
126 };
127 unsafe { sys::igIsMousePosValid(&v as *const sys::ImVec2_c) }
128 }
129
130 #[doc(alias = "IsMouseReleasedWithDelay")]
132 pub fn is_mouse_released_with_delay(&self, button: MouseButton, delay: f32) -> bool {
133 unsafe { sys::igIsMouseReleasedWithDelay(button.into(), delay) }
134 }
135
136 #[doc(alias = "GetMousePos")]
138 pub fn mouse_pos(&self) -> [f32; 2] {
139 let pos = unsafe { sys::igGetMousePos() };
140 [pos.x, pos.y]
141 }
142
143 #[doc(alias = "GetMousePosOnOpeningCurrentPopup")]
145 pub fn mouse_pos_on_opening_current_popup(&self) -> [f32; 2] {
146 let pos = unsafe { sys::igGetMousePosOnOpeningCurrentPopup() };
147 [pos.x, pos.y]
148 }
149
150 #[doc(alias = "IsMouseHoveringRect")]
152 pub fn is_mouse_hovering_rect(&self, r_min: [f32; 2], r_max: [f32; 2]) -> bool {
153 unsafe {
154 sys::igIsMouseHoveringRect(
155 sys::ImVec2::new(r_min[0], r_min[1]),
156 sys::ImVec2::new(r_max[0], r_max[1]),
157 true,
158 )
159 }
160 }
161
162 #[doc(alias = "IsMouseHoveringRect")]
164 pub fn is_mouse_hovering_rect_with_clip(
165 &self,
166 r_min: [f32; 2],
167 r_max: [f32; 2],
168 clip: bool,
169 ) -> bool {
170 unsafe {
171 sys::igIsMouseHoveringRect(
172 sys::ImVec2::new(r_min[0], r_min[1]),
173 sys::ImVec2::new(r_max[0], r_max[1]),
174 clip,
175 )
176 }
177 }
178
179 #[doc(alias = "IsMouseDragging")]
181 pub fn is_mouse_dragging(&self, button: MouseButton) -> bool {
182 unsafe { sys::igIsMouseDragging(button as i32, -1.0) }
183 }
184
185 #[doc(alias = "IsMouseDragging")]
187 pub fn is_mouse_dragging_with_threshold(
188 &self,
189 button: MouseButton,
190 lock_threshold: f32,
191 ) -> bool {
192 unsafe { sys::igIsMouseDragging(button as i32, lock_threshold) }
193 }
194
195 #[doc(alias = "GetMouseDragDelta")]
197 pub fn mouse_drag_delta(&self, button: MouseButton) -> [f32; 2] {
198 let delta = unsafe { sys::igGetMouseDragDelta(button as i32, -1.0) };
199 [delta.x, delta.y]
200 }
201
202 #[doc(alias = "GetMouseDragDelta")]
204 pub fn mouse_drag_delta_with_threshold(
205 &self,
206 button: MouseButton,
207 lock_threshold: f32,
208 ) -> [f32; 2] {
209 let delta = unsafe { sys::igGetMouseDragDelta(button as i32, lock_threshold) };
210 [delta.x, delta.y]
211 }
212
213 #[doc(alias = "ResetMouseDragDelta")]
215 pub fn reset_mouse_drag_delta(&self, button: MouseButton) {
216 unsafe { sys::igResetMouseDragDelta(button as i32) }
217 }
218
219 #[doc(alias = "IsItemToggledSelection")]
224 pub fn is_item_toggled_selection(&self) -> bool {
225 unsafe { sys::igIsItemToggledSelection() }
226 }
227}