/
column.go
103 lines (95 loc) · 2.69 KB
/
column.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
package gel
import (
l "gioui.org/layout"
)
type ColumnRow struct {
Label string
W l.Widget
}
type Rows []ColumnRow
type Column struct {
*Window
rows []ColumnRow
font string
scale float32
color, background string
list *List
}
func (w *Window) Column(rows Rows, font string, scale float32, color string,
background string) *Column {
return &Column{Window: w, rows: rows, font: font, scale: scale, color: color,
background: background, list: w.List()}
}
func (c *Column) Fn(gtx l.Context) l.Dimensions {
max, list := c.List(gtx)
out := c.Theme.SliceToWidget(list, l.Vertical)
gtx.Constraints.Max.X = max
return out(gtx)
}
func (c *Column) List(gtx l.Context) (max int, out []l.Widget) {
le := func(gtx l.Context, index int) l.Dimensions {
return c.H6(c.rows[index].Label).Font(c.font).TextScale(c.scale).Fn(gtx)
}
// render the widgets onto a second context to get their dimensions
gtx1 := CopyContextDimensionsWithMaxAxis(gtx, l.Vertical)
// generate the dimensions for all the list elements
dims := GetDimensionList(gtx1, len(c.rows), le)
D.S(dims)
for i := range dims {
if dims[i].Size.X > max {
max = dims[i].Size.X
}
}
for x := range c.rows {
i := x
_ = i
out = append(out, func(gtx l.Context) l.Dimensions {
return c.Flex(). // AlignEnd().SpaceStart().
Rigid(
c.Fill("red", l.Center, c.TextSize.V, 0, EmptySpace(max-dims[i].Size.X, dims[i].Size.Y)).Fn,
).
Rigid(
c.Inset(0.5, func(gtx l.Context) l.Dimensions {
// D.Ln("max!", m)
// // gtx.Constraints.Max.X = max
// gtx.Constraints.Max.Y = dims[i].Size.Y
// gtx.Constraints.Min.Y = dims[i].Size.Y
// gtx.Constraints.Min.X = max
// gtx.Constraints.Constrain(image.Point{X: max, Y: dims[i].Size.Y})
// gtx.Constraints.Max.X = max
// gtx.Constraints.Min.Y = 0
// gtx.Constraints.Max.Y = dims[i].Size.Y
// gtx.Constraints.Constrain(dims[i].Size)
dms := c.Label().
Text(c.rows[i].Label).
Font(c.font).
TextScale(c.scale).
Color(c.color).
Fn(gtx)
return dms
}).Fn,
).
Rigid(
c.Inset(0.5,
c.rows[i].W,
).Fn,
).
Fn(gtx)
// return c.Theme.Fill("Primary",
// c.Theme.Flex().AlignEnd().SpaceBetween().
// Rigid(
// ).Fn,
// ).
// Fn(gtx)
})
}
// le = func(gtx l.Context, index int) l.Dimensions {
// return out[index](gtx)
// }
return max, out
// // render the widgets onto a second context to get their dimensions
// gtx1 = CopyContextDimensionsWithMaxAxis(gtx, gtx.Constraints.Max, l.Vertical)
// dim := GetDimension(gtx1, c.Theme.SliceToWidget(out, l.Vertical))
// max = dim.Size.X
// return
}