~eliasnaur/gio

f2df7c145801734dcbc80e3e7ccaf3be513c107a — Elias Naur a month ago 31d722d
widget: change Enum.Layout to follow layout protocol

Respect constraints and return dimensions.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2 files changed, 13 insertions(+), 1 deletions(-)

M widget/enum.go
M widget/material/radiobutton.go
M widget/enum.go => widget/enum.go +12 -1
@@ 1,8 1,12 @@
package widget

import (
	"image"

	"gioui.org/gesture"
	"gioui.org/io/pointer"
	"gioui.org/layout"
	"gioui.org/op"
)

type Enum struct {


@@ 32,7 36,12 @@ func (e *Enum) Changed() bool {
}

// Layout adds the event handler for key.
func (e *Enum) Layout(gtx layout.Context, key string) {
func (e *Enum) Layout(gtx layout.Context, key string) layout.Dimensions {
	var st op.StackOp
	st.Push(gtx.Ops)
	defer st.Pop()
	pointer.Rect(image.Rectangle{Max: gtx.Constraints.Min}).Add(gtx.Ops)

	if index(e.values, key) == -1 {
		e.values = append(e.values, key)
		e.clicks = append(e.clicks, gesture.Click{})


@@ 48,4 57,6 @@ func (e *Enum) Layout(gtx layout.Context, key string) {
		}
		clk.Add(gtx.Ops)
	}

	return layout.Dimensions{Size: gtx.Constraints.Min}
}

M widget/material/radiobutton.go => widget/material/radiobutton.go +1 -0
@@ 37,6 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 {
	dims := r.layout(gtx, r.Group.Value == r.Key)
	gtx.Constraints.Min = dims.Size
	r.Group.Layout(gtx, r.Key)
	return dims
}