2019-07-23 01:29:07 +02:00
|
|
|
package widgets
|
|
|
|
|
|
|
|
import (
|
|
|
|
"git.sr.ht/~sircmpwn/aerc/lib/ui"
|
|
|
|
"git.sr.ht/~sircmpwn/aerc/models"
|
|
|
|
)
|
|
|
|
|
|
|
|
type HeaderLayout [][]string
|
|
|
|
|
2019-12-23 12:51:59 +01:00
|
|
|
type HeaderLayoutFilter struct {
|
|
|
|
layout HeaderLayout
|
|
|
|
keep func(msg *models.MessageInfo, header string) bool // filter criteria
|
|
|
|
}
|
|
|
|
|
2019-07-23 01:29:07 +02:00
|
|
|
// forMessage returns a filtered header layout, removing rows whose headers
|
|
|
|
// do not appear in the provided message.
|
2019-12-23 12:51:59 +01:00
|
|
|
func (filter HeaderLayoutFilter) forMessage(msg *models.MessageInfo) HeaderLayout {
|
|
|
|
result := make(HeaderLayout, 0, len(filter.layout))
|
|
|
|
for _, row := range filter.layout {
|
2019-07-23 01:29:07 +02:00
|
|
|
// To preserve layout alignment, only hide rows if all columns are empty
|
|
|
|
for _, col := range row {
|
2019-12-23 12:51:59 +01:00
|
|
|
if filter.keep(msg, col) {
|
2019-07-23 01:29:07 +02:00
|
|
|
result = append(result, row)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
// grid builds a ui grid, populating each cell by calling a callback function
|
|
|
|
// with the current header string.
|
|
|
|
func (layout HeaderLayout) grid(cb func(string) ui.Drawable) (grid *ui.Grid, height int) {
|
2020-03-03 22:20:07 +01:00
|
|
|
rowCount := len(layout)
|
2019-07-23 01:29:07 +02:00
|
|
|
grid = ui.MakeGrid(rowCount, 1, ui.SIZE_EXACT, ui.SIZE_WEIGHT)
|
|
|
|
for i, cols := range layout {
|
|
|
|
r := ui.MakeGrid(1, len(cols), ui.SIZE_EXACT, ui.SIZE_WEIGHT)
|
|
|
|
for j, col := range cols {
|
|
|
|
r.AddChild(cb(col)).At(0, j)
|
|
|
|
}
|
|
|
|
grid.AddChild(r).At(i, 0)
|
|
|
|
}
|
|
|
|
return grid, rowCount
|
|
|
|
}
|