1#![allow(clippy::float_cmp)]
2use bitflags::bitflags;
3
4use crate::input::mouse::MouseButton;
5use crate::style::StyleColor;
6use crate::sys;
7use crate::Ui;
8
9bitflags! {
10 #[repr(transparent)]
12 pub struct ItemHoveredFlags: u32 {
13 const ALLOW_WHEN_BLOCKED_BY_POPUP = sys::ImGuiHoveredFlags_AllowWhenBlockedByPopup;
15 const ALLOW_WHEN_BLOCKED_BY_ACTIVE_ITEM = sys::ImGuiHoveredFlags_AllowWhenBlockedByActiveItem;
17 const ALLOW_WHEN_OVERLAPPED = sys::ImGuiHoveredFlags_AllowWhenOverlapped;
19 const ALLOW_WHEN_DISABLED = sys::ImGuiHoveredFlags_AllowWhenDisabled;
21 const RECT_ONLY = sys::ImGuiHoveredFlags_RectOnly;
22 }
23}
24
25impl<'ui> Ui<'ui> {
27 #[doc(alias = "IsItemHovered")]
29 pub fn is_item_hovered(&self) -> bool {
30 unsafe { sys::igIsItemHovered(0) }
31 }
32 #[doc(alias = "IsItemHovered")]
34 pub fn is_item_hovered_with_flags(&self, flags: ItemHoveredFlags) -> bool {
35 unsafe { sys::igIsItemHovered(flags.bits() as i32) }
36 }
37 #[doc(alias = "IsItemActive")]
39 pub fn is_item_active(&self) -> bool {
40 unsafe { sys::igIsItemActive() }
41 }
42 #[doc(alias = "IsItemFocused")]
43 pub fn is_item_focused(&self) -> bool {
45 unsafe { sys::igIsItemFocused() }
46 }
47 #[doc(alias = "IsItemClicked")]
52 pub fn is_item_clicked(&self) -> bool {
53 self.is_item_clicked_with_button(MouseButton::Left)
54 }
55
56 #[doc(alias = "IsItemClicked")]
58 pub fn is_item_clicked_with_button(&self, button: MouseButton) -> bool {
59 unsafe { sys::igIsItemClicked(button as i32) }
60 }
61 #[doc(alias = "IsItemVisible")]
63 pub fn is_item_visible(&self) -> bool {
64 unsafe { sys::igIsItemVisible() }
65 }
66 #[doc(alias = "IsItemEdited")]
68 pub fn is_item_edited(&self) -> bool {
69 unsafe { sys::igIsItemEdited() }
70 }
71 #[doc(alias = "IsItemActivated")]
73 pub fn is_item_activated(&self) -> bool {
74 unsafe { sys::igIsItemActivated() }
75 }
76 #[doc(alias = "IsItemDeactivated")]
78 pub fn is_item_deactivated(&self) -> bool {
79 unsafe { sys::igIsItemDeactivated() }
80 }
81 #[doc(alias = "IsItemDeactivatedAfterEdit")]
83 pub fn is_item_deactivated_after_edit(&self) -> bool {
85 unsafe { sys::igIsItemDeactivatedAfterEdit() }
86 }
87 #[doc(alias = "IsItemToggledOpen")]
89 pub fn is_item_toggled_open(&self) -> bool {
90 unsafe { sys::igIsItemToggledOpen() }
91 }
92 #[doc(alias = "IsAnyItemHovered")]
94 pub fn is_any_item_hovered(&self) -> bool {
95 unsafe { sys::igIsAnyItemHovered() }
96 }
97 #[doc(alias = "IsAnyItemActive")]
99 pub fn is_any_item_active(&self) -> bool {
100 unsafe { sys::igIsAnyItemActive() }
101 }
102 #[doc(alias = "IsAnyItemFocused")]
104 pub fn is_any_item_focused(&self) -> bool {
105 unsafe { sys::igIsAnyItemFocused() }
106 }
107 #[doc(alias = "GetItemRectMin")]
109 pub fn item_rect_min(&self) -> [f32; 2] {
110 let mut out = sys::ImVec2::zero();
111 unsafe { sys::igGetItemRectMin(&mut out) }
112 out.into()
113 }
114 #[doc(alias = "GetItemRectMax")]
116 pub fn item_rect_max(&self) -> [f32; 2] {
117 let mut out = sys::ImVec2::zero();
118 unsafe { sys::igGetItemRectMax(&mut out) }
119 out.into()
120 }
121 #[doc(alias = "GetItemRectSize")]
123 pub fn item_rect_size(&self) -> [f32; 2] {
124 let mut out = sys::ImVec2::zero();
125 unsafe { sys::igGetItemRectSize(&mut out) }
126 out.into()
127 }
128 #[doc(alias = "SetItemAllowOverlap")]
132 pub fn set_item_allow_overlap(&self) {
133 unsafe { sys::igSetItemAllowOverlap() };
134 }
135 #[doc(alias = "SetItemDefaultFocus")]
137 pub fn set_item_default_focus(&self) {
138 unsafe { sys::igSetItemDefaultFocus() };
139 }
140}
141
142impl<'ui> Ui<'ui> {
144 #[doc(alias = "IsRectVisibleNil")]
146 pub fn is_cursor_rect_visible(&self, size: [f32; 2]) -> bool {
147 unsafe { sys::igIsRectVisible_Nil(size.into()) }
148 }
149 #[doc(alias = "IsRectVisibleNilVec2")]
151 pub fn is_rect_visible(&self, rect_min: [f32; 2], rect_max: [f32; 2]) -> bool {
152 unsafe { sys::igIsRectVisible_Vec2(rect_min.into(), rect_max.into()) }
153 }
154 #[doc(alias = "GetTime")]
158 pub fn time(&self) -> f64 {
159 unsafe { sys::igGetTime() }
160 }
161 #[doc(alias = "GetFrameCount")]
165 pub fn frame_count(&self) -> i32 {
166 unsafe { sys::igGetFrameCount() }
167 }
168 #[doc(alias = "GetStyle")]
173 pub fn style_color(&self, style_color: StyleColor) -> [f32; 4] {
174 self.ctx.style()[style_color]
175 }
176}