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:
Elias Naur
2020-05-24 13:50:03 +02:00
parent 3164a3fee7
commit 31d722d9eb
3 changed files with 15 additions and 9 deletions
+10 -1
View File
@@ -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}
}