Files
sointu/tracker/gioui/surface.go
2025-11-02 15:52:51 +02:00

35 lines
743 B
Go

package gioui
import (
"image/color"
"gioui.org/layout"
"gioui.org/op/clip"
"gioui.org/op/paint"
)
type Surface struct {
Height int
Inset layout.Inset
Focus bool
}
func (s Surface) Layout(gtx C, widget layout.Widget) D {
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
}