-
-
Notifications
You must be signed in to change notification settings - Fork 356
/
stack.go
141 lines (110 loc) · 2.59 KB
/
stack.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package ui
import "github.com/maxence-charriere/go-app/v10/pkg/app"
// IStack is the interface that describes a container that displays its items
// as stacked panels.
type IStack interface {
app.UI
// Sets the ID.
ID(v string) IStack
// Sets the class. Multiple classes can be defined by successive calls.
Class(v string) IStack
// Sets the style. Multiple styles can be defined by successive calls.
Style(k, v string) IStack
// Left aligns the content on the left.
Left() IStack
// Center aligns the content on the horizontal center.
Center() IStack
// Right aligns the content on the right.
Right() IStack
// Top aligns the content on the top.
Top() IStack
// Middle aligns the content on the vertical center.
Middle() IStack
// Bottom aligns the content on the bottom.
Bottom() IStack
// Stretch stretches the content vertically.
Stretch() IStack
// Sets the content.
Content(elems ...app.UI) IStack
}
// Stack creates a container that displays its items as stacked panels.
func Stack() IStack {
return &stack{
IhorizontalAlign: "flex-start",
IverticalAlign: "flex-start",
}
}
type stack struct {
app.Compo
Iid string
Iclass string
IhorizontalAlign string
IverticalAlign string
Istyles []style
Icontent []app.UI
}
func (s *stack) ID(v string) IStack {
s.Iid = v
return s
}
func (s *stack) Class(v string) IStack {
s.Iclass = app.AppendClass(s.Iclass, v)
return s
}
func (s *stack) Style(k, v string) IStack {
if v == "" {
return s
}
s.Istyles = append(s.Istyles, style{
key: k,
value: v,
})
return s
}
func (s *stack) Left() IStack {
s.IhorizontalAlign = "flex-start"
return s
}
func (s *stack) Center() IStack {
s.IhorizontalAlign = "center"
return s
}
func (s *stack) Right() IStack {
s.IhorizontalAlign = "flex-end"
return s
}
func (s *stack) Top() IStack {
s.IverticalAlign = "flex-start"
return s
}
func (s *stack) Middle() IStack {
s.IverticalAlign = "center"
return s
}
func (s *stack) Bottom() IStack {
s.IverticalAlign = "flex-end"
return s
}
func (s *stack) Stretch() IStack {
s.IverticalAlign = "stretch"
return s
}
func (s *stack) Content(elems ...app.UI) IStack {
s.Icontent = app.FilterUIElems(elems...)
return s
}
func (s *stack) OnUpdate(ctx app.Context) {
}
func (s *stack) Render() app.UI {
body := app.Div().
DataSet("goapp", "Stack").
ID(s.Iid).
Class(s.Iclass).
Style("display", "flex").
Style("justify-content", s.IhorizontalAlign).
Style("align-items", s.IverticalAlign)
for _, s := range s.Istyles {
body.Style(s.key, s.value)
}
return body.Body(s.Icontent...)
}