summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2018-08-24 21:47:02 -0400
committerPietro Gagliardi <[email protected]>2018-08-24 21:47:02 -0400
commitb74862a0b92a626774efa32c5acb6c88133803ee (patch)
tree1a19f3e91890f3e211ce60cc643f11dc4b89d35f
parent0a17df91fc4545617ecd0785db82cde14da5a9dc (diff)
Started TableModel: converted TableValue.
-rw-r--r--tablemodel.go101
1 files changed, 101 insertions, 0 deletions
diff --git a/tablemodel.go b/tablemodel.go
new file mode 100644
index 0000000..181388e
--- /dev/null
+++ b/tablemodel.go
@@ -0,0 +1,101 @@
+// 24 august 2018
+
+package ui
+
+// #include <stdlib.h>
+// #include "ui.h"
+// #include "util.h"
+// extern int doTableModelNumColumns(uiTableModelHandler *, uiTableModel *);
+// extern uiTableValueType doTableModelColumnType(uiTableModelHandler *, uiTableModel *, int);
+// extern int doTableModelNumRows(uiTableModelHandler *, uiTableModel *);
+// extern uiTableValue *doTableModelCellValue(uiTableModelHandler *mh, uiTableModel *m, int row, int column);
+// extern void doTableModelSetCellValue(uiTableModelHandler *, uiTableModel *, int, int, const uiTableValue *);
+// static inline uiTableModelHandler *allocTableModelHandler(void)
+// {
+// uiTableModelHandler *mh;
+//
+// mh = (uiTableModelHandler *) pkguiAlloc(sizeof (uiTableModelHandler));
+// mh->NumColumns = doTableModelNumColumns;
+// mh->ColumnType = doTableModelColumnType;
+// mh->NumRows = doTableModelNumRows;
+// mh->CellValue = doTableModelCellValue;
+// mh->SetCellValue = doTableModelSetCellValue;
+// return mh;
+// }
+// static inline void freeTableModelHandler(uiTableModelHandler *mh)
+// {
+// free(mh);
+// }
+import "C"
+
+// TableValue is a type that represents a piece of data that can come
+// out of a TableModel.
+type TableValue interface {
+ toLibui() *C.uiTableValue
+}
+
+// TableString is a TableValue that stores a string. TableString is
+// used for displaying text in a Table.
+type TableString string
+
+func (s TableString) toLibui() *C.uiTableValue {
+ cs := C.CString(string(s))
+ defer freestr(cs)
+ return C.uiNewTableValueString(cs)
+}
+
+// TableImage is a TableValue that represents an Image. Ownership
+// of the Image is not copied; you must keep it alive alongside the
+// TableImage.
+type TableImage struct {
+ I *Image
+}
+
+func (i TableImage) toLibui() *C.uiTableValue {
+ return C.uiNewTableValueImage(i.I.i)
+}
+
+// TableInt is a TableValue that stores integers. These are used for
+// progressbars. Due to current limitations of libui, they also
+// represent checkbox states, via TableFalse and TableTrue.
+type TableInt int
+
+// TableFalse and TableTrue are the Boolean constants for TableInt.
+const (
+ TableFalse TableInt = 0
+ TableTrue TableInt = 1
+)
+
+func (i TableInt) toLibui() *C.uiTableValue {
+ return C.uiNewTableValueInt(C.int(i))
+}
+
+// TableColor is a TableValue that represents a color.
+type TableColor struct {
+ R float64
+ G float64
+ B float64
+ A float64
+}
+
+func (c TableColor) toLibui() *C.uiTableValue {
+ return C.uiNewTableValueColor(C.double(c.R), C.double(c.G), C.double(c.B), C.double(c.A))
+}
+
+func tableValueFromLibui(value *C.uiTableValue) TableValue {
+ if value == nil {
+ return nil
+ }
+ switch C.uiTableValueGetType(value) {
+ case C.uiTableValueTypeString:
+ cs := C.uiTableValueString(value)
+ return TableString(C.GoString(cs))
+ case C.uiTableValueTypeImage:
+ panic("TODO")
+ case C.uiTableValueTypeInt:
+ return TableInt(C.uiTableValueInt(value))
+ case C.uiTableValueTypeColor:
+ panic("TODO")
+ }
+ panic("unreachable")
+}