~eliasnaur/gio

b3e8f5953e7765d72f2a93ac9a105d1684c4a469 — Elias Naur 10 months ago 44d16d0
ui/layout: add Stack example

Signed-off-by: Elias Naur <mail@eliasnaur.com>
1 files changed, 25 insertions(+), 0 deletions(-)

M ui/layout/layout_test.go
M ui/layout/layout_test.go => ui/layout/layout_test.go +25 -0
@@ 85,6 85,31 @@ func ExampleFlex() {
	// 50%: {0 45}
}

func ExampleStack() {
	ops := new(ui.Ops)

	cs := layout.RigidConstraints(image.Point{X: 100, Y: 100})

	stack := layout.Stack{}
	stack.Init(ops, cs)

	// Rigid 50x50 widget.
	cs = stack.Rigid()
	dims := layoutWidget(50, 50, cs)
	child1 := stack.End(dims)

	// Force widget to the same size as the first.
	cs = stack.Expand()
	fmt.Printf("Expand: %v\n", cs)
	dims = layoutWidget(10, 10, cs)
	child2 := stack.End(dims)

	dims = stack.Layout(child1, child2)

	// Output:
	// Expand: {{50 50} {50 50}}
}

func layoutWidget(width, height int, cs layout.Constraints) layout.Dimens {
	return layout.Dimens{
		Size: image.Point{