This repository has been archived by the owner on Dec 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 101
/
Popup.go
155 lines (134 loc) · 6.82 KB
/
Popup.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
package imgui
// #include "wrapper/Popup.h"
import "C"
// PopupFlags Flags for OpenPopup*(), BeginPopupContext*(), IsPopupOpen() functions.
// - To be backward compatible with older API which took an 'int mouse_button = 1' argument, we need to treat
// small flags values as a mouse button index, so we encode the mouse button in the first few bits of the flags.
// It is therefore guaranteed to be legal to pass a mouse button index in ImGuiPopupFlags.
// - For the same reason, we exceptionally default the ImGuiPopupFlags argument of BeginPopupContextXXX functions to 1 instead of 0.
// IMPORTANT: because the default parameter is 1 (==ImGuiPopupFlags_MouseButtonRight), if you rely on the default parameter
// and want to another another flag, you need to pass in the ImGuiPopupFlags_MouseButtonRight flag.
// - Multiple buttons currently cannot be combined/or-ed in those functions (we could allow it later).
type PopupFlags int
const (
// PopupFlagsNone no popup flags apply.
PopupFlagsNone PopupFlags = 0
// PopupFlagsMouseButtonLeft For BeginPopupContext*(): open on Left Mouse release. Guaranteed to always be == 0 (same as ImGuiMouseButton_Left).
PopupFlagsMouseButtonLeft PopupFlags = 0
// PopupFlagsMouseButtonRight For BeginPopupContext*(): open on Right Mouse release. Guaranteed to always be == 1 (same as ImGuiMouseButton_Right).
PopupFlagsMouseButtonRight PopupFlags = 1
// PopupFlagsMouseButtonMiddle For BeginPopupContext*(): open on Middle Mouse release. Guaranteed to always be == 2 (same as ImGuiMouseButton_Middle).
PopupFlagsMouseButtonMiddle PopupFlags = 2
// PopupFlagsNoOpenOverExistingPopup For OpenPopup*(), BeginPopupContext*(): don't open if there's already a popup at the same level of the popup stack.
PopupFlagsNoOpenOverExistingPopup PopupFlags = 1 << 5
// PopupFlagsNoOpenOverItems For BeginPopupContextWindow(): don't return true when hovering items, only when hovering empty space.
PopupFlagsNoOpenOverItems PopupFlags = 1 << 6
// PopupFlagsAnyPopupID For IsPopupOpen(): ignore the ImGuiID parameter and test for any popup.
PopupFlagsAnyPopupID PopupFlags = 1 << 7
// PopupFlagsAnyPopupLevel For IsPopupOpen(): search/test at any level of the popup stack (default test in the current level).
PopupFlagsAnyPopupLevel PopupFlags = 1 << 8
// PopupFlagsAnyPopup for any usage.
PopupFlagsAnyPopup = PopupFlagsAnyPopupID | PopupFlagsAnyPopupLevel
)
// BeginPopupV returns true if the popup is open, and you can start outputting to it.
// Only call EndPopup() if BeginPopup() returns true.
// WindowFlags are forwarded to the window.
func BeginPopupV(name string, flags WindowFlags) bool {
nameArg, nameFin := wrapString(name)
defer nameFin()
return C.iggBeginPopup(nameArg, C.int(flags)) != 0
}
// BeginPopup calls BeginPopupV(name, nil, 0).
func BeginPopup(name string) bool {
return BeginPopupV(name, 0)
}
// BeginPopupModalV creates modal dialog (regular window with title bar, block interactions behind the modal window,
// can't close the modal window by clicking outside).
// WindowFlags are forwarded to the window.
func BeginPopupModalV(name string, open *bool, flags WindowFlags) bool {
nameArg, nameFin := wrapString(name)
defer nameFin()
openArg, openFin := wrapBool(open)
defer openFin()
return C.iggBeginPopupModal(nameArg, openArg, C.int(flags)) != 0
}
// BeginPopupModal calls BeginPopupModalV(name, nil, 0).
func BeginPopupModal(name string) bool {
return BeginPopupModalV(name, nil, 0)
}
// EndPopup finishes a popup. Only call EndPopup() if BeginPopupXXX() returns true!
func EndPopup() {
C.iggEndPopup()
}
// OpenPopupV marks popup as open (don't call every frame!).
// Popups are closed when user click outside, or if CloseCurrentPopup() is called within a BeginPopup()/EndPopup() block.
// By default, Selectable()/MenuItem() are calling CloseCurrentPopup().
// Popup identifiers are relative to the current ID-stack (so OpenPopup and BeginPopup needs to be at the same level).
func OpenPopupV(id string, flags PopupFlags) {
idArg, idFin := wrapString(id)
defer idFin()
C.iggOpenPopup(idArg, C.int(flags))
}
// OpenPopup calls OpenPopupV(id, 0).
func OpenPopup(id string) {
OpenPopupV(id, 0)
}
// OpenPopupOnItemClickV helper to open popup when clicked on last item. return true when just opened. (note: actually triggers on the mouse _released_ event to be consistent with popup behaviors).
func OpenPopupOnItemClickV(id string, flags PopupFlags) {
idArg, idFin := wrapString(id)
defer idFin()
C.iggOpenPopupOnItemClick(idArg, C.int(flags))
}
// OpenPopupOnItemClick calls OpenPopupOnItemClickV("", PopupFlagsMouseButtonRight).
func OpenPopupOnItemClick() {
OpenPopupOnItemClickV("", PopupFlagsMouseButtonRight)
}
// CloseCurrentPopup closes the popup we have begin-ed into.
// Clicking on a MenuItem or Selectable automatically close the current popup.
func CloseCurrentPopup() {
C.iggCloseCurrentPopup()
}
// BeginPopupContextItemV returns true if the identified mouse button was pressed
// while hovering over the last item.
func BeginPopupContextItemV(id string, flags PopupFlags) bool {
idArg, idFin := wrapString(id)
defer idFin()
return C.iggBeginPopupContextItem(idArg, C.int(flags)) != 0
}
// BeginPopupContextItem calls BeginPopupContextItemV("", PopupFlagsMouseButtonRight).
func BeginPopupContextItem() bool {
return BeginPopupContextItemV("", PopupFlagsMouseButtonRight)
}
// BeginPopupContextWindowV open+begin popup when clicked on current window.
func BeginPopupContextWindowV(id string, flags PopupFlags) bool {
idArg, idFin := wrapString(id)
defer idFin()
return C.iggBeginPopupContextWindow(idArg, C.int(flags)) != 0
}
// BeginPopupContextWindow calls BeginPopupContextWindowV("", PopupFlagsMouseButtonRight).
func BeginPopupContextWindow() bool {
return BeginPopupContextWindowV("", PopupFlagsMouseButtonRight)
}
// BeginPopupContextVoidV open+begin popup when clicked in void (where there are no windows).
func BeginPopupContextVoidV(id string, flags PopupFlags) bool {
idArg, idFin := wrapString(id)
defer idFin()
return C.iggBeginPopupContextVoid(idArg, C.int(flags)) != 0
}
// BeginPopupContextVoid calls BeginPopupContextVoidV("", PopupFlagsMouseButtonRight).
func BeginPopupContextVoid() bool {
return BeginPopupContextVoidV("", PopupFlagsMouseButtonRight)
}
// IsPopupOpenV return true if the popup is open.
// IsPopupOpenV(id, PopupFlagsNone): return true if the popup is open at the current BeginPopup() level of the popup stack.
// IsPopupOpenV(id, PopupFlagsAnyPopupID: return true if any popup is open at the current BeginPopup() level of the popup stack.
// IsPopupOpenV(id, PopupFlagsAnyPopup): return true if any popup is open.
func IsPopupOpenV(id string, flags PopupFlags) bool {
idArg, idFin := wrapString(id)
defer idFin()
return C.iggIsPopupOpen(idArg, C.int(flags)) != 0
}
// IsPopupOpen calls IsPopupOpenV(id, PopupFlagsNone).
func IsPopupOpen(id string) bool {
return IsPopupOpenV(id, PopupFlagsNone)
}