#![allow(clippy::float_cmp)]
use bitflags::bitflags;
use crate::input::mouse::MouseButton;
use crate::style::StyleColor;
use crate::sys;
use crate::Ui;
bitflags! {
#[repr(transparent)]
pub struct ItemHoveredFlags: u32 {
const ALLOW_WHEN_BLOCKED_BY_POPUP = sys::ImGuiHoveredFlags_AllowWhenBlockedByPopup;
const ALLOW_WHEN_BLOCKED_BY_ACTIVE_ITEM = sys::ImGuiHoveredFlags_AllowWhenBlockedByActiveItem;
const ALLOW_WHEN_OVERLAPPED = sys::ImGuiHoveredFlags_AllowWhenOverlapped;
const ALLOW_WHEN_DISABLED = sys::ImGuiHoveredFlags_AllowWhenDisabled;
const RECT_ONLY = sys::ImGuiHoveredFlags_RectOnly;
}
}
impl<'ui> Ui<'ui> {
#[doc(alias = "IsItemHovered")]
pub fn is_item_hovered(&self) -> bool {
unsafe { sys::igIsItemHovered(0) }
}
#[doc(alias = "IsItemHovered")]
pub fn is_item_hovered_with_flags(&self, flags: ItemHoveredFlags) -> bool {
unsafe { sys::igIsItemHovered(flags.bits() as i32) }
}
#[doc(alias = "IsItemActive")]
pub fn is_item_active(&self) -> bool {
unsafe { sys::igIsItemActive() }
}
#[doc(alias = "IsItemFocused")]
pub fn is_item_focused(&self) -> bool {
unsafe { sys::igIsItemFocused() }
}
#[doc(alias = "IsItemClicked")]
pub fn is_item_clicked(&self) -> bool {
self.is_item_clicked_with_button(MouseButton::Left)
}
#[doc(alias = "IsItemClicked")]
pub fn is_item_clicked_with_button(&self, button: MouseButton) -> bool {
unsafe { sys::igIsItemClicked(button as i32) }
}
#[doc(alias = "IsItemVisible")]
pub fn is_item_visible(&self) -> bool {
unsafe { sys::igIsItemVisible() }
}
#[doc(alias = "IsItemEdited")]
pub fn is_item_edited(&self) -> bool {
unsafe { sys::igIsItemEdited() }
}
#[doc(alias = "IsItemActivated")]
pub fn is_item_activated(&self) -> bool {
unsafe { sys::igIsItemActivated() }
}
#[doc(alias = "IsItemDeactivated")]
pub fn is_item_deactivated(&self) -> bool {
unsafe { sys::igIsItemDeactivated() }
}
#[doc(alias = "IsItemDeactivatedAfterEdit")]
pub fn is_item_deactivated_after_edit(&self) -> bool {
unsafe { sys::igIsItemDeactivatedAfterEdit() }
}
#[doc(alias = "IsItemToggledOpen")]
pub fn is_item_toggled_open(&self) -> bool {
unsafe { sys::igIsItemToggledOpen() }
}
#[doc(alias = "IsAnyItemHovered")]
pub fn is_any_item_hovered(&self) -> bool {
unsafe { sys::igIsAnyItemHovered() }
}
#[doc(alias = "IsAnyItemActive")]
pub fn is_any_item_active(&self) -> bool {
unsafe { sys::igIsAnyItemActive() }
}
#[doc(alias = "IsAnyItemFocused")]
pub fn is_any_item_focused(&self) -> bool {
unsafe { sys::igIsAnyItemFocused() }
}
#[doc(alias = "GetItemRectMin")]
pub fn item_rect_min(&self) -> [f32; 2] {
let mut out = sys::ImVec2::zero();
unsafe { sys::igGetItemRectMin(&mut out) }
out.into()
}
#[doc(alias = "GetItemRectMax")]
pub fn item_rect_max(&self) -> [f32; 2] {
let mut out = sys::ImVec2::zero();
unsafe { sys::igGetItemRectMax(&mut out) }
out.into()
}
#[doc(alias = "GetItemRectSize")]
pub fn item_rect_size(&self) -> [f32; 2] {
let mut out = sys::ImVec2::zero();
unsafe { sys::igGetItemRectSize(&mut out) }
out.into()
}
#[doc(alias = "SetItemAllowOverlap")]
pub fn set_item_allow_overlap(&self) {
unsafe { sys::igSetItemAllowOverlap() };
}
#[doc(alias = "SetItemDefaultFocus")]
pub fn set_item_default_focus(&self) {
unsafe { sys::igSetItemDefaultFocus() };
}
}
impl<'ui> Ui<'ui> {
#[doc(alias = "IsRectVisibleNil")]
pub fn is_cursor_rect_visible(&self, size: [f32; 2]) -> bool {
unsafe { sys::igIsRectVisible_Nil(size.into()) }
}
#[doc(alias = "IsRectVisibleNilVec2")]
pub fn is_rect_visible(&self, rect_min: [f32; 2], rect_max: [f32; 2]) -> bool {
unsafe { sys::igIsRectVisible_Vec2(rect_min.into(), rect_max.into()) }
}
#[doc(alias = "GetTime")]
pub fn time(&self) -> f64 {
unsafe { sys::igGetTime() }
}
#[doc(alias = "GetFrameCount")]
pub fn frame_count(&self) -> i32 {
unsafe { sys::igGetFrameCount() }
}
#[doc(alias = "GetStyle")]
pub fn style_color(&self, style_color: StyleColor) -> [f32; 4] {
self.ctx.style()[style_color]
}
}