mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 09:55:40 +00:00
widget: change Enum.Layout to follow layout protocol
Respect constraints and return dimensions. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+12
-1
@@ -1,8 +1,12 @@
|
|||||||
package widget
|
package widget
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"image"
|
||||||
|
|
||||||
"gioui.org/gesture"
|
"gioui.org/gesture"
|
||||||
|
"gioui.org/io/pointer"
|
||||||
"gioui.org/layout"
|
"gioui.org/layout"
|
||||||
|
"gioui.org/op"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Enum struct {
|
type Enum struct {
|
||||||
@@ -32,7 +36,12 @@ func (e *Enum) Changed() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Layout adds the event handler for key.
|
// 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 {
|
if index(e.values, key) == -1 {
|
||||||
e.values = append(e.values, key)
|
e.values = append(e.values, key)
|
||||||
e.clicks = append(e.clicks, gesture.Click{})
|
e.clicks = append(e.clicks, gesture.Click{})
|
||||||
@@ -48,4 +57,6 @@ func (e *Enum) Layout(gtx layout.Context, key string) {
|
|||||||
}
|
}
|
||||||
clk.Add(gtx.Ops)
|
clk.Add(gtx.Ops)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return layout.Dimensions{Size: gtx.Constraints.Min}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ func RadioButton(th *Theme, group *widget.Enum, key, label string) RadioButtonSt
|
|||||||
// Layout updates enum and displays the radio button.
|
// Layout updates enum and displays the radio button.
|
||||||
func (r RadioButtonStyle) Layout(gtx layout.Context) layout.Dimensions {
|
func (r RadioButtonStyle) Layout(gtx layout.Context) layout.Dimensions {
|
||||||
dims := r.layout(gtx, r.Group.Value == r.Key)
|
dims := r.layout(gtx, r.Group.Value == r.Key)
|
||||||
|
gtx.Constraints.Min = dims.Size
|
||||||
r.Group.Layout(gtx, r.Key)
|
r.Group.Layout(gtx, r.Key)
|
||||||
return dims
|
return dims
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user