From 890ebe32940ba605ef7a0a8c6a6cb7609936bf03 Mon Sep 17 00:00:00 2001 From: "5684185+vsariola@users.noreply.github.com" <5684185+vsariola@users.noreply.github.com> Date: Sat, 5 Oct 2024 13:24:31 +0300 Subject: [PATCH] refactor(tracker/gioui): use layout.Background, not layout.Stacked --- tracker/gioui/numericupdown.go | 47 +++++++++++----------------------- 1 file changed, 15 insertions(+), 32 deletions(-) diff --git a/tracker/gioui/numericupdown.go b/tracker/gioui/numericupdown.go index 02dd989..3b788bc 100644 --- a/tracker/gioui/numericupdown.go +++ b/tracker/gioui/numericupdown.go @@ -113,49 +113,32 @@ func (s *NumericUpDownStyle) actualLayout(gtx C) D { func (s *NumericUpDownStyle) button(height int, icon *widget.Icon, delta int, click *gesture.Click) layout.Widget { return func(gtx C) D { - btnWidth := gtx.Dp(s.ButtonWidth) - return layout.Stack{Alignment: layout.Center}.Layout(gtx, - layout.Stacked(func(gtx layout.Context) layout.Dimensions { - //paint.FillShape(gtx.Ops, black, clip.Rect(image.Rect(0, 0, btnWidth, height)).Op()) - return layout.Dimensions{Size: image.Point{X: btnWidth, Y: height}} - }), - layout.Expanded(func(gtx C) D { - size := btnWidth - if height < size { - size = height - } - if size < 1 { - size = 1 - } + width := gtx.Dp(s.ButtonWidth) + return layout.Background{}.Layout(gtx, + func(gtx C) D { if icon != nil { - p := size - if p < 1 { - p = 1 - } - gtx.Constraints = layout.Exact(image.Pt(p, p)) return icon.Layout(gtx, s.IconColor) } - return layout.Dimensions{} - }), - layout.Expanded(func(gtx C) D { + return layout.Dimensions{Size: image.Point{X: width, Y: height}} + }, + func(gtx C) D { + gtx.Constraints = layout.Exact(image.Pt(width, height)) return s.layoutClick(gtx, delta, click) - }), - ) + }) } } func (s *NumericUpDownStyle) layoutText(gtx C) D { - return layout.Stack{Alignment: layout.Center}.Layout(gtx, - layout.Stacked(func(gtx C) D { + return layout.Background{}.Layout(gtx, + func(gtx C) D { paint.FillShape(gtx.Ops, s.BackgroundColor, clip.Rect(image.Rect(0, 0, gtx.Constraints.Max.X, gtx.Constraints.Max.Y)).Op()) - return layout.Dimensions{Size: gtx.Constraints.Max} - }), - layout.Expanded(func(gtx layout.Context) layout.Dimensions { paint.ColorOp{Color: s.Color}.Add(gtx.Ops) return widget.Label{Alignment: text.Middle}.Layout(gtx, &s.shaper, s.Font, s.TextSize, fmt.Sprintf("%v", s.NumberInput.Int.Value()), op.CallOp{}) - }), - layout.Expanded(s.layoutDrag), - ) + }, + func(gtx C) D { + gtx.Constraints.Min = gtx.Constraints.Max + return s.layoutDrag(gtx) + }) } func (s *NumericUpDownStyle) layoutDrag(gtx layout.Context) layout.Dimensions {