widget/material: use cosntraints for setting pointer hit areas

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2020-05-11 12:23:18 +02:00
parent 3fd1ccbbed
commit 4e20ea83a1
2 changed files with 11 additions and 2 deletions
+5
View File
@@ -81,6 +81,11 @@ func (c Constraints) Constrain(size image.Point) image.Point {
return image.Point{X: c.Width.Constrain(size.X), Y: c.Height.Constrain(size.Y)}
}
// Min returns the smallest dimensions that satisfy the constraints.
func (c Constraints) Min() image.Point {
return image.Point{X: c.Width.Min, Y: c.Height.Min}
}
// RigidConstraints returns the constraints that can only be
// satisfied by the given dimensions.
func RigidConstraints(size image.Point) Constraints {
+6 -2
View File
@@ -114,7 +114,9 @@ func (b ButtonLayoutStyle) Layout(gtx *layout.Context, button *widget.Button, w
w()
})
})
pointer.Rect(image.Rectangle{Max: gtx.Dimensions.Size}).Add(gtx.Ops)
}),
layout.Expanded(func() {
pointer.Rect(image.Rectangle{Max: gtx.Constraints.Min()}).Add(gtx.Ops)
button.Layout(gtx)
}),
)
@@ -146,7 +148,9 @@ func (b IconButtonStyle) Layout(gtx *layout.Context, button *widget.Button) {
Size: image.Point{X: size, Y: size},
}
})
pointer.Ellipse(image.Rectangle{Max: gtx.Dimensions.Size}).Add(gtx.Ops)
}),
layout.Expanded(func() {
pointer.Ellipse(image.Rectangle{Max: gtx.Constraints.Min()}).Add(gtx.Ops)
button.Layout(gtx)
}),
)