-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.go
166 lines (131 loc) · 2.51 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
156
157
158
159
160
161
162
163
164
165
166
package gig
import (
"strconv"
"github.com/leonsal/gig/imgui"
)
type Popup struct {
Widget
strId imgui.CString
flags imgui.WindowFlags
popupFlags imgui.PopupFlags
open bool
}
func NewPopup() *Popup {
p := new(Popup)
p.Init(p)
p.strId.SetString(strconv.Itoa(p.ID()))
p.SetRender(func() {
if p.open {
imgui.OpenPopupCS(p.strId, p.popupFlags)
p.open = false
}
if imgui.BeginPopupCS(p.strId, p.flags) {
p.RenderChildren()
imgui.EndPopup()
}
})
return p
}
func (p *Popup) Save(pp **Popup) *Popup {
*pp = p
return p
}
func (p *Popup) SetFlags(flags imgui.WindowFlags) *Popup {
p.flags = flags
return p
}
func (p *Popup) SetPopupFlags(flags imgui.PopupFlags) *Popup {
p.popupFlags = flags
return p
}
func (p *Popup) Open() *Popup {
p.open = true
return p
}
func CloseCurrentPopup() {
imgui.CloseCurrentPopup()
}
type PopupModal struct {
Widget
title imgui.CString
flags imgui.WindowFlags
popupFlags imgui.PopupFlags
size imgui.Vec2
sizeCond imgui.Cond
doOpen bool
doClose bool
open bool
popen *bool
}
func NewPopupModal(name string) *PopupModal {
p := new(PopupModal)
p.Init(p, name)
return p
}
func (p *PopupModal) Init(control IWidget, name string) {
p.Widget.Init(control)
p.title.SetString(name)
p.SetRender(func() {
if p.doOpen {
imgui.OpenPopupCS(p.title, p.popupFlags)
p.doOpen = false
}
if p.size.X != 0 && p.size.Y != 0 {
imgui.SetNextWindowSize(p.size, p.sizeCond)
}
if imgui.BeginPopupModalCS(p.title, p.popen, p.flags) {
if p.doClose {
imgui.CloseCurrentPopup()
p.doClose = false
}
p.RenderChildren()
imgui.EndPopup()
}
if p.popen != nil && p.open == false {
p.open = true
}
})
}
func (p *PopupModal) Save(pp **PopupModal) *PopupModal {
*pp = p
return p
}
func (p *PopupModal) SetTitle(title string) *PopupModal {
p.title.SetString(title)
return p
}
func (p *PopupModal) SetSize(size imgui.Vec2, cond imgui.Cond) *PopupModal {
p.size = size
p.sizeCond = cond
return p
}
func (p *PopupModal) SetCanClose(canclose bool) *PopupModal {
if canclose {
p.open = true
p.popen = &p.open
} else {
p.popen = nil
}
return p
}
func (p *PopupModal) Open() *PopupModal {
p.doOpen = true
return p
}
func (p *PopupModal) Close() *PopupModal {
p.doClose = true
return p
}
type Tooltip struct {
Widget
}
func NewToolTip() *Tooltip {
t := new(Tooltip)
t.Init(t)
t.SetRender(func() {
imgui.BeginTooltip()
t.RenderChildren()
imgui.EndTooltip()
})
return t
}