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 self.run_with_bound_context(|| 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 self.run_with_bound_context(|| unsafe {
17 sys::igIsKeyPressed_Bool(key as sys::ImGuiKey, true)
18 })
19 }
20
21 #[doc(alias = "IsKeyPressed")]
23 pub fn is_key_pressed_with_repeat(&self, key: Key, repeat: bool) -> bool {
24 self.run_with_bound_context(|| unsafe {
25 sys::igIsKeyPressed_Bool(key as sys::ImGuiKey, repeat)
26 })
27 }
28
29 #[doc(alias = "IsKeyReleased")]
31 pub fn is_key_released(&self, key: Key) -> bool {
32 self.run_with_bound_context(|| unsafe { sys::igIsKeyReleased_Nil(key as sys::ImGuiKey) })
33 }
34
35 #[doc(alias = "IsKeyChordPressed")]
37 pub fn is_key_chord_pressed(&self, key_chord: KeyChord) -> bool {
38 self.run_with_bound_context(|| unsafe { sys::igIsKeyChordPressed_Nil(key_chord.raw()) })
39 }
40
41 #[doc(alias = "Shortcut")]
43 pub fn shortcut(&self, key_chord: KeyChord) -> bool {
44 self.shortcut_with_flags(key_chord, ShortcutOptions::new())
45 }
46
47 #[doc(alias = "Shortcut")]
49 pub fn shortcut_with_flags(
50 &self,
51 key_chord: KeyChord,
52 flags: impl Into<ShortcutOptions>,
53 ) -> bool {
54 let flags = flags.into();
55 self.run_with_bound_context(|| unsafe { sys::igShortcut_Nil(key_chord.raw(), flags.raw()) })
56 }
57
58 #[doc(alias = "SetNextItemShortcut")]
60 pub fn set_next_item_shortcut(&self, key_chord: KeyChord) {
61 self.set_next_item_shortcut_with_flags(key_chord, NextItemShortcutOptions::new());
62 }
63
64 #[doc(alias = "SetNextItemShortcut")]
66 pub fn set_next_item_shortcut_with_flags(
67 &self,
68 key_chord: KeyChord,
69 flags: impl Into<NextItemShortcutOptions>,
70 ) {
71 let flags = flags.into();
72 self.run_with_bound_context(|| unsafe {
73 sys::igSetNextItemShortcut(key_chord.raw(), flags.raw())
74 });
75 }
76
77 #[doc(alias = "SetNextFrameWantCaptureKeyboard")]
79 pub fn set_next_frame_want_capture_keyboard(&self, want_capture_keyboard: bool) {
80 self.run_with_bound_context(|| unsafe {
81 sys::igSetNextFrameWantCaptureKeyboard(want_capture_keyboard)
82 });
83 }
84
85 #[doc(alias = "SetNextFrameWantCaptureMouse")]
87 pub fn set_next_frame_want_capture_mouse(&self, want_capture_mouse: bool) {
88 self.run_with_bound_context(|| unsafe {
89 sys::igSetNextFrameWantCaptureMouse(want_capture_mouse)
90 });
91 }
92
93 #[doc(alias = "IsMouseDown")]
95 pub fn is_mouse_down(&self, button: MouseButton) -> bool {
96 self.run_with_bound_context(|| unsafe { sys::igIsMouseDown_Nil(button.into()) })
97 }
98
99 #[doc(alias = "IsMouseClicked")]
101 pub fn is_mouse_clicked(&self, button: MouseButton) -> bool {
102 self.run_with_bound_context(|| unsafe { sys::igIsMouseClicked_Bool(button.into(), false) })
103 }
104
105 #[doc(alias = "IsMouseClicked")]
107 pub fn is_mouse_clicked_with_repeat(&self, button: MouseButton, repeat: bool) -> bool {
108 self.run_with_bound_context(|| unsafe { sys::igIsMouseClicked_Bool(button.into(), repeat) })
109 }
110
111 #[doc(alias = "IsMouseReleased")]
113 pub fn is_mouse_released(&self, button: MouseButton) -> bool {
114 self.run_with_bound_context(|| unsafe { sys::igIsMouseReleased_Nil(button.into()) })
115 }
116
117 #[doc(alias = "IsMouseDoubleClicked")]
119 pub fn is_mouse_double_clicked(&self, button: MouseButton) -> bool {
120 self.run_with_bound_context(|| unsafe { sys::igIsMouseDoubleClicked_Nil(button.into()) })
121 }
122
123 #[doc(alias = "IsMousePosValid")]
127 pub fn is_mouse_pos_valid(&self) -> bool {
128 self.run_with_bound_context(|| unsafe { sys::igIsMousePosValid(std::ptr::null()) })
129 }
130
131 #[doc(alias = "IsMousePosValid")]
133 pub fn is_mouse_pos_valid_at(&self, pos: [f32; 2]) -> bool {
134 let v = sys::ImVec2_c {
135 x: pos[0],
136 y: pos[1],
137 };
138 self.run_with_bound_context(|| unsafe {
139 sys::igIsMousePosValid(&v as *const sys::ImVec2_c)
140 })
141 }
142
143 #[doc(alias = "IsMouseReleasedWithDelay")]
145 pub fn is_mouse_released_with_delay(&self, button: MouseButton, delay: f32) -> bool {
146 assert!(
147 delay.is_finite() && delay >= 0.0,
148 "Ui::is_mouse_released_with_delay() delay must be finite and non-negative"
149 );
150 self.run_with_bound_context(|| unsafe {
151 sys::igIsMouseReleasedWithDelay(button.into(), delay)
152 })
153 }
154
155 #[doc(alias = "IsMouseReleasedWithDelay")]
157 pub fn is_mouse_released_with_single_click_delay(&self, button: MouseButton) -> bool {
158 self.run_with_bound_context(|| unsafe {
159 sys::igIsMouseReleasedWithDelay(button.into(), -1.0)
160 })
161 }
162
163 #[doc(alias = "GetMousePos")]
165 pub fn mouse_pos(&self) -> [f32; 2] {
166 let pos = self.run_with_bound_context(|| unsafe { sys::igGetMousePos() });
167 [pos.x, pos.y]
168 }
169
170 #[doc(alias = "GetMousePosOnOpeningCurrentPopup")]
172 pub fn mouse_pos_on_opening_current_popup(&self) -> [f32; 2] {
173 let pos =
174 self.run_with_bound_context(|| unsafe { sys::igGetMousePosOnOpeningCurrentPopup() });
175 [pos.x, pos.y]
176 }
177
178 #[doc(alias = "IsMouseHoveringRect")]
180 pub fn is_mouse_hovering_rect(&self, r_min: [f32; 2], r_max: [f32; 2]) -> bool {
181 self.run_with_bound_context(|| unsafe {
182 sys::igIsMouseHoveringRect(
183 sys::ImVec2::new(r_min[0], r_min[1]),
184 sys::ImVec2::new(r_max[0], r_max[1]),
185 true,
186 )
187 })
188 }
189
190 #[doc(alias = "IsMouseHoveringRect")]
192 pub fn is_mouse_hovering_rect_with_clip(
193 &self,
194 r_min: [f32; 2],
195 r_max: [f32; 2],
196 clip: bool,
197 ) -> bool {
198 self.run_with_bound_context(|| unsafe {
199 sys::igIsMouseHoveringRect(
200 sys::ImVec2::new(r_min[0], r_min[1]),
201 sys::ImVec2::new(r_max[0], r_max[1]),
202 clip,
203 )
204 })
205 }
206
207 #[doc(alias = "IsMouseDragging")]
209 pub fn is_mouse_dragging(&self, button: MouseButton) -> bool {
210 self.run_with_bound_context(|| unsafe { sys::igIsMouseDragging(button as i32, -1.0) })
211 }
212
213 #[doc(alias = "IsMouseDragging")]
215 pub fn is_mouse_dragging_with_threshold(
216 &self,
217 button: MouseButton,
218 lock_threshold: f32,
219 ) -> bool {
220 self.run_with_bound_context(|| unsafe {
221 sys::igIsMouseDragging(button as i32, lock_threshold)
222 })
223 }
224
225 #[doc(alias = "GetMouseDragDelta")]
227 pub fn mouse_drag_delta(&self, button: MouseButton) -> [f32; 2] {
228 let delta = self
229 .run_with_bound_context(|| unsafe { sys::igGetMouseDragDelta(button as i32, -1.0) });
230 [delta.x, delta.y]
231 }
232
233 #[doc(alias = "GetMouseDragDelta")]
235 pub fn mouse_drag_delta_with_threshold(
236 &self,
237 button: MouseButton,
238 lock_threshold: f32,
239 ) -> [f32; 2] {
240 let delta = self.run_with_bound_context(|| unsafe {
241 sys::igGetMouseDragDelta(button as i32, lock_threshold)
242 });
243 [delta.x, delta.y]
244 }
245
246 #[doc(alias = "ResetMouseDragDelta")]
248 pub fn reset_mouse_drag_delta(&self, button: MouseButton) {
249 self.run_with_bound_context(|| unsafe { sys::igResetMouseDragDelta(button as i32) });
250 }
251
252 #[doc(alias = "IsItemToggledSelection")]
257 pub fn is_item_toggled_selection(&self) -> bool {
258 self.run_with_bound_context(|| unsafe { sys::igIsItemToggledSelection() })
259 }
260}