1#![allow(clippy::float_cmp)]
2use bitflags::bitflags;
34use crate::input::mouse::MouseButton;
5use crate::style::StyleColor;
6use crate::sys;
7use crate::Ui;
89bitflags! {
10/// Item hover check option flags
11#[repr(transparent)]
12pub struct ItemHoveredFlags: u32 {
13/// Return true even if a popup window is blocking access to this item
14const ALLOW_WHEN_BLOCKED_BY_POPUP = sys::ImGuiHoveredFlags_AllowWhenBlockedByPopup;
15/// Return true even if an active item is blocking access to this item
16const ALLOW_WHEN_BLOCKED_BY_ACTIVE_ITEM = sys::ImGuiHoveredFlags_AllowWhenBlockedByActiveItem;
17/// Return true even if the position is obstructed or overlapped by another window
18const ALLOW_WHEN_OVERLAPPED = sys::ImGuiHoveredFlags_AllowWhenOverlapped;
19/// Return true even if the item is disabled
20const ALLOW_WHEN_DISABLED = sys::ImGuiHoveredFlags_AllowWhenDisabled;
21const RECT_ONLY = sys::ImGuiHoveredFlags_RectOnly;
22 }
23}
2425/// # Item/widget utilities
26impl<'ui> Ui<'ui> {
27/// Returns `true` if the last item is hovered
28#[doc(alias = "IsItemHovered")]
29pub fn is_item_hovered(&self) -> bool {
30unsafe { sys::igIsItemHovered(0) }
31 }
32/// Returns `true` if the last item is hovered based on the given flags
33#[doc(alias = "IsItemHovered")]
34pub fn is_item_hovered_with_flags(&self, flags: ItemHoveredFlags) -> bool {
35unsafe { sys::igIsItemHovered(flags.bits() as i32) }
36 }
37/// Returns `true` if the last item is active
38#[doc(alias = "IsItemActive")]
39pub fn is_item_active(&self) -> bool {
40unsafe { sys::igIsItemActive() }
41 }
42#[doc(alias = "IsItemFocused")]
43/// Returns `true` if the last item is focused for keyboard/gamepad navigation
44pub fn is_item_focused(&self) -> bool {
45unsafe { sys::igIsItemFocused() }
46 }
47/// Returns `true` if the last item is being clicked by `MouseButton::Left`.
48 ///
49 /// This is the same as [is_item_clicked_with_button](Self::is_item_clicked_with_button)
50 /// with `button` set to `MouseButton::Left`.
51#[doc(alias = "IsItemClicked")]
52pub fn is_item_clicked(&self) -> bool {
53self.is_item_clicked_with_button(MouseButton::Left)
54 }
5556/// Returns `true` if the last item is being clicked
57#[doc(alias = "IsItemClicked")]
58pub fn is_item_clicked_with_button(&self, button: MouseButton) -> bool {
59unsafe { sys::igIsItemClicked(button as i32) }
60 }
61/// Returns `true` if the last item is visible
62#[doc(alias = "IsItemVisible")]
63pub fn is_item_visible(&self) -> bool {
64unsafe { sys::igIsItemVisible() }
65 }
66/// Returns `true` if the last item modified its underlying value this frame or was pressed
67#[doc(alias = "IsItemEdited")]
68pub fn is_item_edited(&self) -> bool {
69unsafe { sys::igIsItemEdited() }
70 }
71/// Returns `true` if the last item was just made active
72#[doc(alias = "IsItemActivated")]
73pub fn is_item_activated(&self) -> bool {
74unsafe { sys::igIsItemActivated() }
75 }
76/// Returns `true` if the last item was just made inactive
77#[doc(alias = "IsItemDeactivated")]
78pub fn is_item_deactivated(&self) -> bool {
79unsafe { sys::igIsItemDeactivated() }
80 }
81/// Returns `true` if the last item was just made inactive and made a value change when it was
82#[doc(alias = "IsItemDeactivatedAfterEdit")]
83/// active
84pub fn is_item_deactivated_after_edit(&self) -> bool {
85unsafe { sys::igIsItemDeactivatedAfterEdit() }
86 }
87/// Returns `true` if the last item open state was toggled
88#[doc(alias = "IsItemToggledOpen")]
89pub fn is_item_toggled_open(&self) -> bool {
90unsafe { sys::igIsItemToggledOpen() }
91 }
92/// Returns `true` if any item is hovered
93#[doc(alias = "IsAnyItemHovered")]
94pub fn is_any_item_hovered(&self) -> bool {
95unsafe { sys::igIsAnyItemHovered() }
96 }
97/// Returns `true` if any item is active
98#[doc(alias = "IsAnyItemActive")]
99pub fn is_any_item_active(&self) -> bool {
100unsafe { sys::igIsAnyItemActive() }
101 }
102/// Returns `true` if any item is focused
103#[doc(alias = "IsAnyItemFocused")]
104pub fn is_any_item_focused(&self) -> bool {
105unsafe { sys::igIsAnyItemFocused() }
106 }
107/// Returns the upper-left bounding rectangle of the last item (in screen coordinates)
108#[doc(alias = "GetItemRectMin")]
109pub fn item_rect_min(&self) -> [f32; 2] {
110let mut out = sys::ImVec2::zero();
111unsafe { sys::igGetItemRectMin(&mut out) }
112 out.into()
113 }
114/// Returns the lower-right bounding rectangle of the last item (in screen coordinates)
115#[doc(alias = "GetItemRectMax")]
116pub fn item_rect_max(&self) -> [f32; 2] {
117let mut out = sys::ImVec2::zero();
118unsafe { sys::igGetItemRectMax(&mut out) }
119 out.into()
120 }
121/// Returns the size of the last item
122#[doc(alias = "GetItemRectSize")]
123pub fn item_rect_size(&self) -> [f32; 2] {
124let mut out = sys::ImVec2::zero();
125unsafe { sys::igGetItemRectSize(&mut out) }
126 out.into()
127 }
128/// Allows the last item to be overlapped by a subsequent item.
129 ///
130 /// Both may be activated during the same frame before the later one takes priority.
131#[doc(alias = "SetItemAllowOverlap")]
132pub fn set_item_allow_overlap(&self) {
133unsafe { sys::igSetItemAllowOverlap() };
134 }
135/// Makes the last item the default focused item of the window
136#[doc(alias = "SetItemDefaultFocus")]
137pub fn set_item_default_focus(&self) {
138unsafe { sys::igSetItemDefaultFocus() };
139 }
140}
141142/// # Miscellaneous utilities
143impl<'ui> Ui<'ui> {
144/// Returns `true` if the rectangle (of given size, starting from cursor position) is visible
145#[doc(alias = "IsRectVisibleNil")]
146pub fn is_cursor_rect_visible(&self, size: [f32; 2]) -> bool {
147unsafe { sys::igIsRectVisible_Nil(size.into()) }
148 }
149/// Returns `true` if the rectangle (in screen coordinates) is visible
150#[doc(alias = "IsRectVisibleNilVec2")]
151pub fn is_rect_visible(&self, rect_min: [f32; 2], rect_max: [f32; 2]) -> bool {
152unsafe { sys::igIsRectVisible_Vec2(rect_min.into(), rect_max.into()) }
153 }
154/// Returns the global imgui-rs time.
155 ///
156 /// Incremented by Io::delta_time every frame.
157#[doc(alias = "GetTime")]
158pub fn time(&self) -> f64 {
159unsafe { sys::igGetTime() }
160 }
161/// Returns the global imgui-rs frame count.
162 ///
163 /// Incremented by 1 every frame.
164#[doc(alias = "GetFrameCount")]
165pub fn frame_count(&self) -> i32 {
166unsafe { sys::igGetFrameCount() }
167 }
168/// Returns a single style color from the user interface style.
169 ///
170 /// Use this function if you need to access the colors, but don't want to clone the entire
171 /// style object.
172#[doc(alias = "GetStyle")]
173pub fn style_color(&self, style_color: StyleColor) -> [f32; 4] {
174self.ctx.style()[style_color]
175 }
176}