forked from gomatcha/matcha
/
addremove.go
63 lines (55 loc) · 1.21 KB
/
addremove.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
package view
import (
"golang.org/x/image/colornames"
"gomatcha.io/matcha/bridge"
"gomatcha.io/matcha/layout/constraint"
"gomatcha.io/matcha/paint"
"gomatcha.io/matcha/view"
)
func init() {
bridge.RegisterFunc("gomatcha.io/matcha/examples/view NewAddRemoveView", func() view.View {
return NewAddRemoveView()
})
}
type AddRemoveView struct {
view.Embed
showView bool
}
func NewAddRemoveView() *AddRemoveView {
return &AddRemoveView{}
}
func (v *AddRemoveView) Build(ctx view.Context) view.Model {
l := &constraint.Layouter{}
chl1 := view.NewButton()
chl1.Enabled = true
if !v.showView {
chl1.String = "Add"
} else {
chl1.String = "Remove"
}
chl1.PaintStyle = &paint.Style{BackgroundColor: colornames.Red}
chl1.OnPress = func() {
v.showView = !v.showView
v.Signal()
}
_ = l.Add(chl1, func(s *constraint.Solver) {
s.Top(100)
s.Left(0)
s.Width(200)
})
if v.showView {
chl2 := view.NewBasicView()
chl2.Painter = &paint.Style{BackgroundColor: colornames.Green}
l.Add(chl2, func(s *constraint.Solver) {
s.Top(200)
s.Left(0)
s.Width(100)
s.Height(100)
})
}
return view.Model{
Children: l.Views(),
Layouter: l,
Painter: &paint.Style{BackgroundColor: colornames.White},
}
}