/
base.go
62 lines (50 loc) · 1.09 KB
/
base.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
package module
import (
"image/draw"
"github.com/shimmerglass/bar3x/ui"
"github.com/shimmerglass/bar3x/ui/base"
)
type moduleBase struct {
base.Base
Root ui.Drawable
}
func newBase(p ui.ParentDrawable) moduleBase {
return moduleBase{Base: base.NewBase(p)}
}
func (b *moduleBase) SetContext(ctx ui.Context) {
b.Base.SetContext(ctx)
if b.Root != nil {
b.Root.SetContext(ctx)
}
}
func (b *moduleBase) Add(ui.Drawable) {}
func (b *moduleBase) Children() []ui.Drawable {
return []ui.Drawable{b.Root}
}
func (b *moduleBase) ChildContext(int) ui.Context {
return b.Base.Context()
}
func (b *moduleBase) Width() int {
return b.Root.Width()
}
func (b *moduleBase) OnWidthChange(c func(int)) {
b.Root.OnWidthChange(c)
}
func (b *moduleBase) Height() int {
return b.Root.Height()
}
func (b *moduleBase) OnHeightChange(c func(int)) {
b.Root.OnHeightChange(c)
}
func (b *moduleBase) Draw(x, y int, im draw.Image) {
if b.Root == nil {
return
}
b.Root.Draw(x, y, im)
}
func (b *moduleBase) SendEvent(ev ui.Event) bool {
if !b.Base.SendEvent(ev) {
return false
}
return b.Root.SendEvent(ev)
}