From 2d96e760d39a964c16a2de2e7f701f87ec590f22 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Thu, 16 May 2019 15:41:43 +0200 Subject: [PATCH] ui/layout,ui/text,ui/widget: shorten Widget function names to W Signed-off-by: Elias Naur --- ui/layout/layout.go | 20 ++++++++++---------- ui/text/editor.go | 2 +- ui/text/label.go | 2 +- ui/widget/image.go | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/ui/layout/layout.go b/ui/layout/layout.go index ae6a5774..96dbaec3 100644 --- a/ui/layout/layout.go +++ b/ui/layout/layout.go @@ -70,12 +70,12 @@ func ExactConstraints(size image.Point) Constraints { } type Insets struct { - W Widget + C Widget Top, Right, Bottom, Left float32 } -func (in Insets) Layout(ops *ui.Ops, cs Constraints) Dimens { +func (in Insets) W(ops *ui.Ops, cs Constraints) Dimens { mcs := cs t, r, b, l := int(math.Round(float64(in.Top))), int(math.Round(float64(in.Right))), int(math.Round(float64(in.Bottom))), int(math.Round(float64(in.Left))) if mcs.Width.Max != ui.Inf { @@ -100,7 +100,7 @@ func (in Insets) Layout(ops *ui.Ops, cs Constraints) Dimens { } ops.Begin() ui.OpTransform{Transform: ui.Offset(toPointF(image.Point{X: l, Y: t}))}.Add(ops) - dims := in.W(ops, mcs) + dims := in.C(ops, mcs) ops.End().Add(ops) return Dimens{ Size: cs.Constrain(dims.Size.Add(image.Point{X: r + l, Y: t + b})), @@ -109,7 +109,7 @@ func (in Insets) Layout(ops *ui.Ops, cs Constraints) Dimens { } func EqualInsets(v float32, w Widget) Insets { - return Insets{W: w, Top: v, Right: v, Bottom: v, Left: v} + return Insets{C: w, Top: v, Right: v, Bottom: v, Left: v} } func isInf(v ui.Value) bool { @@ -117,11 +117,11 @@ func isInf(v ui.Value) bool { } type Sized struct { - W Widget + C Widget Width, Height float32 } -func (s Sized) Layout(ops *ui.Ops, cs Constraints) Dimens { +func (s Sized) W(ops *ui.Ops, cs Constraints) Dimens { if h := int(s.Height + 0.5); h != 0 { if cs.Height.Min < h { cs.Height.Min = h @@ -138,17 +138,17 @@ func (s Sized) Layout(ops *ui.Ops, cs Constraints) Dimens { cs.Width.Max = w } } - return s.W(ops, cs) + return s.C(ops, cs) } type Align struct { - W Widget + C Widget Alignment Direction } -func (a Align) Layout(ops *ui.Ops, cs Constraints) Dimens { +func (a Align) W(ops *ui.Ops, cs Constraints) Dimens { ops.Begin() - dims := a.W(ops, cs.Loose()) + dims := a.C(ops, cs.Loose()) block := ops.End() sz := dims.Size if cs.Width.Max != ui.Inf { diff --git a/ui/text/editor.go b/ui/text/editor.go index 7655720c..40592538 100644 --- a/ui/text/editor.go +++ b/ui/text/editor.go @@ -128,7 +128,7 @@ func (e *Editor) caretWidth() fixed.Int26_6 { return fixed.Int26_6(oneDp * 64) } -func (e *Editor) Layout(ops *ui.Ops, cs layout.Constraints) layout.Dimens { +func (e *Editor) W(ops *ui.Ops, cs layout.Constraints) layout.Dimens { twoDp := int(e.cfg.Pixels(ui.Dp(2)) + 0.5) e.padLeft, e.padRight = twoDp, twoDp maxWidth := cs.Width.Max diff --git a/ui/text/label.go b/ui/text/label.go index ac02f4d2..a1d16d0f 100644 --- a/ui/text/label.go +++ b/ui/text/label.go @@ -80,7 +80,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) W(ops *ui.Ops, cs layout.Constraints) layout.Dimens { textLayout := l.Face.Layout(l.Text, false, cs.Width.Max) lines := textLayout.Lines dims := linesDimens(lines) diff --git a/ui/widget/image.go b/ui/widget/image.go index 3eaef624..c133c0e0 100644 --- a/ui/widget/image.go +++ b/ui/widget/image.go @@ -16,7 +16,7 @@ type Image struct { Rect image.Rectangle } -func (im Image) Layout(ops *ui.Ops, cs layout.Constraints) layout.Dimens { +func (im Image) W(ops *ui.Ops, cs layout.Constraints) layout.Dimens { d := image.Point{X: cs.Width.Max, Y: cs.Height.Max} if d.X == ui.Inf { d.X = cs.Width.Min