diff --git a/layout/example_test.go b/layout/example_test.go index 72fa0c10..d3ac8dc6 100644 --- a/layout/example_test.go +++ b/layout/example_test.go @@ -30,13 +30,12 @@ func ExampleInset() { // (70,70) } -func ExampleAlign() { +func ExampleDirection() { gtx := new(layout.Context) // Rigid constraints with both minimum and maximum set. gtx.Reset(nil, image.Point{X: 100, Y: 100}) - align := layout.Align(layout.Center) - align.Layout(gtx, func() { + layout.Center.Layout(gtx, func() { // Lay out a 50x50 sized widget. layoutWidget(gtx, 50, 50) fmt.Println(gtx.Dimensions.Size) diff --git a/layout/layout.go b/layout/layout.go index 4a98b02d..d934221d 100644 --- a/layout/layout.go +++ b/layout/layout.go @@ -95,9 +95,6 @@ type Inset struct { Top, Right, Bottom, Left unit.Value } -// Align aligns a widget in the available space. -type Align Direction - // Layout a widget. func (in Inset) Layout(gtx *Context, w Widget) { top := gtx.Px(in.Top) @@ -140,8 +137,8 @@ func UniformInset(v unit.Value) Inset { return Inset{Top: v, Right: v, Bottom: v, Left: v} } -// Layout a widget. -func (a Align) Layout(gtx *Context, w Widget) { +// Layout a widget according to the direction. +func (a Direction) Layout(gtx *Context, w Widget) { var macro op.MacroOp macro.Record(gtx.Ops) cs := gtx.Constraints diff --git a/widget/material/button.go b/widget/material/button.go index 8110e60e..a2c56536 100644 --- a/widget/material/button.go +++ b/widget/material/button.go @@ -80,7 +80,7 @@ func (b Button) Layout(gtx *layout.Context, button *widget.Button) { layout.Stacked(func() { gtx.Constraints.Width.Min = hmin gtx.Constraints.Height.Min = vmin - layout.Align(layout.Center).Layout(gtx, func() { + layout.Center.Layout(gtx, func() { layout.Inset{Top: unit.Dp(10), Bottom: unit.Dp(10), Left: unit.Dp(12), Right: unit.Dp(12)}.Layout(gtx, func() { paint.ColorOp{Color: col}.Add(gtx.Ops) widget.Label{}.Layout(gtx, b.shaper, b.Font, b.Text) diff --git a/widget/material/checkable.go b/widget/material/checkable.go index e9e8d384..51309c59 100644 --- a/widget/material/checkable.go +++ b/widget/material/checkable.go @@ -38,7 +38,7 @@ func (c *checkable) layout(gtx *layout.Context, checked bool) { vmin := gtx.Constraints.Height.Min layout.Flex{Alignment: layout.Middle}.Layout(gtx, layout.Rigid(func() { - layout.Align(layout.Center).Layout(gtx, func() { + layout.Center.Layout(gtx, func() { layout.UniformInset(unit.Dp(2)).Layout(gtx, func() { size := gtx.Px(c.Size) icon.Color = c.IconColor @@ -53,7 +53,7 @@ func (c *checkable) layout(gtx *layout.Context, checked bool) { layout.Rigid(func() { gtx.Constraints.Width.Min = hmin gtx.Constraints.Height.Min = vmin - layout.Align(layout.Start).Layout(gtx, func() { + layout.W.Layout(gtx, func() { layout.UniformInset(unit.Dp(2)).Layout(gtx, func() { paint.ColorOp{Color: c.Color}.Add(gtx.Ops) widget.Label{}.Layout(gtx, c.shaper, c.Font, c.Label)