about summary refs log tree commit diff stats
path: root/subx/examples/ex4
diff options
context:
space:
mode:
Diffstat (limited to 'subx/examples/ex4')
0 files changed, 0 insertions, 0 deletions
5.2&id=67fb0938a66605a0b6a837005804637b348b250d'>67fb093 ^
b360cca ^
67fb093 ^










f3158b3 ^
67fb093 ^







67fb093 ^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44








                                         




                                                                                   

                                                                           


                                                                                   

                                                                                        
                                                  










                                                                                          
                               







                                                                             

                             
package widgets

import (
	"git.sr.ht/~sircmpwn/aerc/lib/ui"
	"git.sr.ht/~sircmpwn/aerc/models"
)

type HeaderLayout [][]string

type HeaderLayoutFilter struct {
	layout HeaderLayout
	keep   func(msg *models.MessageInfo, header string) bool // filter criteria
}

// forMessage returns a filtered header layout, removing rows whose headers
// do not appear in the provided message.
func (filter HeaderLayoutFilter) forMessage(msg *models.MessageInfo) HeaderLayout {
	result := make(HeaderLayout, 0, len(filter.layout))
	for _, row := range filter.layout {
		// To preserve layout alignment, only hide rows if all columns are empty
		for _, col := range row {
			if filter.keep(msg, col) {
				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) {
	rowCount := len(layout)
	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
}