From cf787a1a8c0a100058c4d86c9f7c16c8a2c975e6 Mon Sep 17 00:00:00 2001 From: Chris Waldon Date: Wed, 9 Mar 2022 14:01:25 -0500 Subject: [PATCH] widget/material: make clickable respect constraints This change makes material.Clickable propagate the constraints it is invoked with to the widget being made clickable. Without this, the internal use of layout.Stack resets the minimum constraints to zero. This has the confusing effect of breaking a working layout when you decide to wrap one element in a Clickable, which I think is sufficiently surprising that we should eliminate the footgun. Signed-off-by: Chris Waldon --- widget/material/button.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/widget/material/button.go b/widget/material/button.go index ea6d3548..94276e5f 100644 --- a/widget/material/button.go +++ b/widget/material/button.go @@ -91,6 +91,7 @@ func IconButton(th *Theme, button *widget.Clickable, icon *widget.Icon, descript func Clickable(gtx layout.Context, button *widget.Clickable, w layout.Widget) layout.Dimensions { return button.Layout(gtx, func(gtx layout.Context) layout.Dimensions { semantic.Button.Add(gtx.Ops) + constraints := gtx.Constraints return layout.Stack{}.Layout(gtx, layout.Expanded(func(gtx layout.Context) layout.Dimensions { defer clip.Rect{Max: gtx.Constraints.Min}.Push(gtx.Ops).Pop() @@ -102,7 +103,10 @@ func Clickable(gtx layout.Context, button *widget.Clickable, w layout.Widget) la } return layout.Dimensions{Size: gtx.Constraints.Min} }), - layout.Stacked(w), + layout.Stacked(func(gtx layout.Context) layout.Dimensions { + gtx.Constraints = constraints + return w(gtx) + }), ) }) }