mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-04 17:05:38 +00:00
layout: simplify Flex API to a single Layout call
With the simplification of MacroOp, it is now possible to simplify
the Flex API to just a single Layout method, similar to List:
layout.Flex{}.Layout(gtx,
layout.Rigid(func() { ... }),
layout.Flexed(0.5, func() { ... }),
)
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -36,32 +36,30 @@ func (c *checkable) layout(gtx *layout.Context, checked bool) {
|
||||
|
||||
hmin := gtx.Constraints.Width.Min
|
||||
vmin := gtx.Constraints.Height.Min
|
||||
flex := layout.Flex{Alignment: layout.Middle}
|
||||
|
||||
ico := flex.Rigid(gtx, func() {
|
||||
layout.Align(layout.Center).Layout(gtx, func() {
|
||||
layout.UniformInset(unit.Dp(2)).Layout(gtx, func() {
|
||||
size := gtx.Px(c.Size)
|
||||
icon.Color = c.IconColor
|
||||
icon.Layout(gtx, unit.Px(float32(size)))
|
||||
gtx.Dimensions = layout.Dimensions{
|
||||
Size: image.Point{X: size, Y: size},
|
||||
}
|
||||
layout.Flex{Alignment: layout.Middle}.Layout(gtx,
|
||||
layout.Rigid(func() {
|
||||
layout.Align(layout.Center).Layout(gtx, func() {
|
||||
layout.UniformInset(unit.Dp(2)).Layout(gtx, func() {
|
||||
size := gtx.Px(c.Size)
|
||||
icon.Color = c.IconColor
|
||||
icon.Layout(gtx, unit.Px(float32(size)))
|
||||
gtx.Dimensions = layout.Dimensions{
|
||||
Size: image.Point{X: size, Y: size},
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
}),
|
||||
|
||||
lbl := flex.Rigid(gtx, func() {
|
||||
gtx.Constraints.Width.Min = hmin
|
||||
gtx.Constraints.Height.Min = vmin
|
||||
layout.Align(layout.Start).Layout(gtx, func() {
|
||||
layout.UniformInset(unit.Dp(2)).Layout(gtx, func() {
|
||||
paint.ColorOp{Color: c.Color}.Add(gtx.Ops)
|
||||
widget.Label{}.Layout(gtx, c.shaper, c.Font, c.Label)
|
||||
layout.Rigid(func() {
|
||||
gtx.Constraints.Width.Min = hmin
|
||||
gtx.Constraints.Height.Min = vmin
|
||||
layout.Align(layout.Start).Layout(gtx, func() {
|
||||
layout.UniformInset(unit.Dp(2)).Layout(gtx, func() {
|
||||
paint.ColorOp{Color: c.Color}.Add(gtx.Ops)
|
||||
widget.Label{}.Layout(gtx, c.shaper, c.Font, c.Label)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
flex.Layout(gtx, ico, lbl)
|
||||
}),
|
||||
)
|
||||
pointer.Rect(image.Rectangle{Max: gtx.Dimensions.Size}).Add(gtx.Ops)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user