Skip to main content

dear_imgui_rs/utils/
item.rs

1use crate::input::MouseButton;
2use crate::sys;
3use crate::utils::non_negative_count_from_i32;
4
5impl crate::ui::Ui {
6    /// Returns a delayed single-click count, or an immediate count for repeated clicks.
7    ///
8    /// This uses the left mouse button and [`Io::mouse_single_click_delay`](crate::Io::mouse_single_click_delay).
9    #[doc(alias = "GetItemClickedCountWithSingleClickDelay")]
10    pub fn item_clicked_count_with_single_click_delay(&self) -> usize {
11        self.item_clicked_count_with_single_click_delay_for(MouseButton::Left)
12    }
13
14    /// Returns a delayed single-click count for `button`, or an immediate count for repeated clicks.
15    #[doc(alias = "GetItemClickedCountWithSingleClickDelay")]
16    pub fn item_clicked_count_with_single_click_delay_for(&self, button: MouseButton) -> usize {
17        non_negative_count_from_i32(
18            "Ui::item_clicked_count_with_single_click_delay_for()",
19            self.run_with_bound_context(|| unsafe {
20                sys::igGetItemClickedCountWithSingleClickDelay(button.into(), -1.0)
21            }),
22        )
23    }
24
25    /// Returns a delayed single-click count using an explicit delay.
26    ///
27    /// Dear ImGui clamps the delay to remain longer than the configured double-click time.
28    #[doc(alias = "GetItemClickedCountWithSingleClickDelay")]
29    pub fn item_clicked_count_with_delay(&self, button: MouseButton, delay: f32) -> usize {
30        assert!(
31            delay.is_finite() && delay >= 0.0,
32            "Ui::item_clicked_count_with_delay() delay must be finite and non-negative"
33        );
34        non_negative_count_from_i32(
35            "Ui::item_clicked_count_with_delay()",
36            self.run_with_bound_context(|| unsafe {
37                sys::igGetItemClickedCountWithSingleClickDelay(button.into(), delay)
38            }),
39        )
40    }
41
42    /// Returns `true` if the last item open state was toggled
43    #[doc(alias = "IsItemToggledOpen")]
44    pub fn is_item_toggled_open(&self) -> bool {
45        self.run_with_bound_context(|| unsafe { sys::igIsItemToggledOpen() })
46    }
47
48    /// Returns the upper-left bounding rectangle of the last item (screen space)
49    #[doc(alias = "GetItemRectMin")]
50    pub fn item_rect_min(&self) -> [f32; 2] {
51        let rect = self.run_with_bound_context(|| unsafe { sys::igGetItemRectMin() });
52        [rect.x, rect.y]
53    }
54
55    /// Returns the lower-right bounding rectangle of the last item (screen space)
56    #[doc(alias = "GetItemRectMax")]
57    pub fn item_rect_max(&self) -> [f32; 2] {
58        let rect = self.run_with_bound_context(|| unsafe { sys::igGetItemRectMax() });
59        [rect.x, rect.y]
60    }
61
62    /// Allows the next item to be overlapped by a subsequent item.
63    #[doc(alias = "SetNextItemAllowOverlap")]
64    pub fn set_next_item_allow_overlap(&self) {
65        self.run_with_bound_context(|| unsafe { sys::igSetNextItemAllowOverlap() });
66    }
67}