~eliasnaur/gio

94f275288571009dcf32fe59b302fcf617879c42 — Elias Naur 6 months ago 4ce8f4e
ui/layout: add Align example

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

M ui/layout/layout_test.go
M ui/layout/layout_test.go => ui/layout/layout_test.go +29 -10
@@ 13,28 13,47 @@ type config struct{}

var cfg = new(config)

var cs = layout.Constraints{
	Width: layout.Constraint{
		Max: 100,
	},
	Height: layout.Constraint{
		Max: 100,
	},
}

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

	// Loose constraints with no minimal size.
	var cs layout.Constraints
	cs.Width.Max = 100
	cs.Height.Max = 100

	// Inset all edges by 10.
	inset := layout.UniformInset(ui.Dp(10))
	cs = inset.Begin(cfg, ops, cs)
	// Lay out a 50x50 sized widget.
	dims := layoutWidget(50, 50, cs)
	fmt.Println(dims.Size)
	dims = inset.End(dims)

	fmt.Println(dims.Size)

	// Output: (70,70)
	// Output:
	// (50,50)
	// (70,70)
}

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

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

	align := layout.Align{Alignment: layout.Center}
	cs = align.Begin(ops, cs)
	// Lay out a 50x50 sized widget.
	dims := layoutWidget(50, 50, cs)
	fmt.Println(dims.Size)

	dims = align.End(dims)

	fmt.Println(dims.Size)

	// Output:
	// (50,50)
	// (100,100)
}

func layoutWidget(width, height int, cs layout.Constraints) layout.Dimens {