mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 09:55:40 +00:00
widget: change Bool.Layout to follow layout protocol
Just like Clickable, Bool.Layout should respect constraints and return its dimensions. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+10
-1
@@ -1,8 +1,12 @@
|
||||
package widget
|
||||
|
||||
import (
|
||||
"image"
|
||||
|
||||
"gioui.org/gesture"
|
||||
"gioui.org/io/pointer"
|
||||
"gioui.org/layout"
|
||||
"gioui.org/op"
|
||||
)
|
||||
|
||||
type Bool struct {
|
||||
@@ -24,7 +28,7 @@ func (b *Bool) Changed() bool {
|
||||
return changed
|
||||
}
|
||||
|
||||
func (b *Bool) Layout(gtx layout.Context) {
|
||||
func (b *Bool) Layout(gtx layout.Context) layout.Dimensions {
|
||||
for _, e := range b.gesture.Events(gtx) {
|
||||
switch e.Type {
|
||||
case gesture.TypeClick:
|
||||
@@ -35,5 +39,10 @@ func (b *Bool) Layout(gtx layout.Context) {
|
||||
b.Value = !b.Value
|
||||
}
|
||||
}
|
||||
var st op.StackOp
|
||||
st.Push(gtx.Ops)
|
||||
defer st.Pop()
|
||||
pointer.Rect(image.Rectangle{Max: gtx.Constraints.Min}).Add(gtx.Ops)
|
||||
b.gesture.Add(gtx.Ops)
|
||||
return layout.Dimensions{Size: gtx.Constraints.Min}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user