/
applayout.go
38 lines (34 loc) · 1.15 KB
/
applayout.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
package applayout
import (
"gioui.org/layout"
"gioui.org/unit"
)
// DetailRow lays out two widgets in a horizontal row, with the left
// widget considered the "Primary" widget.
type DetailRow struct {
// PrimaryWidth is the fraction of the available width that should
// be allocated to the primary widget. It should be in the range
// (0,1.0]. Defaults to 0.3 if not set.
PrimaryWidth float32
// Inset is automatically applied to both widgets. This inset is
// required, and will default to a uniform 8DP inset if not set.
layout.Inset
}
var DefaultInset = layout.UniformInset(unit.Dp(8))
// Layout the DetailRow with the provided widgets.
func (d DetailRow) Layout(gtx layout.Context, primary, detail layout.Widget) layout.Dimensions {
if d.PrimaryWidth == 0 {
d.PrimaryWidth = 0.3
}
if d.Inset == (layout.Inset{}) {
d.Inset = DefaultInset
}
return layout.Flex{Alignment: layout.Middle}.Layout(gtx,
layout.Flexed(d.PrimaryWidth, func(gtx layout.Context) layout.Dimensions {
return d.Inset.Layout(gtx, primary)
}),
layout.Flexed(1-d.PrimaryWidth, func(gtx layout.Context) layout.Dimensions {
return d.Inset.Layout(gtx, detail)
}),
)
}