From b8cf70e8e9fc1f94a0e3a43bdf5fc3290cd61f17 Mon Sep 17 00:00:00 2001 From: "5684185+vsariola@users.noreply.github.com" <5684185+vsariola@users.noreply.github.com> Date: Tue, 24 Jun 2025 20:43:48 +0300 Subject: [PATCH] refactor(tracker/gioui): use min(max(... instead of ifs --- tracker/gioui/surface.go | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/tracker/gioui/surface.go b/tracker/gioui/surface.go index ad84917..ae52cfd 100644 --- a/tracker/gioui/surface.go +++ b/tracker/gioui/surface.go @@ -17,22 +17,13 @@ type Surface struct { func (s Surface) Layout(gtx C, widget layout.Widget) D { return layout.Background{}.Layout(gtx, func(gtx C) D { - grayInt := s.Gray + gray := s.Gray if s.Focus { - grayInt += 8 + gray += 8 } - var grayUint8 uint8 - if grayInt < 0 { - grayUint8 = 0 - } else if grayInt > 255 { - grayUint8 = 255 - } else { - grayUint8 = uint8(grayInt) - } - color := color.NRGBA{R: grayUint8, G: grayUint8, B: grayUint8, A: 255} - paint.FillShape(gtx.Ops, color, clip.Rect{ - Max: gtx.Constraints.Min, - }.Op()) + gray8 := uint8(min(max(gray, 0), 255)) + color := color.NRGBA{R: gray8, G: gray8, B: gray8, A: 255} + paint.FillShape(gtx.Ops, color, clip.Rect{Max: gtx.Constraints.Min}.Op()) return D{Size: gtx.Constraints.Min} }, func(gtx C) D {