mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-03 00:16:15 +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:
+12
-15
@@ -53,21 +53,18 @@ func ExampleFlex() {
|
||||
gtx := new(layout.Context)
|
||||
gtx.Reset(nil, image.Point{X: 100, Y: 100})
|
||||
|
||||
flex := layout.Flex{}
|
||||
|
||||
// Rigid 10x10 widget.
|
||||
child1 := flex.Rigid(gtx, func() {
|
||||
fmt.Printf("Rigid: %v\n", gtx.Constraints.Width)
|
||||
layoutWidget(gtx, 10, 10)
|
||||
})
|
||||
|
||||
// Child with 50% space allowance.
|
||||
child2 := flex.Flex(gtx, 0.5, func() {
|
||||
fmt.Printf("50%%: %v\n", gtx.Constraints.Width)
|
||||
layoutWidget(gtx, 10, 10)
|
||||
})
|
||||
|
||||
flex.Layout(gtx, child1, child2)
|
||||
layout.Flex{}.Layout(gtx,
|
||||
// Rigid 10x10 widget.
|
||||
layout.Rigid(func() {
|
||||
fmt.Printf("Rigid: %v\n", gtx.Constraints.Width)
|
||||
layoutWidget(gtx, 10, 10)
|
||||
}),
|
||||
// Child with 50% space allowance.
|
||||
layout.Flexed(0.5, func() {
|
||||
fmt.Printf("50%%: %v\n", gtx.Constraints.Width)
|
||||
layoutWidget(gtx, 10, 10)
|
||||
}),
|
||||
)
|
||||
|
||||
// Output:
|
||||
// Rigid: {0 100}
|
||||
|
||||
Reference in New Issue
Block a user