From 148a2828e7bd7a08bab0414c5bcc19f9e8ab5b80 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Sat, 29 Feb 2020 14:06:25 +0100 Subject: [PATCH] layout: don't force Expanded Stack children larger than their minimum Instead, honor the constraints after laying out both Stacked and Expanded children. Signed-off-by: Elias Naur --- layout/stack.go | 2 +- widget/material/button.go | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/layout/stack.go b/layout/stack.go index 0f5ec18a..67c962d5 100644 --- a/layout/stack.go +++ b/layout/stack.go @@ -69,7 +69,6 @@ func (s Stack) Layout(gtx *Context, children ...StackChild) { children[i].macro = m children[i].dims = dims } - maxSZ = gtx.Constraints.Constrain(maxSZ) // Then lay out Expanded children. for i, w := range children { if !w.expanded { @@ -93,6 +92,7 @@ func (s Stack) Layout(gtx *Context, children ...StackChild) { children[i].dims = dims } + maxSZ = gtx.Constraints.Constrain(maxSZ) var baseline int for _, ch := range children { sz := ch.dims.Size diff --git a/widget/material/button.go b/widget/material/button.go index a6e70367..8cea7905 100644 --- a/widget/material/button.go +++ b/widget/material/button.go @@ -98,12 +98,13 @@ func (b Button) Layout(gtx *layout.Context, button *widget.Button) { } func (b IconButton) Layout(gtx *layout.Context, button *widget.Button) { - layout.Stack{}.Layout(gtx, + layout.Stack{Alignment: layout.Center}.Layout(gtx, layout.Expanded(func() { - size := float32(gtx.Constraints.Width.Min) - rr := float32(size) * .5 + size := gtx.Constraints.Width.Min + sizef := float32(size) + rr := sizef * .5 clip.Rect{ - Rect: f32.Rectangle{Max: f32.Point{X: size, Y: size}}, + Rect: f32.Rectangle{Max: f32.Point{X: sizef, Y: sizef}}, NE: rr, NW: rr, SE: rr, SW: rr, }.Op(gtx.Ops).Add(gtx.Ops) fill(gtx, b.Background)