diff --git a/widget/enum.go b/widget/enum.go index 112247fb..e4869c38 100644 --- a/widget/enum.go +++ b/widget/enum.go @@ -7,6 +7,7 @@ import ( "gioui.org/gesture" "gioui.org/layout" + "gioui.org/op" "gioui.org/op/clip" ) @@ -44,8 +45,11 @@ func (e *Enum) Hovered() (string, bool) { } // Layout adds the event handler for key. -func (e *Enum) Layout(gtx layout.Context, key string) layout.Dimensions { - defer clip.Rect(image.Rectangle{Max: gtx.Constraints.Min}).Push(gtx.Ops).Pop() +func (e *Enum) Layout(gtx layout.Context, key string, content layout.Widget) layout.Dimensions { + m := op.Record(gtx.Ops) + dims := content(gtx) + c := m.Stop() + defer clip.Rect(image.Rectangle{Max: dims.Size}).Push(gtx.Ops).Pop() if index(e.values, key) == -1 { e.values = append(e.values, key) @@ -72,6 +76,7 @@ func (e *Enum) Layout(gtx layout.Context, key string) layout.Dimensions { } clk.Add(gtx.Ops) } + c.Add(gtx.Ops) - return layout.Dimensions{Size: gtx.Constraints.Min} + return dims } diff --git a/widget/material/radiobutton.go b/widget/material/radiobutton.go index bd1c9be3..c8d2cf47 100644 --- a/widget/material/radiobutton.go +++ b/widget/material/radiobutton.go @@ -3,10 +3,7 @@ package material import ( - "image" - "gioui.org/layout" - "gioui.org/op/clip" "gioui.org/unit" "gioui.org/widget" ) @@ -40,9 +37,7 @@ func RadioButton(th *Theme, group *widget.Enum, key, label string) RadioButtonSt // Layout updates enum and displays the radio button. func (r RadioButtonStyle) Layout(gtx layout.Context) layout.Dimensions { hovered, hovering := r.Group.Hovered() - dims := r.layout(gtx, r.Group.Value == r.Key, hovering && hovered == r.Key) - defer clip.Rect(image.Rectangle{Max: dims.Size}).Push(gtx.Ops).Pop() - gtx.Constraints.Min = dims.Size - r.Group.Layout(gtx, r.Key) - return dims + return r.Group.Layout(gtx, r.Key, func(gtx layout.Context) layout.Dimensions { + return r.layout(gtx, r.Group.Value == r.Key, hovering && hovered == r.Key) + }) }