widget/material: allow button Inset to be customizable

Signed-off-by: Larry Clapp <larry@theclapp.org>
This commit is contained in:
Larry Clapp
2020-02-17 09:29:19 -05:00
committed by Elias Naur
parent ae6161dfb6
commit 0dd77be975
+7 -1
View File
@@ -25,6 +25,7 @@ type Button struct {
TextSize unit.Value TextSize unit.Value
Background color.RGBA Background color.RGBA
CornerRadius unit.Value CornerRadius unit.Value
Inset layout.Inset
shaper text.Shaper shaper text.Shaper
} }
@@ -34,6 +35,7 @@ type IconButton struct {
Icon *Icon Icon *Icon
Size unit.Value Size unit.Value
Padding unit.Value Padding unit.Value
Inset layout.Inset
} }
func (t *Theme) Button(txt string) Button { func (t *Theme) Button(txt string) Button {
@@ -42,6 +44,10 @@ func (t *Theme) Button(txt string) Button {
Color: rgb(0xffffff), Color: rgb(0xffffff),
Background: t.Color.Primary, Background: t.Color.Primary,
TextSize: t.TextSize.Scale(14.0 / 16.0), TextSize: t.TextSize.Scale(14.0 / 16.0),
Inset: layout.Inset{
Top: unit.Dp(10), Bottom: unit.Dp(10),
Left: unit.Dp(12), Right: unit.Dp(12),
},
shaper: t.Shaper, shaper: t.Shaper,
} }
} }
@@ -80,7 +86,7 @@ func (b Button) Layout(gtx *layout.Context, button *widget.Button) {
gtx.Constraints.Width.Min = hmin gtx.Constraints.Width.Min = hmin
gtx.Constraints.Height.Min = vmin gtx.Constraints.Height.Min = vmin
layout.Center.Layout(gtx, func() { layout.Center.Layout(gtx, func() {
layout.Inset{Top: unit.Dp(10), Bottom: unit.Dp(10), Left: unit.Dp(12), Right: unit.Dp(12)}.Layout(gtx, func() { b.Inset.Layout(gtx, func() {
paint.ColorOp{Color: col}.Add(gtx.Ops) paint.ColorOp{Color: col}.Add(gtx.Ops)
widget.Label{}.Layout(gtx, b.shaper, b.Font, b.TextSize, b.Text) widget.Label{}.Layout(gtx, b.shaper, b.Font, b.TextSize, b.Text)
}) })