-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrid.go
132 lines (110 loc) · 3.42 KB
/
grid.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
package newt
/*
#cgo pkg-config: libnewt
#cgo LDFLAGS: -lnewt
#include <stdio.h>
#include <stdlib.h>
#include <newt.h>
*/
import "C"
import (
"unsafe"
)
func CreateGrid(cols, rows int) Component {
var c Component
c.g = C.newtCreateGrid(C.int(cols), C.int(rows))
c.t = GRID_SUBGRID
return c
}
func stackem(isVert, close1 bool, comps ...Component) Component {
num := len(comps)
var grid Component
if isVert {
grid = CreateGrid(1, num)
} else {
grid = CreateGrid(num, 1)
}
for i, v := range comps {
var row, col, padLeft, padRight int
if isVert {
row = i
col = 0
padLeft = 0
padRight = 0
if !close1 && i != 0 {
padRight = 1
}
} else {
row = 0
col = i
padLeft = 0
padRight = 0
if !close1 && i != 0 {
padLeft = 1
}
}
GridSetField(grid, col, row, v.t, v, padLeft, padRight, 0, 0, 0, 0)
}
return grid
}
func GridVStacked(comps ...Component) Component {
return stackem(true, false, comps...)
}
func GridVCloseStacked(comps ...Component) Component {
return stackem(true, true, comps...)
}
func GridHStacked(comps ...Component) Component {
return stackem(false, false, comps...)
}
func GridHCloseStacked(comps ...Component) Component {
return stackem(false, true, comps...)
}
func GridBasicWindow(text, middle, buttons Component) Component {
var c Component
c.g = C.newtGridBasicWindow(text.c, middle.g, buttons.g)
c.t = GRID_SUBGRID
return c
}
func GridSimpleWindow(text, middle, buttons Component) Component {
var c Component
c.g = C.newtGridSimpleWindow(text.c, middle.c, buttons.g)
c.t = GRID_SUBGRID
return c
}
func GridSetField(c Component, col, row int, typ uint32, val Component, padLeft, padTop, padRight, padBottom, anchor, flags int) {
switch typ {
case GRID_COMPONENT:
C.newtGridSetField(c.g, C.int(col), C.int(row), typ, unsafe.Pointer(val.c), C.int(padLeft), C.int(padTop), C.int(padRight), C.int(padBottom), C.int(anchor), C.int(flags))
case GRID_SUBGRID:
C.newtGridSetField(c.g, C.int(col), C.int(row), typ, unsafe.Pointer(val.g), C.int(padLeft), C.int(padTop), C.int(padRight), C.int(padBottom), C.int(anchor), C.int(flags))
case GRID_EMPTY:
C.newtGridSetField(c.g, C.int(col), C.int(row), typ, nil, C.int(padLeft), C.int(padTop), C.int(padRight), C.int(padBottom), C.int(anchor), C.int(flags))
}
}
func GridPlace(c Component, left, top int) {
C.newtGridPlace(c.g, C.int(left), C.int(top))
}
func GridDestroy(c Component, recurse int) {
C.newtGridFree(c.g, C.int(recurse))
}
func GridFree(c Component, recurse int) {
C.newtGridFree(c.g, C.int(recurse))
}
func GridGetSize(c Component) (int, int) {
var width, height C.int
C.newtGridGetSize(c.g, &width, &height)
return int(width), int(height)
}
func GridWrappedWindow(c Component, title string) {
t := C.CString(title)
defer C.free(unsafe.Pointer(t))
C.newtGridWrappedWindow(c.g, t)
}
func GridWrappedWindowAt(c Component, title string, left, top int) {
t := C.CString(title)
defer C.free(unsafe.Pointer(t))
C.newtGridWrappedWindowAt(c.g, t, C.int(left), C.int(top))
}
func GridAddComponentsToForm(grid, form Component, recurse int) {
C.newtGridAddComponentsToForm(grid.g, form.c, C.int(recurse))
}