refactor(tracker/gioui): Surface is given relative Height, not Gray

This commit is contained in:
5684185+vsariola@users.noreply.github.com
2025-11-02 15:52:51 +02:00
parent 3495d91a4a
commit fa9654d311
8 changed files with 31 additions and 28 deletions

View File

@ -9,25 +9,26 @@ import (
)
type Surface struct {
Gray int
Inset layout.Inset
Focus bool
Height int
Inset layout.Inset
Focus bool
}
func (s Surface) Layout(gtx C, widget layout.Widget) D {
return layout.Background{}.Layout(gtx,
func(gtx C) D {
gray := s.Gray
if s.Focus {
gray += 8
}
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 {
return s.Inset.Layout(gtx, widget)
},
)
t := TrackerFromContext(gtx)
t.surfaceHeight += s.Height
bg := func(gtx C) D {
gray := s.Height * 8
if s.Focus {
gray += 8
}
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}
}
fg := func(gtx C) D { return s.Inset.Layout(gtx, widget) }
dims := layout.Background{}.Layout(gtx, bg, fg)
t.surfaceHeight -= s.Height
return dims
}