ui/layout: document List, Stack

Tweak Flex documentation.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-08-10 16:35:51 +02:00
parent 8f17163a13
commit ba3a952af2
3 changed files with 22 additions and 4 deletions
+2 -2
View File
@@ -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")
+7 -2
View File
@@ -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.
+13
View File
@@ -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