~eliasnaur/gio

ba3a952af2b90016153300b37412175a66bc96ad — Elias Naur 6 months ago 8f17163
ui/layout: document List, Stack

Tweak Flex documentation.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
3 files changed, 22 insertions(+), 4 deletions(-)

M ui/layout/flex.go
M ui/layout/list.go
M ui/layout/stack.go
M ui/layout/flex.go => ui/layout/flex.go +2 -2
@@ 30,8 30,7 @@ type Flex struct {
	maxBaseline int
}

// FlexChild is the layout result of a call to Rigid or
// Flexible.
// FlexChild is the layout result of a call End.
type FlexChild struct {
	macro ui.MacroOp
	dims  Dimens


@@ 67,6 66,7 @@ const (
	modeFlex
)

// Init must be called before Rigid or Flexible.
func (f *Flex) Init(ops *ui.Ops, cs Constraints) *Flex {
	if f.mode > modeBegun {
		panic("must End the current child before calling Init again")

M ui/layout/list.go => ui/layout/list.go +7 -2
@@ 17,9 17,14 @@ type scrollChild struct {
	macro ui.MacroOp
}

// List displays a subsection of a potentially infinitely
// large underlying list. List accepts user input to scroll
// the subsection.
type List struct {
	Axis      Axis
	Invert    bool
	Axis Axis
	// Invert inverts a List so it is anchored from its end.
	Invert bool
	// Alignment is the cross axis alignment.
	Alignment Alignment

	// The distance scrolled since last call to Init.

M ui/layout/stack.go => ui/layout/stack.go +13 -0
@@ 8,7 8,11 @@ import (
	"gioui.org/ui"
)

// Stack lays out child elements on top of each other,
// according to an alignment direction.
type Stack struct {
	// Alignment is the direction to align children
	// smaller than the available space.
	Alignment Direction

	macro       ui.MacroOp


@@ 20,11 24,13 @@ type Stack struct {
	baseline    int
}

// StackChild is the layout result of a call to End.
type StackChild struct {
	macro ui.MacroOp
	dims  Dimens
}

// Init a stack before calling Rigid or Expand.
func (s *Stack) Init(ops *ui.Ops, cs Constraints) *Stack {
	s.ops = ops
	s.cs = cs


@@ 45,11 51,15 @@ func (s *Stack) begin() {
	s.macro.Record(s.ops)
}

// Rigid begins a child with the same constraints that were
// passed to Init.
func (s *Stack) Rigid() Constraints {
	s.begin()
	return s.cs
}

// Expand begins a child with constraints that exactly match
// the biggest child previously added.
func (s *Stack) Expand() Constraints {
	s.begin()
	return Constraints{


@@ 58,6 68,7 @@ func (s *Stack) Expand() Constraints {
	}
}

// End a child by specifying its dimensions.
func (s *Stack) End(dims Dimens) StackChild {
	s.macro.Stop()
	s.begun = false


@@ 75,6 86,8 @@ func (s *Stack) End(dims Dimens) StackChild {
	return StackChild{s.macro, dims}
}

// Layout a list of children. The order of the children determines their laid
// out order.
func (s *Stack) Layout(children ...StackChild) Dimens {
	for _, ch := range children {
		sz := ch.dims.Size