-
Notifications
You must be signed in to change notification settings - Fork 648
/
table.go
157 lines (137 loc) · 5.75 KB
/
table.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// 26 august 2018
package ui
import (
"unsafe"
)
// #include "pkgui.h"
import "C"
// TableModelColumnNeverEditable and
// TableModelColumnAlwaysEditable are the value of an editable
// model column parameter to one of the Table create column
// functions; if used, that jparticular Table colum is not editable
// by the user and always editable by the user, respectively.
const (
TableModelColumnNeverEditable = -1
TableModelColumnAlwaysEditable = -2
)
// TableTextColumnOptionalParams are the optional parameters
// that control the appearance of the text column of a Table.
type TableTextColumnOptionalParams struct {
// ColorModelColumn is the model column containing the
// text color of this Table column's text, or -1 to use the
// default color.
//
// If CellValue for this column for any cell returns nil, that
// cell will also use the default text color.
ColorModelColumn int
}
func (p *TableTextColumnOptionalParams) toLibui() *C.uiTableTextColumnOptionalParams {
if p == nil {
return nil
}
cp := C.pkguiAllocTableTextColumnOptionalParams()
cp.ColorModelColumn = C.int(p.ColorModelColumn)
return cp
}
// TableParams defines the parameters passed to NewTable.
type TableParams struct {
// Model is the TableModel to use for this uiTable.
// This parameter cannot be nil.
Model *TableModel
// RowBackgroundColorModelColumn is a model column
// number that defines the background color used for the
// entire row in the Table, or -1 to use the default color for
// all rows.
//
// If CellValue for this column for any row returns NULL, that
// row will also use the default background color.
RowBackgroundColorModelColumn int
}
func (p *TableParams) toLibui() *C.uiTableParams {
cp := C.pkguiAllocTableParams()
cp.Model = p.Model.m
cp.RowBackgroundColorModelColumn = C.int(p.RowBackgroundColorModelColumn)
return cp
}
// Table is a Control that shows tabular data, allowing users to
// manipulate rows of such data at a time.
type Table struct {
ControlBase
t *C.uiTable
}
// NewTable creates a new Table with the specified parameters.
func NewTable(p *TableParams) *Table {
t := new(Table)
cp := p.toLibui()
t.t = C.uiNewTable(cp)
C.pkguiFreeTableParams(cp)
t.ControlBase = NewControlBase(t, uintptr(unsafe.Pointer(t.t)))
return t
}
// AppendTextColumn appends a text column to t. name is
// displayed in the table header. textModelColumn is where the text
// comes from. If a row is editable according to
// textEditableModelColumn, SetCellValue is called with
// textModelColumn as the column.
func (t *Table) AppendTextColumn(name string, textModelColumn int, textEditableModelColumn int, textParams *TableTextColumnOptionalParams) {
cname := C.CString(name)
defer freestr(cname)
cp := textParams.toLibui()
defer C.pkguiFreeTableTextColumnOptionalParams(cp)
C.uiTableAppendTextColumn(t.t, cname, C.int(textModelColumn), C.int(textEditableModelColumn), cp)
}
// AppendImageColumn appends an image column to t.
// Images are drawn at icon size, appropriate to the pixel density
// of the screen showing the Table.
func (t *Table) AppendImageColumn(name string, imageModelColumn int) {
cname := C.CString(name)
defer freestr(cname)
C.uiTableAppendImageColumn(t.t, cname, C.int(imageModelColumn))
}
// AppendImageTextColumn appends a column to t that
// shows both an image and text.
func (t *Table) AppendImageTextColumn(name string, imageModelColumn int, textModelColumn int, textEditableModelColumn int, textParams *TableTextColumnOptionalParams) {
cname := C.CString(name)
defer freestr(cname)
cp := textParams.toLibui()
defer C.pkguiFreeTableTextColumnOptionalParams(cp)
C.uiTableAppendImageTextColumn(t.t, cname, C.int(imageModelColumn), C.int(textModelColumn), C.int(textEditableModelColumn), cp)
}
// AppendCheckboxColumn appends a column to t that
// contains a checkbox that the user can interact with (assuming the
// checkbox is editable). SetCellValue will be called with
// checkboxModelColumn as the column in this case.
func (t *Table) AppendCheckboxColumn(name string, checkboxModelColumn int, checkboxEditableModelColumn int) {
cname := C.CString(name)
defer freestr(cname)
C.uiTableAppendCheckboxColumn(t.t, cname, C.int(checkboxModelColumn), C.int(checkboxEditableModelColumn))
}
// AppendCheckboxTextColumn appends a column to t
// that contains both a checkbox and text.
func (t *Table) AppendCheckboxTextColumn(name string, checkboxModelColumn int, checkboxEditableModelColumn int, textModelColumn int, textEditableModelColumn int, textParams *TableTextColumnOptionalParams) {
cname := C.CString(name)
defer freestr(cname)
cp := textParams.toLibui()
defer C.pkguiFreeTableTextColumnOptionalParams(cp)
C.uiTableAppendCheckboxTextColumn(t.t, cname, C.int(checkboxModelColumn), C.int(checkboxEditableModelColumn), C.int(textModelColumn), C.int(textEditableModelColumn), cp)
}
// AppendProgressBarColumn appends a column to t
// that displays a progress bar. These columns work like
// ProgressBar: a cell value of 0..100 displays that percentage, and
// a cell value of -1 displays an indeterminate progress bar.
func (t *Table) AppendProgressBarColumn(name string, progressModelColumn int) {
cname := C.CString(name)
defer freestr(cname)
C.uiTableAppendProgressBarColumn(t.t, cname, C.int(progressModelColumn))
}
// AppendButtonColumn appends a column to t
// that shows a button that the user can click on. When the user
// does click on the button, SetCellValue is called with a nil
// value and buttonModelColumn as the column.
// CellValue on buttonModelColumn should return the text to show
// in the button.
func (t *Table) AppendButtonColumn(name string, buttonModelColumn int, buttonClickableModelColumn int) {
cname := C.CString(name)
defer freestr(cname)
C.uiTableAppendButtonColumn(t.t, cname, C.int(buttonModelColumn), C.int(buttonClickableModelColumn))
}