widget/material: draw button to max width with ButtonLayout

This patch allows support to draw button to maximum width using ButtonLayout.
This commit is contained in:
metaclips
2020-03-25 16:16:53 +01:00
committed by Elias Naur
parent 43df9f2677
commit f7a23ad46a
+4
View File
@@ -91,6 +91,8 @@ func (b Button) Layout(gtx *layout.Context, button *widget.Button) {
}
func (b ButtonLayout) Layout(gtx *layout.Context, button *widget.Button, w layout.Widget) {
hmin := gtx.Constraints.Width.Min
vmin := gtx.Constraints.Height.Min
layout.Stack{Alignment: layout.Center}.Layout(gtx,
layout.Expanded(func() {
rr := float32(gtx.Px(b.CornerRadius))
@@ -107,6 +109,8 @@ func (b ButtonLayout) Layout(gtx *layout.Context, button *widget.Button, w layou
}
}),
layout.Stacked(func() {
gtx.Constraints.Width.Min = hmin
gtx.Constraints.Height.Min = vmin
layout.Center.Layout(gtx, func() {
b.Inset.Layout(gtx, func() {
paint.ColorOp{Color: b.Color}.Add(gtx.Ops)