-
Notifications
You must be signed in to change notification settings - Fork 103
/
column.go
91 lines (84 loc) · 2.73 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
package render
import (
"image"
"github.com/tidbyt/gg"
)
// Column lays out and draws its children vertically (in a column).
//
// By default, a Column is as small as possible, while still holding
// all its children. However, if `expanded` is set, the Column will
// fill all available space vertically. The width of a Column is
// always that of its widest child.
//
// Alignment along the vertical main axis is controlled by passing
// one of the following `main_align` values:
// - `"start"`: place children at the beginning of the column
// - `"end"`: place children at the end of the column
// - `"center"`: place children in the middle of the column
// - `"space_between"`: place equal space between children
// - `"space_evenly"`: equal space between children and before/after first/last child
// - `"space_around"`: equal space between children, and half of that before/after first/last child
//
// Alignment along the horizontal cross axis is controlled by passing
// one of the following `cross_align` values:
// - `"start"`: place children at the left
// - `"end"`: place children at the right
// - `"center"`: place children in the center
//
// DOC(Children): Child widgets to lay out
// DOC(Expanded): Column should expand to fill all available vertical space
// DOC(MainAlign): Alignment along vertical main axis
// DOC(CrossAlign): Alignment along horizontal cross axis
//
// EXAMPLE BEGIN
// render.Column(
// children=[
// render.Box(width=10, height=8, color="#a00"),
// render.Box(width=14, height=6, color="#0a0"),
// render.Box(width=16, height=4, color="#00a"),
// ],
// )
// EXAMPLE END
//
// EXAMPLE BEGIN
// render.Column(
// expanded=True,
// main_align="space_around",
// cross_align="center",
// children=[
// render.Box(width=10, height=8, color="#a00"),
// render.Box(width=14, height=6, color="#0a0"),
// render.Box(width=16, height=4, color="#00a"),
// ],
// )
// EXAMPLE END
type Column struct {
Widget
Children []Widget `starlark:"children,required"`
MainAlign string `starlark:"main_align"`
CrossAlign string `starlark:"cross_align"`
Expanded bool
}
func (c Column) PaintBounds(bounds image.Rectangle, frameIdx int) image.Rectangle {
v := Vector{
Vertical: true,
Children: c.Children,
MainAlign: c.MainAlign,
CrossAlign: c.CrossAlign,
Expanded: c.Expanded,
}
return v.PaintBounds(bounds, frameIdx)
}
func (c Column) Paint(dc *gg.Context, bounds image.Rectangle, frameIdx int) {
v := Vector{
Vertical: true,
Children: c.Children,
MainAlign: c.MainAlign,
CrossAlign: c.CrossAlign,
Expanded: c.Expanded,
}
v.Paint(dc, bounds, frameIdx)
}
func (c Column) FrameCount() int {
return MaxFrameCount(c.Children)
}