-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindow.go
97 lines (73 loc) · 1.67 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
86
87
88
89
90
91
92
93
94
95
96
97
package rlyeh
import (
rl "github.com/gen2brain/raylib-go/raylib"
)
type Window struct {
id int32
active bool
bounds rl.Rectangle
widgets []Widget
}
func NewWindow(bounds rl.Rectangle, widgets ...Widget) *Window {
self := &Window{}
self.id = nextId()
self.active = true
self.bounds = bounds
self.widgets = []Widget{}
for _, widget := range widgets {
self.Add(widget)
}
return self
}
func (self *Window) GetBounds() rl.Rectangle {
return self.bounds
}
func (self *Window) SetBounds(bounds rl.Rectangle) {
self.bounds = bounds
}
func (self *Window) Add(widget Widget) {
if 0 == widget.GetId() {
widget.SetId(nextId())
}
self.widgets = append(self.widgets, widget)
}
func (self *Window) Update(dt float32) {
if !self.IsActive() {
return
}
for i := 0; i < len(self.widgets); i++ {
widget := self.widgets[i]
widget.Update(dt)
}
}
func (self *Window) Draw() {
if !self.IsActive() {
return
}
for i := 0; i < len(self.widgets); i++ {
widget := self.widgets[i]
oldBounds := widget.GetBounds()
dataSize := widget.GetDataSize()
newBounds := rl.Rectangle{X: self.bounds.X, Y: self.bounds.Y,
Width: dataSize.Width, Height: dataSize.Height}
newBounds = fillBounds(self.bounds, newBounds, widget.GetFill())
newBounds = alignBounds(self.bounds, newBounds, widget.GetAlign())
newBounds = shrinkBounds(self.bounds, newBounds)
if oldBounds != newBounds {
widget.SetBounds(newBounds)
}
widget.Draw()
}
}
func (self *Window) IsActive() bool {
return self.active
}
func (self *Window) SetActive(value bool) {
self.active = value
}
func (self *Window) IsModal() bool {
return false
}
func (self *Window) IsMovable() bool {
return false
}