-
Notifications
You must be signed in to change notification settings - Fork 0
/
textbox.go
60 lines (49 loc) · 1.53 KB
/
textbox.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
package newt
/*
#cgo pkg-config: libnewt
#cgo LDFLAGS: -lnewt
#include <stdio.h>
#include <stdlib.h>
#include <newt.h>
*/
import "C"
import (
"unsafe"
)
func TextboxReflowed(left, top int, text string, width, flexDown, flexUp, flags int) Component {
t := C.CString(text)
defer C.free(unsafe.Pointer(t))
var c Component
c.c = C.newtTextboxReflowed(C.int(left), C.int(top), t, C.int(width), C.int(flexDown), C.int(flexUp), C.int(flags))
c.t = GRID_COMPONENT
return c
}
func Textbox(left, top, width, height, flags int) Component {
var c Component
c.c = C.newtTextbox(C.int(left), C.int(top), C.int(width), C.int(height), C.int(flags))
c.t = GRID_COMPONENT
return c
}
func TextboxSetText(c Component, text string) {
t := C.CString(text)
defer C.free(unsafe.Pointer(t))
C.newtTextboxSetText(c.c, t)
}
func TextboxSetHeight(c Component, height int) {
C.newtTextboxSetHeight(c.c, C.int(height))
}
func TextboxGetNumLines(c Component) int {
return int(C.newtTextboxGetNumLines(c.c))
}
func TextboxSetColors(c Component, normal, active int) {
C.newtTextboxSetColors(c.c, C.int(normal), C.int(active))
}
func ReflowText(text string, width, flexDown, flexUp int) (string, int, int) {
t := C.CString(text)
defer C.free(unsafe.Pointer(t))
var actualWidth, actualHeight C.int
r := C.newtReflowText(t, C.int(width), C.int(flexDown), C.int(flexUp), &actualWidth, &actualHeight)
defer C.free(unsafe.Pointer(r))
s := C.GoString(r)
return s, int(actualWidth), int(actualHeight)
}