Debian Codegraph @

app/headerlayout.go

raw
1 package app
2
3 import (
4 "git.sr.ht/~rjarry/aerc/lib/ui"
5 "git.sr.ht/~rjarry/aerc/models"
6 )
7
8 type HeaderLayout [][]string
9
10 type HeaderLayoutFilter struct {
11 layout HeaderLayout
12 keep func(msg *models.MessageInfo, header string) bool // filter criteria
13 }
14
15 // forMessage returns a filtered header layout, removing rows whose headers
16 // do not appear in the provided message.
17 func (filter HeaderLayoutFilter) forMessage(msg *models.MessageInfo) HeaderLayout {
18 result := make(HeaderLayout, 0, len(filter.layout))
19 for _, row := range filter.layout {
20 // To preserve layout alignment, only hide rows if all columns are empty
21 for _, col := range row {
22 if filter.keep(msg, col) {
23 result = append(result, row)
24 break
25 }
26 }
27 }
28 return result
29 }
30
31 // grid builds a ui grid, populating each cell by calling a callback function
32 // with the current header string.
33 func (layout HeaderLayout) grid(cb func(string) ui.Drawable) (grid *ui.Grid, height int) {
34 rowCount := len(layout)
35 grid = ui.MakeGrid(rowCount, 1, ui.SIZE_EXACT, ui.SIZE_WEIGHT)
36 for i, cols := range layout {
37 r := ui.MakeGrid(1, len(cols), ui.SIZE_EXACT, ui.SIZE_WEIGHT)
38 for j, col := range cols {
39 r.AddChild(cb(col)).At(0, j)
40 }
41 grid.AddChild(r).At(i, 0)
42 }
43 return grid, rowCount
44 }