-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwidgets.query.go
166 lines (143 loc) · 7.15 KB
/
widgets.query.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package imgui
// Item/Widgets Utilities and Query Functions
// - Most of the functions are referring to the previous Item that has been submitted.
// - See Demo Window under "Widgets->Querying Status" for an interactive visualization of most of those functions.
// IsItemHovered is the last item hovered? (and usable, aka not blocked by a popup, etc.). See ImGuiHoveredFlags for more options.
// This is roughly matching the behavior of internal-facing ItemHoverable()
// - we allow hovering to be true when ActiveId==window.MoveID, so that clicking on non-interactive items such as a Text() item still returns true with IsItemHovered()
// - this should work even for non-interactive items that have no ID, so we cannot use LastItemId
func IsItemHovered(flags ImGuiHoveredFlags) bool {
var g = GImGui
var window = g.CurrentWindow
if g.NavDisableMouseHover && !g.NavDisableHighlight {
if (g.LastItemData.InFlags&ImGuiItemFlags_Disabled != 0) && (flags&ImGuiHoveredFlags_AllowWhenDisabled == 0) {
return false
}
return IsItemFocused()
}
// Test for bounding box overlap, as updated as ItemAdd()
var status_flags = g.LastItemData.StatusFlags
if status_flags&ImGuiItemStatusFlags_HoveredRect == 0 {
return false
}
IM_ASSERT((flags & (ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows)) == 0) // Flags not supported by this function
// Test if we are hovering the right window (our window could be behind another window)
// [2021/03/02] Reworked / reverted the revert, finally. Note we want e.g. BeginGroup/ItemAdd/EndGroup to work as well. (#3851)
// [2017/10/16] Reverted commit 344d48be3 and testing RootWindow instead. I believe it is correct to NOT test for RootWindow but this leaves us unable
// to use IsItemHovered() after EndChild() itself. Until a solution is found I believe reverting to the test from 2017/09/27 is safe since this was
// the test that has been running for a long while.
if g.HoveredWindow != window && (status_flags&ImGuiItemStatusFlags_HoveredWindow) == 0 {
if (flags & ImGuiHoveredFlags_AllowWhenOverlapped) == 0 {
return false
}
}
// Test if another item is active (e.g. being dragged)
if (flags & ImGuiHoveredFlags_AllowWhenBlockedByActiveItem) == 0 {
if g.ActiveId != 0 && g.ActiveId != g.LastItemData.ID && !g.ActiveIdAllowOverlap && g.ActiveId != window.MoveId {
return false
}
}
// Test if interactions on this window are blocked by an active popup or modal.
// The ImGuiHoveredFlags_AllowWhenBlockedByPopup flag will be tested here.
if !IsWindowContentHoverable(window, flags) {
return false
}
// Test if the item is disabled
if (g.LastItemData.InFlags&ImGuiItemFlags_Disabled != 0) && (flags&ImGuiHoveredFlags_AllowWhenDisabled == 0) {
return false
}
// Special handling for calling after Begin() which represent the title bar or tab.
// When the window is collapsed (SkipItems==true) that last item will never be overwritten so we need to detect the case.
return g.LastItemData.ID == window.MoveId && window.WriteAccessed
}
// IsItemFocused is the last item focused for keyboard/gamepad navigation?
// == GetItemID() == GetFocusID()
func IsItemFocused() bool {
var g = GImGui
return !(g.NavId != g.LastItemData.ID || g.NavId == 0)
}
// IsItemClicked is the last item hovered and mouse clicked on? (**) == IsMouseClicked(mouse_button) && IsItemHovered()Important. (**) this it NOT equivalent to the behavior of e.g. Button(). Read comments in function definition.
// Important: this can be useful but it is NOT equivalent to the behavior of e.g.Button()!
// Most widgets have specific reactions based on mouse-up/down state, mouse position etc.
func IsItemClicked(mouse_button ImGuiMouseButton) bool {
return IsMouseClicked(mouse_button, false) && IsItemHovered(ImGuiHoveredFlags_None)
}
// IsItemVisible is the last item visible? (items may be out of sight because of clipping/scrolling)
func IsItemVisible() bool {
var g = GImGui
return g.CurrentWindow.ClipRect.Overlaps(g.LastItemData.Rect)
}
// IsItemEdited did the last item modify its underlying value this frame? or was pressed? This is generally the same as the "bool" return value of many widgets.
func IsItemEdited() bool {
var g = GImGui
return (g.LastItemData.StatusFlags & ImGuiItemStatusFlags_Edited) != 0
}
// IsItemActivated was the last item just made active (item was previously inactive).
func IsItemActivated() bool {
var g = GImGui
if g.ActiveId != 0 {
return g.ActiveId == g.LastItemData.ID && g.ActiveIdPreviousFrame != g.LastItemData.ID
}
return false
}
// IsItemDeactivated was the last item just made inactive (item was previously active). Useful for Undo/Redo patterns with widgets that requires continuous editing.
func IsItemDeactivated() bool {
var g = GImGui
if g.LastItemData.StatusFlags&ImGuiItemStatusFlags_HasDeactivated != 0 {
return (g.LastItemData.StatusFlags & ImGuiItemStatusFlags_Deactivated) != 0
}
return g.ActiveIdPreviousFrame == g.LastItemData.ID && g.ActiveIdPreviousFrame != 0 && g.ActiveId != g.LastItemData.ID
}
// IsItemDeactivatedAfterEdit was the last item just made inactive and made a value change when it was active? (e.g. Slider/Drag moved). Useful for Undo/Redo patterns with widgets that requires continuous editing. Note that you may get false positives (some widgets such as Combo()/ListBox()/Selectable() will return true even when clicking an already selected item).
func IsItemDeactivatedAfterEdit() bool {
var g = GImGui
return IsItemDeactivated() && (g.ActiveIdPreviousFrameHasBeenEditedBefore || (g.ActiveId == 0 && g.ActiveIdHasBeenEditedBefore))
}
// IsItemToggledOpen was the last item open state toggled? set by TreeNode().
func IsItemToggledOpen() bool {
var g = GImGui
return (g.LastItemData.StatusFlags & ImGuiItemStatusFlags_ToggledOpen) != 0
}
// IsAnyItemHovered is any item hovered?
func IsAnyItemHovered() bool {
var g = GImGui
return g.HoveredId != 0 || g.HoveredIdPreviousFrame != 0
}
// IsAnyItemActive is any item active?
func IsAnyItemActive() bool {
var g = GImGui
return g.ActiveId != 0
}
// IsAnyItemFocused is any item focused?
func IsAnyItemFocused() bool {
var g = GImGui
return g.NavId != 0 && !g.NavDisableHighlight
}
// GetItemRectMin get upper-left bounding rectangle of the last item (screen space)
func GetItemRectMin() ImVec2 {
var g = GImGui
return g.LastItemData.Rect.Min
}
// GetItemRectMax get lower-right bounding rectangle of the last item (screen space)
func GetItemRectMax() ImVec2 {
var g = GImGui
return g.LastItemData.Rect.Max
}
// GetItemRectSize get size of last item
func GetItemRectSize() ImVec2 {
var g = GImGui
return g.LastItemData.Rect.GetSize()
}
// SetItemAllowOverlap allow last item to be overlapped by a subsequent item. sometimes useful with invisible buttons, selectables, etc. to catch unused area.
// Allow last item to be overlapped by a subsequent item. Both may be activated during the same frame before the later one takes priority.
// FIXME: Although this is exposed, its interaction and ideal idiom with using ImGuiButtonFlags_AllowItemOverlap flag are extremely confusing, need rework.
func SetItemAllowOverlap() {
var g = GImGui
var id = g.LastItemData.ID
if g.HoveredId == id {
g.HoveredIdAllowOverlap = true
}
if g.ActiveId == id {
g.ActiveIdAllowOverlap = true
}
}