widget,widget/material: use constraints for setting up hit area

Before this change, the widget.Button.Layout method assumed the caller had set
up the pointer hit area before. Further, the very common rectangular hit
areas needed both an AreaOp and a widget.Button.Layout call.

Make widget.Button less subtle and more useful by setting up a
pointer hit area given by the incoming minimum constraints.

Drop a pointer.AreaOp made redundant by the change.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2020-05-11 12:26:45 +02:00
parent 4e20ea83a1
commit fd2cb4a7a1
2 changed files with 6 additions and 1 deletions
+6
View File
@@ -3,10 +3,12 @@
package widget
import (
"image"
"time"
"gioui.org/f32"
"gioui.org/gesture"
"gioui.org/io/pointer"
"gioui.org/layout"
"gioui.org/op"
)
@@ -44,7 +46,11 @@ func (b *Button) History() []Click {
func (b *Button) Layout(gtx *layout.Context) {
// Flush clicks from before the previous frame.
b.processEvents(gtx)
var st op.StackOp
st.Push(gtx.Ops)
pointer.Rect(image.Rectangle{Max: gtx.Constraints.Min()}).Add(gtx.Ops)
b.click.Add(gtx.Ops)
st.Pop()
for len(b.history) > 0 {
c := b.history[0]
if gtx.Now().Sub(c.Time) < 1*time.Second {
-1
View File
@@ -116,7 +116,6 @@ func (b ButtonLayoutStyle) Layout(gtx *layout.Context, button *widget.Button, w
})
}),
layout.Expanded(func() {
pointer.Rect(image.Rectangle{Max: gtx.Constraints.Min()}).Add(gtx.Ops)
button.Layout(gtx)
}),
)