mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
widget/material: use cosntraints for setting pointer hit areas
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
}),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user