-
-
Notifications
You must be signed in to change notification settings - Fork 135
/
Window.go
85 lines (71 loc) · 1.9 KB
/
Window.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
package giu
import (
"github.com/AllenDang/giu/imgui"
)
func SingleWindow(title string) *WindowWidget {
size := Context.platform.DisplaySize()
return Window(title).
Flags(
imgui.WindowFlagsNoTitleBar|
imgui.WindowFlagsNoCollapse|
imgui.WindowFlagsNoScrollbar|
imgui.WindowFlagsNoMove|
imgui.WindowFlagsNoResize).
Size(size[0], size[1])
}
func SingleWindowWithMenuBar(title string) *WindowWidget {
size := Context.platform.DisplaySize()
return Window(title).
Flags(
imgui.WindowFlagsNoTitleBar|
imgui.WindowFlagsNoCollapse|
imgui.WindowFlagsNoScrollbar|
imgui.WindowFlagsNoMove|
imgui.WindowFlagsMenuBar|
imgui.WindowFlagsNoResize).Size(size[0], size[1])
}
type WindowWidget struct {
title string
open *bool
flags WindowFlags
x, y float32
width, height float32
}
func Window(title string) *WindowWidget {
return &WindowWidget{
title: title,
}
}
func (w *WindowWidget) IsOpen(open *bool) *WindowWidget {
w.open = open
return w
}
func (w *WindowWidget) Flags(flags WindowFlags) *WindowWidget {
w.flags = flags
return w
}
func (w *WindowWidget) Size(width, height float32) *WindowWidget {
w.width, w.height = width, height
return w
}
func (w *WindowWidget) Pos(x, y float32) *WindowWidget {
w.x, w.y = x, y
return w
}
func (w *WindowWidget) Layout(widgets ...Widget) {
if widgets == nil {
return
}
if w.flags&imgui.WindowFlagsNoMove != 0 && w.flags&imgui.WindowFlagsNoResize != 0 {
imgui.SetNextWindowPos(imgui.Vec2{X: w.x, Y: w.y})
imgui.SetNextWindowSize(imgui.Vec2{X: w.width, Y: w.height})
} else {
imgui.SetNextWindowPosV(imgui.Vec2{X: w.x, Y: w.y}, imgui.ConditionFirstUseEver, imgui.Vec2{X: 0, Y: 0})
imgui.SetNextWindowSizeV(imgui.Vec2{X: w.width, Y: w.height}, imgui.ConditionFirstUseEver)
}
showed := imgui.BeginV(w.title, w.open, int(w.flags))
if showed {
Layout(widgets).Build()
}
imgui.End()
}