mirror of
				https://github.com/Drezil/imgui.git
				synced 2025-10-31 13:11:05 +01:00 
			
		
		
		
	IsItemHovered(), IsWindowHovered(): added flags to enable various and more specific behavior. Will enable improvements for popups/context menus and drag'n drop. (relate ~#439, #1013, #143, #925)
The legacy confusing IsItemRectHovered(), IsWindowRectHovered() can be completely removed now. Changed IsWindowHovered() behavior with default parameter: it now return false is the window is blocked by a popup. Demo: Added tests for those two functions.
This commit is contained in:
		
							
								
								
									
										23
									
								
								imgui.h
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								imgui.h
									
									
									
									
									
								
							| @@ -80,6 +80,7 @@ typedef int ImGuiColumnsFlags;      // flags: for *Columns*() | ||||
| typedef int ImGuiInputTextFlags;    // flags: for InputText*()                  // enum ImGuiInputTextFlags_ | ||||
| typedef int ImGuiSelectableFlags;   // flags: for Selectable()                  // enum ImGuiSelectableFlags_ | ||||
| typedef int ImGuiTreeNodeFlags;     // flags: for TreeNode*(), Collapsing*()    // enum ImGuiTreeNodeFlags_ | ||||
| typedef int ImGuiHoveredFlags;      // flags: for IsItemHovered()               // enum ImGuiHoveredFlags_ | ||||
| typedef int (*ImGuiTextEditCallback)(ImGuiTextEditCallbackData *data); | ||||
| typedef void (*ImGuiSizeConstraintCallback)(ImGuiSizeConstraintCallbackData* data); | ||||
| #ifdef _MSC_VER | ||||
| @@ -414,8 +415,7 @@ namespace ImGui | ||||
|     IMGUI_API void          StyleColorsClassic(ImGuiStyle* dst = NULL); | ||||
|  | ||||
|     // Utilities | ||||
|     IMGUI_API bool          IsItemHovered();                                                    // is the last item hovered by mouse (and usable)? | ||||
|     IMGUI_API bool          IsItemRectHovered();                                                // is the last item hovered by mouse? even if another item is active or window is blocked by popup while we are hovering this | ||||
|     IMGUI_API bool          IsItemHovered(ImGuiHoveredFlags flags = 0);                         // is the last item hovered by mouse (and usable)? | ||||
|     IMGUI_API bool          IsItemActive();                                                     // is the last item active? (e.g. button being held, text field being edited- items that don't interact will always return false) | ||||
|     IMGUI_API bool          IsItemClicked(int mouse_button = 0);                                // is the last item clicked? (e.g. button/node just clicked on) | ||||
|     IMGUI_API bool          IsItemVisible();                                                    // is the last item visible? (aka not out of sight due to clipping/scrolling.) | ||||
| @@ -426,11 +426,10 @@ namespace ImGui | ||||
|     IMGUI_API ImVec2        GetItemRectSize();                                                  // " | ||||
|     IMGUI_API void          SetItemAllowOverlap();                                              // allow last item to be overlapped by a subsequent item. sometimes useful with invisible buttons, selectables, etc. to catch unused area. | ||||
|     IMGUI_API bool          IsWindowFocused();                                                  // is current window focused | ||||
|     IMGUI_API bool          IsWindowHovered();                                                  // is current window hovered and hoverable (not blocked by a popup) (differentiate child windows from each others) | ||||
|     IMGUI_API bool          IsWindowRectHovered();                                              // is current window rectangle hovered, disregarding of any consideration of being blocked by a popup. (unlike IsWindowHovered() this will return true even if the window is blocked because of a popup) | ||||
|     IMGUI_API bool          IsWindowHovered(ImGuiHoveredFlags flags = 0);                       // is current window hovered (and typically: not blocked by a popup/modal) | ||||
|     IMGUI_API bool          IsRootWindowFocused();                                              // is current root window focused (root = top-most parent of a child, otherwise self) | ||||
|     IMGUI_API bool          IsRootWindowOrAnyChildFocused();                                    // is current root window or any of its child (including current window) focused | ||||
|     IMGUI_API bool          IsRootWindowOrAnyChildHovered();                                    // is current root window or any of its child (including current window) hovered and hoverable (not blocked by a popup) | ||||
|     IMGUI_API bool          IsRootWindowOrAnyChildHovered(ImGuiHoveredFlags flags = 0);         // is current root window or any of its child (including current window) hovered and hoverable (not blocked by a popup) | ||||
|     IMGUI_API bool          IsAnyWindowHovered();                                               // is mouse hovering any visible window | ||||
|     IMGUI_API bool          IsRectVisible(const ImVec2& size);                                  // test if rectangle (of given size, starting from cursor position) is visible / not clipped. | ||||
|     IMGUI_API bool          IsRectVisible(const ImVec2& rect_min, const ImVec2& rect_max);      // test if rectangle (in screen space) is visible / not clipped. to perform coarse clipping on user's side. | ||||
| @@ -569,6 +568,16 @@ enum ImGuiSelectableFlags_ | ||||
|     ImGuiSelectableFlags_AllowDoubleClick   = 1 << 2    // Generate press events on double clicks too | ||||
| }; | ||||
|  | ||||
| enum ImGuiHoveredFlags_ | ||||
| { | ||||
|     ImGuiHoveredFlags_Default                       = 0,        // 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. | ||||
|     ImGuiHoveredFlags_AllowWhenBlockedByPopup       = 1 << 0,   // Return true even if a popup window is normally blocking access to this item/window | ||||
|     //ImGuiHoveredFlags_AllowWhenBlockedByModal     = 1 << 1,   // Return true even if a modal popup window is normally blocking access to this item/window. FIXME-TODO: Unavailable yet. | ||||
|     ImGuiHoveredFlags_AllowWhenBlockedByActiveItem  = 1 << 2,   // Return true even if an active item is blocking access to this item/window | ||||
|     ImGuiHoveredFlags_AllowWhenOverlapped           = 1 << 3,   // Return true even if the position is overlapped by another window | ||||
|     ImGuiHoveredFlags_RectOnly                      = ImGuiHoveredFlags_AllowWhenBlockedByPopup | ImGuiHoveredFlags_AllowWhenBlockedByActiveItem | ImGuiHoveredFlags_AllowWhenOverlapped | ||||
| }; | ||||
|  | ||||
| // User fill ImGuiIO.KeyMap[] array with indices into the ImGuiIO.KeysDown[512] array | ||||
| enum ImGuiKey_ | ||||
| { | ||||
| @@ -881,10 +890,10 @@ namespace ImGui | ||||
|     bool                    Begin(const char* name, bool* p_open, const ImVec2& size_on_first_use, float bg_alpha_override = -1.0f, ImGuiWindowFlags flags = 0); // OBSOLETE 1.52+. use SetNextWindowSize() instead if you want to set a window size. | ||||
|     static inline void      AlignFirstTextHeightToWidgets() { AlignTextToFramePadding(); }     // OBSOLETE 1.52+ | ||||
|     static inline void      SetNextWindowPosCenter(ImGuiCond cond = 0) { SetNextWindowPos(ImVec2(GetIO().DisplaySize.x * 0.5f, GetIO().DisplaySize.y * 0.5f), cond, ImVec2(0.5f, 0.5f)); } // OBSOLETE 1.52+ | ||||
|     static inline bool      IsItemHoveredRect() { return IsItemRectHovered(); }                // OBSOLETE 1.51+ | ||||
|     static inline bool      IsItemHoveredRect() { return IsItemHovered(ImGuiHoveredFlags_RectOnly); } // OBSOLETE 1.51+ | ||||
|     static inline bool      IsPosHoveringAnyWindow(const ImVec2&) { IM_ASSERT(0); return false; } // OBSOLETE 1.51+. This was partly broken. You probably wanted to use ImGui::GetIO().WantCaptureMouse instead. | ||||
|     static inline bool      IsMouseHoveringAnyWindow() { return IsAnyWindowHovered(); }        // OBSOLETE 1.51+ | ||||
|     static inline bool      IsMouseHoveringWindow() { return IsWindowRectHovered(); }          // OBSOLETE 1.51+ | ||||
|     static inline bool      IsMouseHoveringWindow() { return IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup | ImGuiHoveredFlags_AllowWhenBlockedByActiveItem); } // OBSOLETE 1.51+ | ||||
|     static inline bool      CollapsingHeader(const char* label, const char* str_id, bool framed = true, bool default_open = false) { (void)str_id; (void)framed; ImGuiTreeNodeFlags default_open_flags = 1 << 5; return CollapsingHeader(label, (default_open ? default_open_flags : 0)); } // OBSOLETE 1.49+ | ||||
|     static inline ImFont*   GetWindowFont() { return GetFont(); }                              // OBSOLETE 1.48+ | ||||
|     static inline float     GetWindowFontSize() { return GetFontSize(); }                      // OBSOLETE 1.48+ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user