dear_imgui_rs/utils/
input.rs1use super::counts::non_negative_count_from_i32;
2use super::validation::assert_finite_f32;
3use crate::input::{Key, MouseButton};
4use crate::sys;
5
6impl crate::ui::Ui {
7 #[doc(alias = "GetKeyPressedAmount")]
9 pub fn get_key_pressed_amount(&self, key: Key, repeat_delay: f32, rate: f32) -> usize {
10 assert_finite_f32("Ui::get_key_pressed_amount()", "repeat_delay", repeat_delay);
11 assert_finite_f32("Ui::get_key_pressed_amount()", "rate", rate);
12 non_negative_count_from_i32(
13 "Ui::get_key_pressed_amount()",
14 self.run_with_bound_context(|| unsafe {
15 sys::igGetKeyPressedAmount(key.into(), repeat_delay, rate)
16 }),
17 )
18 }
19
20 #[doc(alias = "GetKeyName")]
22 pub fn get_key_name(&self, key: Key) -> &str {
23 self.run_with_bound_context(|| unsafe {
24 let name_ptr = sys::igGetKeyName(key.into());
25 if name_ptr.is_null() {
26 return "Unknown";
27 }
28 let c_str = std::ffi::CStr::from_ptr(name_ptr);
29 c_str.to_str().unwrap_or("Unknown")
30 })
31 }
32
33 #[doc(alias = "GetMouseClickedCount")]
35 pub fn get_mouse_clicked_count(&self, button: MouseButton) -> usize {
36 non_negative_count_from_i32(
37 "Ui::get_mouse_clicked_count()",
38 self.run_with_bound_context(|| unsafe { sys::igGetMouseClickedCount(button.into()) }),
39 )
40 }
41
42 #[doc(alias = "GetMousePos")]
44 pub fn get_mouse_pos(&self) -> [f32; 2] {
45 let pos = self.run_with_bound_context(|| unsafe { sys::igGetMousePos() });
46 [pos.x, pos.y]
47 }
48
49 #[doc(alias = "GetMousePosOnOpeningCurrentPopup")]
51 pub fn get_mouse_pos_on_opening_current_popup(&self) -> [f32; 2] {
52 let pos =
53 self.run_with_bound_context(|| unsafe { sys::igGetMousePosOnOpeningCurrentPopup() });
54 [pos.x, pos.y]
55 }
56
57 #[doc(alias = "GetMouseDragDelta")]
59 pub fn get_mouse_drag_delta(&self, button: MouseButton, lock_threshold: f32) -> [f32; 2] {
60 assert_finite_f32(
61 "Ui::get_mouse_drag_delta()",
62 "lock_threshold",
63 lock_threshold,
64 );
65 let delta = self.run_with_bound_context(|| unsafe {
66 sys::igGetMouseDragDelta(button.into(), lock_threshold)
67 });
68 [delta.x, delta.y]
69 }
70
71 #[doc(alias = "GetIO")]
73 pub fn get_mouse_wheel(&self) -> f32 {
74 self.io().mouse_wheel()
75 }
76
77 #[doc(alias = "GetIO")]
79 pub fn get_mouse_wheel_h(&self) -> f32 {
80 self.io().mouse_wheel_h()
81 }
82
83 #[doc(alias = "IsAnyMouseDown")]
85 pub fn is_any_mouse_down(&self) -> bool {
86 self.run_with_bound_context(|| unsafe { sys::igIsAnyMouseDown() })
87 }
88}