8f37a565b9520441b077f68d61cb12bc0aa4239c — Elias Naur a month ago 79233a3
ui/layout: document layout types and helpers

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

M ui/layout/layout.go
M ui/layout/layout.go => ui/layout/layout.go +24 -11
@@ 21,13 21,22 @@ Min, Max int
  }
  
+ // Dimens are the resolved size and baseline for a user
+ // interface element.
  type Dimens struct {
  	Size     image.Point
  	Baseline int
  }
  
+ // Axis is the the Horizontal or Vertical direction.
  type Axis uint8
+ 
+ // Alignment is the relative alignment of a list of
+ // interface elements.
  type Alignment uint8
+ 
+ // Direction is the alignment of a set of interface elements
+ // relative to a containing space.
  type Direction uint8
  
  const (


@@ 54,6 63,7 @@ Vertical
  )
  
+ // Constrain a value to the range [Min; Max].
  func (c Constraint) Constrain(v int) int {
  	if v < c.Min {
  		return c.Min


@@ 63,8 73,9 @@ return v
  }
  
- func (c Constraints) Constrain(p image.Point) image.Point {
- 	return image.Point{X: c.Width.Constrain(p.X), Y: c.Height.Constrain(p.Y)}
+ // Constrain a size to the Width and Height ranges.
+ func (c Constraints) Constrain(size image.Point) image.Point {
+ 	return image.Point{X: c.Width.Constrain(size.X), Y: c.Height.Constrain(size.Y)}
  }
  
  // RigidConstraints returns the constraints that can only be


@@ 76,6 87,7 @@ }
  }
  
+ // Inset adds space around an interface element.
  type Inset struct {
  	Top, Right, Bottom, Left ui.Value
  


@@ 85,6 97,16 @@ cs                       Constraints
  }
  
+ // Align aligns an interface element in the available space.
+ type Align struct {
+ 	Alignment Direction
+ 
+ 	macro ui.MacroOp
+ 	ops   *ui.Ops
+ 	begun bool
+ 	cs    Constraints
+ }
+ 
  func (in *Inset) Begin(c ui.Config, ops *ui.Ops, cs Constraints) Constraints {
  	if in.begun {
  		panic("must End before Begin")


@@ 135,15 157,6 @@ return Inset{Top: v, Right: v, Bottom: v, Left: v}
  }
  
- type Align struct {
- 	Alignment Direction
- 
- 	macro ui.MacroOp
- 	ops   *ui.Ops
- 	begun bool
- 	cs    Constraints
- }
- 
  func (a *Align) Begin(ops *ui.Ops, cs Constraints) Constraints {
  	if a.begun {
  		panic("must End before Begin")