-
-
Notifications
You must be signed in to change notification settings - Fork 138
/
Popups.go
105 lines (89 loc) · 2.44 KB
/
Popups.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
package giu
import (
"github.com/AllenDang/cimgui-go/imgui"
)
// OpenPopup opens a popup with specified id.
// NOTE: you need to build this popup first (see Pop(Modal)Widget).
func OpenPopup(name string) {
imgui.OpenPopupStr(name)
}
// CloseCurrentPopup closes currently opened popup.
// If no popups opened, no action will be taken.
func CloseCurrentPopup() {
imgui.CloseCurrentPopup()
}
var _ Widget = &PopupWidget{}
// PopupWidget is a window which appears next to the mouse cursor.
// For instance it is used to display color palette in ColorSelectWidget.
type PopupWidget struct {
name string
flags WindowFlags
layout Layout
}
// Popup creates new popup widget.
func Popup(name string) *PopupWidget {
return &PopupWidget{
name: Context.FontAtlas.RegisterString(name),
flags: 0,
layout: nil,
}
}
// Flags sets popup's flags.
func (p *PopupWidget) Flags(flags WindowFlags) *PopupWidget {
p.flags = flags
return p
}
// Layout sets popup's layout.
func (p *PopupWidget) Layout(widgets ...Widget) *PopupWidget {
p.layout = Layout(widgets)
return p
}
// Build implements Widget interface.
func (p *PopupWidget) Build() {
if imgui.BeginPopupV(p.name, imgui.WindowFlags(p.flags)) {
p.layout.Build()
imgui.EndPopup()
}
}
var _ Widget = &PopupModalWidget{}
// PopupModalWidget is a popup window that block every interactions behind it, cannot be closed by
// user, adds a dimming background, has a title bar.
type PopupModalWidget struct {
name string
open *bool
flags WindowFlags
layout Layout
}
// PopupModal creates new popup modal widget.
func PopupModal(name string) *PopupModalWidget {
return &PopupModalWidget{
name: Context.FontAtlas.RegisterString(name),
open: nil,
flags: WindowFlagsNoResize,
layout: nil,
}
}
// IsOpen allows to control popup's state
// NOTE: changing opens' value will not result in changing popup's state
// if OpenPopup(...) wasn't called!
func (p *PopupModalWidget) IsOpen(open *bool) *PopupModalWidget {
p.open = open
return p
}
// Flags allows to specify popup's flags.
func (p *PopupModalWidget) Flags(flags WindowFlags) *PopupModalWidget {
p.flags = flags
return p
}
// Layout sets layout.
func (p *PopupModalWidget) Layout(widgets ...Widget) *PopupModalWidget {
p.layout = Layout(widgets)
return p
}
// Build implements Widget interface.
func (p *PopupModalWidget) Build() {
if imgui.BeginPopupModalV(p.name, p.open, imgui.WindowFlags(p.flags)) {
p.layout.Build()
imgui.EndPopup()
}
}