From 78963bdaae54f14b1e79bbe1a370a0738a8aa4b6 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Mon, 21 Oct 2019 09:20:17 +0200 Subject: [PATCH] widget/material: add and use Icon.Layout method Signed-off-by: Elias Naur --- widget/material/button.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/widget/material/button.go b/widget/material/button.go index 37ce7c70..c8262ac7 100644 --- a/widget/material/button.go +++ b/widget/material/button.go @@ -112,13 +112,7 @@ func (b IconButton) Layout(gtx *layout.Context, button *widget.Button) { layout.UniformInset(b.Padding).Layout(gtx, func() { size := gtx.Px(b.Size) - gtx.Px(b.Padding) if b.Icon != nil { - ico := b.Icon.image(size) - ico.Add(gtx.Ops) - paint.PaintOp{ - Rect: f32.Rectangle{ - Max: toPointF(ico.Size()), - }, - }.Add(gtx.Ops) + b.Icon.Layout(gtx, unit.Px(float32(size))) } gtx.Dimensions = layout.Dimensions{ Size: image.Point{X: size, Y: size}, @@ -147,6 +141,16 @@ func (b IconButton) Layout(gtx *layout.Context, button *widget.Button) { st.Layout(gtx, bg, ico) } +func (ic *Icon) Layout(gtx *layout.Context, sz unit.Value) { + ico := ic.image(gtx.Px(sz)) + ico.Add(gtx.Ops) + paint.PaintOp{ + Rect: f32.Rectangle{ + Max: toPointF(ico.Size()), + }, + }.Add(gtx.Ops) +} + func (ic *Icon) image(sz int) paint.ImageOp { if sz == ic.imgSize { return ic.op