refactor(tracker/gioui): move element etc. functions away from style

Now the element / fg / bg functions are passed to the actual Layout
function, not first put to the style. This avoids moving of the
element function to heap.
This commit is contained in:
5684185+vsariola@users.noreply.github.com
2025-05-26 22:31:01 +03:00
parent de2e64533d
commit d20a23d57b
6 changed files with 35 additions and 39 deletions

View File

@ -71,12 +71,11 @@ func NewScrollTable(table tracker.Table, vertList, horizList tracker.List) *Scro
return ret
}
func FilledScrollTable(th *Theme, scrollTable *ScrollTable, element func(gtx C, x, y int) D, colTitle, rowTitle, colTitleBg, rowTitleBg func(gtx C, i int) D) ScrollTableStyle {
func FilledScrollTable(th *Theme, scrollTable *ScrollTable) ScrollTableStyle {
return ScrollTableStyle{
RowTitleStyle: FilledDragList(th, scrollTable.RowTitleList, rowTitle, rowTitleBg),
ColTitleStyle: FilledDragList(th, scrollTable.ColTitleList, colTitle, colTitleBg),
RowTitleStyle: FilledDragList(th, scrollTable.RowTitleList),
ColTitleStyle: FilledDragList(th, scrollTable.ColTitleList),
ScrollTable: scrollTable,
element: element,
ScrollBarWidth: unit.Dp(14),
RowTitleWidth: unit.Dp(30),
ColumnTitleHeight: unit.Dp(16),
@ -108,7 +107,7 @@ func (st *ScrollTable) ChildFocused() bool {
return st.ColTitleList.Focused() || st.RowTitleList.Focused()
}
func (s ScrollTableStyle) Layout(gtx C) D {
func (s ScrollTableStyle) Layout(gtx C, element func(gtx C, x, y int) D, colTitle, rowTitle, colTitleBg, rowTitleBg func(gtx C, i int) D) D {
defer clip.Rect(image.Rectangle{Max: gtx.Constraints.Max}).Push(gtx.Ops).Pop()
event.Op(gtx.Ops, s.ScrollTable)
@ -118,11 +117,11 @@ func (s ScrollTableStyle) Layout(gtx C) D {
return Surface{Gray: 24, Focus: s.ScrollTable.Focused() || s.ScrollTable.ChildFocused()}.Layout(gtx, func(gtx C) D {
defer clip.Rect(image.Rect(0, 0, gtx.Constraints.Max.X, gtx.Constraints.Max.Y)).Push(gtx.Ops).Pop()
dims := gtx.Constraints.Max
s.layoutColTitles(gtx, p)
s.layoutRowTitles(gtx, p)
s.layoutColTitles(gtx, p, colTitle, colTitleBg)
s.layoutRowTitles(gtx, p, rowTitle, rowTitleBg)
defer op.Offset(p).Push(gtx.Ops).Pop()
gtx.Constraints = layout.Exact(image.Pt(gtx.Constraints.Max.X-p.X, gtx.Constraints.Max.Y-p.Y))
s.layoutTable(gtx)
s.layoutTable(gtx, element)
s.RowTitleStyle.LayoutScrollBar(gtx)
s.ColTitleStyle.LayoutScrollBar(gtx)
return D{Size: dims}
@ -209,7 +208,7 @@ func (s *ScrollTableStyle) handleEvents(gtx layout.Context, p image.Point) {
}
}
func (s ScrollTableStyle) layoutTable(gtx C) {
func (s ScrollTableStyle) layoutTable(gtx C, element func(gtx C, x, y int) D) {
defer clip.Rect(image.Rectangle{Max: gtx.Constraints.Min}).Push(gtx.Ops).Pop()
if s.ScrollTable.requestFocus {
@ -227,26 +226,26 @@ func (s ScrollTableStyle) layoutTable(gtx C) {
for x := 0; x < colP.Count; x++ {
for y := 0; y < rowP.Count; y++ {
o := op.Offset(image.Pt(cellWidth*x, cellHeight*y)).Push(gtx.Ops)
s.element(gtx, x+colP.First, y+rowP.First)
element(gtx, x+colP.First, y+rowP.First)
o.Pop()
}
}
}
func (s *ScrollTableStyle) layoutRowTitles(gtx C, p image.Point) {
func (s *ScrollTableStyle) layoutRowTitles(gtx C, p image.Point, fg, bg func(gtx C, i int) D) {
defer op.Offset(image.Pt(0, p.Y)).Push(gtx.Ops).Pop()
gtx.Constraints.Min.X = p.X
gtx.Constraints.Max.Y -= p.Y
gtx.Constraints.Min.Y = gtx.Constraints.Max.Y
s.RowTitleStyle.Layout(gtx)
s.RowTitleStyle.Layout(gtx, fg, bg)
}
func (s *ScrollTableStyle) layoutColTitles(gtx C, p image.Point) {
func (s *ScrollTableStyle) layoutColTitles(gtx C, p image.Point, fg, bg func(gtx C, i int) D) {
defer op.Offset(image.Pt(p.X, 0)).Push(gtx.Ops).Pop()
gtx.Constraints.Min.Y = p.Y
gtx.Constraints.Max.X -= p.X
gtx.Constraints.Min.X = gtx.Constraints.Max.X
s.ColTitleStyle.Layout(gtx)
s.ColTitleStyle.Layout(gtx, fg, bg)
}
func (s *ScrollTable) command(gtx C, e key.Event) {