...
1 package etk
2
3 import (
4 "image"
5
6 "github.com/hajimehoshi/ebiten/v2"
7 )
8
9
10 type Window struct {
11 *Box
12
13 allChildren []Widget
14
15 active int
16 labels []string
17 hasLabel bool
18 }
19
20 func NewWindow() *Window {
21 return &Window{
22 Box: NewBox(),
23 }
24 }
25
26 func (w *Window) childrenUpdated() {
27 if len(w.allChildren) == 0 {
28 w.children = nil
29 return
30 }
31 w.children = []Widget{w.allChildren[w.active]}
32 }
33
34 func (w *Window) SetRect(r image.Rectangle) {
35 w.Lock()
36 defer w.Unlock()
37
38 w.rect = r
39 for _, wgt := range w.children {
40 wgt.SetRect(r)
41 }
42 }
43
44 func (w *Window) AddChild(wgt ...Widget) {
45 w.allChildren = append(w.allChildren, wgt...)
46
47 for _, widget := range wgt {
48 widget.SetRect(w.rect)
49 }
50
51 blankLabels := make([]string, len(wgt))
52 w.labels = append(w.labels, blankLabels...)
53
54 w.childrenUpdated()
55 }
56
57 func (w *Window) AddChildWithLabel(wgt Widget, label string) {
58 w.Lock()
59 defer w.Unlock()
60
61 wgt.SetRect(w.rect)
62
63 w.allChildren = append(w.allChildren, wgt)
64 w.labels = append(w.labels, label)
65
66 if label != "" {
67 w.hasLabel = true
68 }
69
70 w.childrenUpdated()
71 }
72
73 func (w *Window) HandleMouse(cursor image.Point, pressed bool, clicked bool) (handled bool, err error) {
74 return true, nil
75 }
76
77 func (w *Window) HandleKeyboard() (handled bool, err error) {
78 return true, nil
79 }
80
81 func (w *Window) Draw(screen *ebiten.Image) error {
82
83 return nil
84 }
85
View as plain text