diff --git a/ui/layout/doc.go b/ui/layout/doc.go index 4f4ac99c..60fc37a6 100644 --- a/ui/layout/doc.go +++ b/ui/layout/doc.go @@ -8,8 +8,8 @@ Constraints and dimensions Constraints and dimensions form the the interface between layouts and interface child elements. Every layout operation start with a set of constraints for acceptable widths and heights -of a child. The operation ends by the child computing and returning -its chosen size in the form of a Dimens. +of a child. The operation ends with the child computing and returning +its size and baseline (if any). For example, to add space above a widget: diff --git a/ui/layout/flex.go b/ui/layout/flex.go index 2dee7d24..7f698c24 100644 --- a/ui/layout/flex.go +++ b/ui/layout/flex.go @@ -33,7 +33,7 @@ type Flex struct { // FlexChild is the layout result of a call End. type FlexChild struct { macro ui.MacroOp - dims Dimens + dims Dimensions } // Spacing determine the spacing mode for a Flex. @@ -124,7 +124,7 @@ func (f *Flex) Flexible(weight float32) Constraints { // End a child by specifying its dimensions. Pass the returned layout result // to Layout. -func (f *Flex) End(dims Dimens) FlexChild { +func (f *Flex) End(dims Dimensions) FlexChild { if f.mode <= modeBegun { panic("End called without an active child") } @@ -146,7 +146,7 @@ func (f *Flex) End(dims Dimens) FlexChild { // Layout a list of children. The order of the children determines their laid // out order. -func (f *Flex) Layout(children ...FlexChild) Dimens { +func (f *Flex) Layout(children ...FlexChild) Dimensions { mainc := axisMainConstraint(f.Axis, f.cs) crossSize := axisCrossConstraint(f.Axis, f.cs).Constrain(f.maxCross) var space int @@ -213,7 +213,7 @@ func (f *Flex) Layout(children ...FlexChild) Dimens { if baseline == 0 { baseline = sz.Y } - return Dimens{Size: sz, Baseline: baseline} + return Dimensions{Size: sz, Baseline: baseline} } func axisPoint(a Axis, main, cross int) image.Point { diff --git a/ui/layout/layout.go b/ui/layout/layout.go index 3907a520..a7501d29 100644 --- a/ui/layout/layout.go +++ b/ui/layout/layout.go @@ -21,9 +21,9 @@ type Constraint struct { Min, Max int } -// Dimens are the resolved size and baseline for a user +// Dimensions are the resolved size and baseline for a user // interface element. -type Dimens struct { +type Dimensions struct { Size image.Point Baseline int } @@ -143,13 +143,13 @@ func (in *Inset) Begin(c ui.Config, ops *ui.Ops, cs Constraints) Constraints { // End the inset operation and return the dimensions for the // inset child. -func (in *Inset) End(dims Dimens) Dimens { +func (in *Inset) End(dims Dimensions) Dimensions { if !in.begun { panic("must Begin before End") } in.begun = false in.stack.Pop() - return Dimens{ + return Dimensions{ Size: in.cs.Constrain(dims.Size.Add(image.Point{X: in.right + in.left, Y: in.top + in.bottom})), Baseline: dims.Baseline + in.top, } @@ -177,7 +177,7 @@ func (a *Align) Begin(ops *ui.Ops, cs Constraints) Constraints { // End the align operation and return the dimensions for the // aligned child. -func (a *Align) End(dims Dimens) Dimens { +func (a *Align) End(dims Dimensions) Dimensions { if !a.begun { panic("must Begin before End") } @@ -209,7 +209,7 @@ func (a *Align) End(dims Dimens) Dimens { ui.TransformOp{}.Offset(toPointF(p)).Add(ops) a.macro.Add(ops) stack.Pop() - return Dimens{ + return Dimensions{ Size: sz, Baseline: dims.Baseline, } diff --git a/ui/layout/layout_test.go b/ui/layout/layout_test.go index 5236b308..9efb85bb 100644 --- a/ui/layout/layout_test.go +++ b/ui/layout/layout_test.go @@ -140,8 +140,8 @@ func ExampleList() { // 5 } -func layoutWidget(width, height int, cs layout.Constraints) layout.Dimens { - return layout.Dimens{ +func layoutWidget(width, height int, cs layout.Constraints) layout.Dimensions { + return layout.Dimensions{ Size: image.Point{ X: width, Y: height, diff --git a/ui/layout/list.go b/ui/layout/list.go index 92a3996e..8e202575 100644 --- a/ui/layout/list.go +++ b/ui/layout/list.go @@ -158,7 +158,7 @@ func (l *List) next() (int, bool) { } // End the current child by specifying its dimensions. -func (l *List) End(dims Dimens) { +func (l *List) End(dims Dimensions) { l.child.Stop() child := scrollChild{dims.Size, l.child} switch l.dir { @@ -179,7 +179,7 @@ func (l *List) End(dims Dimens) { } // Layout the List and return its dimensions. -func (l *List) Layout() Dimens { +func (l *List) Layout() Dimensions { if l.more { panic("unfinished child") } @@ -254,5 +254,5 @@ func (l *List) Layout() Dimens { pointer.RectAreaOp{Rect: image.Rectangle{Max: dims}}.Add(ops) l.scroll.Add(ops) l.macro.Add(ops) - return Dimens{Size: dims} + return Dimensions{Size: dims} } diff --git a/ui/layout/stack.go b/ui/layout/stack.go index 7a94d2cf..264d09e1 100644 --- a/ui/layout/stack.go +++ b/ui/layout/stack.go @@ -27,7 +27,7 @@ type Stack struct { // StackChild is the layout result of a call to End. type StackChild struct { macro ui.MacroOp - dims Dimens + dims Dimensions } // Init a stack before calling Rigid or Expand. @@ -69,7 +69,7 @@ func (s *Stack) Expand() Constraints { } // End a child by specifying its dimensions. -func (s *Stack) End(dims Dimens) StackChild { +func (s *Stack) End(dims Dimensions) StackChild { s.macro.Stop() s.begun = false if w := dims.Size.X; w > s.maxSZ.X { @@ -88,7 +88,7 @@ func (s *Stack) End(dims Dimens) StackChild { // Layout a list of children. The order of the children determines their laid // out order. -func (s *Stack) Layout(children ...StackChild) Dimens { +func (s *Stack) Layout(children ...StackChild) Dimensions { for _, ch := range children { sz := ch.dims.Size var p image.Point @@ -114,7 +114,7 @@ func (s *Stack) Layout(children ...StackChild) Dimens { if b == 0 { b = s.maxSZ.Y } - return Dimens{ + return Dimensions{ Size: s.maxSZ, Baseline: b, } diff --git a/ui/text/editor.go b/ui/text/editor.go index 6c8fa2d6..5993700c 100644 --- a/ui/text/editor.go +++ b/ui/text/editor.go @@ -48,7 +48,7 @@ type Editor struct { viewSize image.Point valid bool lines []Line - dims layout.Dimens + dims layout.Dimensions padTop, padBottom int padLeft, padRight int requestFocus bool @@ -165,7 +165,7 @@ func (e *Editor) Focus() { e.requestFocus = true } -func (e *Editor) Layout(cfg ui.Config, queue input.Queue, ops *ui.Ops, cs layout.Constraints) layout.Dimens { +func (e *Editor) Layout(cfg ui.Config, queue input.Queue, ops *ui.Ops, cs layout.Constraints) layout.Dimensions { for _, ok := e.Next(cfg, queue); ok; _, ok = e.Next(cfg, queue) { } twoDp := cfg.Px(ui.Dp(2)) @@ -270,7 +270,7 @@ func (e *Editor) Layout(cfg ui.Config, queue input.Queue, ops *ui.Ops, cs layout pointer.RectAreaOp{Rect: r}.Add(ops) e.scroller.Add(ops) e.clicker.Add(ops) - return layout.Dimens{Size: e.viewSize, Baseline: baseline} + return layout.Dimensions{Size: e.viewSize, Baseline: baseline} } // Text returns the contents of the editor. diff --git a/ui/text/label.go b/ui/text/label.go index 9eb26e7b..d7d69d19 100644 --- a/ui/text/label.go +++ b/ui/text/label.go @@ -92,7 +92,7 @@ func (l *lineIterator) Next() (String, f32.Point, bool) { return String{}, f32.Point{}, false } -func (l Label) Layout(ops *ui.Ops, cs layout.Constraints) layout.Dimens { +func (l Label) Layout(ops *ui.Ops, cs layout.Constraints) layout.Dimensions { textLayout := l.Face.Layout(l.Text, LayoutOptions{MaxWidth: cs.Width.Max}) lines := textLayout.Lines if max := l.MaxLines; max > 0 && len(lines) > max { diff --git a/ui/text/measure.go b/ui/text/measure.go index 7418ba56..91853ab5 100644 --- a/ui/text/measure.go +++ b/ui/text/measure.go @@ -61,7 +61,7 @@ const ( Middle ) -func linesDimens(lines []Line) layout.Dimens { +func linesDimens(lines []Line) layout.Dimensions { var width fixed.Int26_6 var h int var baseline int @@ -78,7 +78,7 @@ func linesDimens(lines []Line) layout.Dimens { h += lines[len(lines)-1].Descent.Ceil() } w := width.Ceil() - return layout.Dimens{ + return layout.Dimensions{ Size: image.Point{ X: w, Y: h, diff --git a/ui/widget/image.go b/ui/widget/image.go index cd7b65fe..90dd1599 100644 --- a/ui/widget/image.go +++ b/ui/widget/image.go @@ -25,7 +25,7 @@ type Image struct { Scale float32 } -func (im Image) Layout(c ui.Config, ops *ui.Ops, cs layout.Constraints) layout.Dimens { +func (im Image) Layout(c ui.Config, ops *ui.Ops, cs layout.Constraints) layout.Dimensions { size := im.Src.Bounds() wf, hf := float32(size.Dx()), float32(size.Dy()) var w, h int @@ -49,5 +49,5 @@ func (im Image) Layout(c ui.Config, ops *ui.Ops, cs layout.Constraints) layout.D } paint.ImageOp{Src: im.Src, Rect: im.Rect}.Add(ops) paint.PaintOp{Rect: dr}.Add(ops) - return layout.Dimens{Size: d, Baseline: d.Y} + return layout.Dimensions{Size: d, Baseline: d.Y} }