-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtableColumnCheck.go
53 lines (45 loc) · 1.14 KB
/
tableColumnCheck.go
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
45
46
47
48
49
50
51
52
53
package faithtop
import (
"fmt"
"github.com/andlabs/ui"
)
// FTableColumnCheck check box column
type FTableColumnCheck struct {
name string
data map[int]bool
onGetChecked func(r int) bool
onSetChecked func(r int, b bool)
}
func (f *FTableColumnCheck) getName() string {
return f.name
}
func (f *FTableColumnCheck) getTableValue(model *ui.TableModel, r int) ui.TableValue {
if v, ok := f.data[r]; ok {
return tranformBool(v)
}
return tranformBool(f.onGetChecked(r))
}
func (f *FTableColumnCheck) setTableValue(model *ui.TableModel, r int, value ui.TableValue) {
fmt.Println(value.(ui.TableInt))
b := value.(ui.TableInt) == ui.TableTrue
f.data[r] = b
model.RowChanged(r)
f.onSetChecked(r, b)
}
func tranformBool(b bool) ui.TableValue {
if b {
return ui.TableTrue
}
return ui.TableFalse
}
func TableColumnCheck(name string, onGetCheck func(row int) bool, onSetChecked func(row int, b bool)) *FTableColumnCheck {
if onGetCheck == nil || onSetChecked == nil {
panic("nil")
}
return &FTableColumnCheck{
name: name,
onGetChecked: onGetCheck,
onSetChecked: onSetChecked,
data: make(map[int]bool),
}
}