Skip to main content

dear_imgui_rs/utils/
hover_flags.rs

1use crate::sys;
2use bitflags::bitflags;
3
4bitflags! {
5    /// Flags accepted by `Ui::is_window_hovered_with_flags()`.
6    #[repr(transparent)]
7    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8    pub struct WindowHoveredFlags: i32 {
9        /// Return true if directly over the item/window, not obstructed by another window, not obstructed by an active popup or modal blocking inputs under them.
10        const NONE = sys::ImGuiHoveredFlags_None as i32;
11        /// IsWindowHovered() only: Return true if any children of the window is hovered
12        const CHILD_WINDOWS = sys::ImGuiHoveredFlags_ChildWindows as i32;
13        /// IsWindowHovered() only: Test from root window (top most parent of the current hierarchy)
14        const ROOT_WINDOW = sys::ImGuiHoveredFlags_RootWindow as i32;
15        /// IsWindowHovered() only: Return true if any window is hovered
16        const ANY_WINDOW = sys::ImGuiHoveredFlags_AnyWindow as i32;
17        /// IsWindowHovered() only: Do not consider popup hierarchy (do not treat popup emitter as parent of popup) (when used with _ChildWindows or _RootWindow)
18        const NO_POPUP_HIERARCHY = sys::ImGuiHoveredFlags_NoPopupHierarchy as i32;
19        /// IsWindowHovered() only: Consider docking hierarchy (treat dockspace host as parent of docked window) (when used with _ChildWindows or _RootWindow)
20        const DOCK_HIERARCHY = sys::ImGuiHoveredFlags_DockHierarchy as i32;
21        /// Return true even if a popup window is normally blocking access to this item/window
22        const ALLOW_WHEN_BLOCKED_BY_POPUP = sys::ImGuiHoveredFlags_AllowWhenBlockedByPopup as i32;
23        /// Return true even if an active item is blocking access to this item/window. Useful for Drag and Drop patterns.
24        const ALLOW_WHEN_BLOCKED_BY_ACTIVE_ITEM = sys::ImGuiHoveredFlags_AllowWhenBlockedByActiveItem as i32;
25        /// IsWindowHovered() only: Shortcut for `ROOT_WINDOW | CHILD_WINDOWS`.
26        const ROOT_AND_CHILD_WINDOWS = sys::ImGuiHoveredFlags_RootAndChildWindows as i32;
27        /// Shortcut for standard flags when using IsWindowHovered() + tooltip-style hover behavior.
28        const FOR_TOOLTIP = sys::ImGuiHoveredFlags_ForTooltip as i32;
29        /// Require mouse to be stationary for style.HoverStationaryDelay (~0.15 sec) at least one time.
30        const STATIONARY = sys::ImGuiHoveredFlags_Stationary as i32;
31    }
32}
33
34impl Default for WindowHoveredFlags {
35    fn default() -> Self {
36        WindowHoveredFlags::NONE
37    }
38}
39
40bitflags! {
41    /// Flags accepted by `Ui::is_item_hovered_with_flags()`.
42    #[repr(transparent)]
43    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
44    pub struct ItemHoveredFlags: i32 {
45        /// Return true if directly over the item, not obstructed by another window, not obstructed by an active popup or modal blocking inputs under it.
46        const NONE = sys::ImGuiHoveredFlags_None as i32;
47        /// Return true even if a popup window is normally blocking access to this item/window
48        const ALLOW_WHEN_BLOCKED_BY_POPUP = sys::ImGuiHoveredFlags_AllowWhenBlockedByPopup as i32;
49        /// Return true even if an active item is blocking access to this item/window. Useful for Drag and Drop patterns.
50        const ALLOW_WHEN_BLOCKED_BY_ACTIVE_ITEM = sys::ImGuiHoveredFlags_AllowWhenBlockedByActiveItem as i32;
51        /// IsItemHovered() only: Return true even if the item uses AllowOverlap mode and is overlapped by another hoverable item.
52        const ALLOW_WHEN_OVERLAPPED_BY_ITEM = sys::ImGuiHoveredFlags_AllowWhenOverlappedByItem as i32;
53        /// IsItemHovered() only: Return true even if the item position is overlapped by another window.
54        const ALLOW_WHEN_OVERLAPPED_BY_WINDOW = sys::ImGuiHoveredFlags_AllowWhenOverlappedByWindow as i32;
55        /// IsItemHovered() only: Return true even if the position is obstructed or overlapped by another window
56        const ALLOW_WHEN_OVERLAPPED = sys::ImGuiHoveredFlags_AllowWhenOverlapped as i32;
57        /// IsItemHovered() only: Return true even if the item is disabled
58        const ALLOW_WHEN_DISABLED = sys::ImGuiHoveredFlags_AllowWhenDisabled as i32;
59        /// IsItemHovered() only: Disable using gamepad/keyboard navigation state when active, always query mouse.
60        const NO_NAV_OVERRIDE = sys::ImGuiHoveredFlags_NoNavOverride as i32;
61        /// IsItemHovered() only: test rectangle visibility with popup/active-item/overlap bypasses.
62        const RECT_ONLY = sys::ImGuiHoveredFlags_RectOnly as i32;
63        /// Shortcut for standard flags when using IsItemHovered() + SetTooltip() sequence.
64        const FOR_TOOLTIP = sys::ImGuiHoveredFlags_ForTooltip as i32;
65        /// Require mouse to be stationary for style.HoverStationaryDelay (~0.15 sec) _at least one time_. After this, can move on same item/window. Using the stationary test tends to reduces the need for a long delay.
66        const STATIONARY = sys::ImGuiHoveredFlags_Stationary as i32;
67        /// IsItemHovered() only: Return true immediately (default). As opposed to IsItemHovered() returning true only after style.HoverDelayNormal elapsed (~0.30 sec)
68        const DELAY_NONE = sys::ImGuiHoveredFlags_DelayNone as i32;
69        /// IsItemHovered() only: Return true after style.HoverDelayShort elapsed (~0.10 sec)
70        const DELAY_SHORT = sys::ImGuiHoveredFlags_DelayShort as i32;
71        /// IsItemHovered() only: Return true after style.HoverDelayNormal elapsed (~0.30 sec)
72        const DELAY_NORMAL = sys::ImGuiHoveredFlags_DelayNormal as i32;
73        /// IsItemHovered() only: Disable shared delay system where moving from one item to a neighboring item keeps the previous timer for a short time (standard for tooltips with long delays)
74        const NO_SHARED_DELAY = sys::ImGuiHoveredFlags_NoSharedDelay as i32;
75    }
76}
77
78impl Default for ItemHoveredFlags {
79    fn default() -> Self {
80        ItemHoveredFlags::NONE
81    }
82}
83
84bitflags! {
85    /// Flags stored in style tooltip hover defaults.
86    ///
87    /// This is the item-hover subset that can be expanded by
88    /// `ItemHoveredFlags::FOR_TOOLTIP`; it intentionally excludes `FOR_TOOLTIP`
89    /// itself to avoid recursive tooltip-style storage.
90    #[repr(transparent)]
91    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
92    pub struct TooltipHoveredFlags: i32 {
93        /// No flags
94        const NONE = sys::ImGuiHoveredFlags_None as i32;
95        /// Return true even if a popup window is normally blocking access to this item/window
96        const ALLOW_WHEN_BLOCKED_BY_POPUP = sys::ImGuiHoveredFlags_AllowWhenBlockedByPopup as i32;
97        /// Return true even if an active item is blocking access to this item/window. Useful for Drag and Drop patterns.
98        const ALLOW_WHEN_BLOCKED_BY_ACTIVE_ITEM = sys::ImGuiHoveredFlags_AllowWhenBlockedByActiveItem as i32;
99        /// Return true even if the item uses AllowOverlap mode and is overlapped by another hoverable item.
100        const ALLOW_WHEN_OVERLAPPED_BY_ITEM = sys::ImGuiHoveredFlags_AllowWhenOverlappedByItem as i32;
101        /// Return true even if the item position is overlapped by another window.
102        const ALLOW_WHEN_OVERLAPPED_BY_WINDOW = sys::ImGuiHoveredFlags_AllowWhenOverlappedByWindow as i32;
103        /// Return true even if the position is obstructed or overlapped by another window.
104        const ALLOW_WHEN_OVERLAPPED = sys::ImGuiHoveredFlags_AllowWhenOverlapped as i32;
105        /// Return true even if the item is disabled.
106        const ALLOW_WHEN_DISABLED = sys::ImGuiHoveredFlags_AllowWhenDisabled as i32;
107        /// Disable using gamepad/keyboard navigation state when active, always query mouse.
108        const NO_NAV_OVERRIDE = sys::ImGuiHoveredFlags_NoNavOverride as i32;
109        /// Test rectangle visibility with popup/active-item/overlap bypasses.
110        const RECT_ONLY = sys::ImGuiHoveredFlags_RectOnly as i32;
111        /// Require mouse to be stationary for style.HoverStationaryDelay at least one time.
112        const STATIONARY = sys::ImGuiHoveredFlags_Stationary as i32;
113        /// Return true immediately.
114        const DELAY_NONE = sys::ImGuiHoveredFlags_DelayNone as i32;
115        /// Return true after style.HoverDelayShort elapsed.
116        const DELAY_SHORT = sys::ImGuiHoveredFlags_DelayShort as i32;
117        /// Return true after style.HoverDelayNormal elapsed.
118        const DELAY_NORMAL = sys::ImGuiHoveredFlags_DelayNormal as i32;
119        /// Disable shared delay system where moving between items preserves the previous timer.
120        const NO_SHARED_DELAY = sys::ImGuiHoveredFlags_NoSharedDelay as i32;
121    }
122}
123
124impl Default for TooltipHoveredFlags {
125    fn default() -> Self {
126        TooltipHoveredFlags::NONE
127    }
128}
129
130pub(crate) fn validate_window_hovered_flags(caller: &str, flags: WindowHoveredFlags) {
131    let unsupported = flags.bits() & !WindowHoveredFlags::all().bits();
132    assert!(
133        unsupported == 0,
134        "{caller} received unsupported ImGuiHoveredFlags window bits: 0x{unsupported:X}"
135    );
136}
137
138pub(crate) fn validate_item_hovered_flags(caller: &str, flags: ItemHoveredFlags) {
139    let unsupported = flags.bits() & !ItemHoveredFlags::all().bits();
140    assert!(
141        unsupported == 0,
142        "{caller} received unsupported ImGuiHoveredFlags item bits: 0x{unsupported:X}"
143    );
144}
145
146pub(crate) fn validate_tooltip_hovered_flags(caller: &str, flags: TooltipHoveredFlags) {
147    let unsupported = flags.bits() & !TooltipHoveredFlags::all().bits();
148    assert!(
149        unsupported == 0,
150        "{caller} received unsupported ImGuiHoveredFlags tooltip bits: 0x{unsupported:X}"
151    );
152}