forked from gomatcha/matcha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
statusbar.go
76 lines (67 loc) · 1.44 KB
/
statusbar.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
package android
import (
"image/color"
"golang.org/x/image/colornames"
"gomatcha.io/matcha/bridge"
"gomatcha.io/matcha/layout/constraint"
"gomatcha.io/matcha/paint"
"gomatcha.io/matcha/view"
"gomatcha.io/matcha/view/android"
)
func init() {
bridge.RegisterFunc("gomatcha.io/matcha/examples/android NewStatusBarView", func() view.View {
return NewStatusBarView()
})
}
type StatusBarView struct {
view.Embed
color color.Color
style android.StatusBarStyle
}
func NewStatusBarView() *StatusBarView {
return &StatusBarView{}
}
func (v *StatusBarView) Build(ctx view.Context) view.Model {
l := &constraint.Layouter{}
chl1 := view.NewButton()
chl1.String = "Toggle Color"
chl1.OnPress = func() {
if v.color == colornames.Red {
v.color = colornames.White
} else {
v.color = colornames.Red
}
v.Signal()
}
l.Add(chl1, func(s *constraint.Solver) {
s.Top(100)
s.Left(100)
s.Width(200)
})
chl2 := view.NewButton()
chl2.String = "Toggle Style"
chl2.OnPress = func() {
if v.style == android.StatusBarStyleLight {
v.style = android.StatusBarStyleDark
} else {
v.style = android.StatusBarStyleLight
}
v.Signal()
}
l.Add(chl2, func(s *constraint.Solver) {
s.Top(200)
s.Left(100)
s.Width(200)
})
return view.Model{
Children: l.Views(),
Layouter: l,
Painter: &paint.Style{BackgroundColor: colornames.White},
Options: []view.Option{
&android.StatusBar{
Color: v.color,
Style: v.style,
},
},
}
}