mirror of
https://github.com/vsariola/sointu.git
synced 2025-07-20 05:54:34 -04:00
refactor(tracker/gioui): use min(max(... instead of ifs
This commit is contained in:
parent
e59fbb50cf
commit
b8cf70e8e9
@ -17,22 +17,13 @@ type Surface struct {
|
|||||||
func (s Surface) Layout(gtx C, widget layout.Widget) D {
|
func (s Surface) Layout(gtx C, widget layout.Widget) D {
|
||||||
return layout.Background{}.Layout(gtx,
|
return layout.Background{}.Layout(gtx,
|
||||||
func(gtx C) D {
|
func(gtx C) D {
|
||||||
grayInt := s.Gray
|
gray := s.Gray
|
||||||
if s.Focus {
|
if s.Focus {
|
||||||
grayInt += 8
|
gray += 8
|
||||||
}
|
}
|
||||||
var grayUint8 uint8
|
gray8 := uint8(min(max(gray, 0), 255))
|
||||||
if grayInt < 0 {
|
color := color.NRGBA{R: gray8, G: gray8, B: gray8, A: 255}
|
||||||
grayUint8 = 0
|
paint.FillShape(gtx.Ops, color, clip.Rect{Max: gtx.Constraints.Min}.Op())
|
||||||
} 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())
|
|
||||||
return D{Size: gtx.Constraints.Min}
|
return D{Size: gtx.Constraints.Min}
|
||||||
},
|
},
|
||||||
func(gtx C) D {
|
func(gtx C) D {
|
||||||
|
Reference in New Issue
Block a user