-
Notifications
You must be signed in to change notification settings - Fork 17
/
textfield.go
123 lines (103 loc) · 3.54 KB
/
textfield.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
package gocoa
// #cgo CFLAGS: -x objective-c
// #cgo LDFLAGS: -framework Cocoa
// #import "textfield.h"
import "C"
import (
"fmt"
"unsafe"
)
// TextField -Button represents a button control that can trigger actions.
type TextField struct {
textFieldPtr C.TextFieldPtr
callback func()
}
var textfields []*TextField
// NewTextField - This func is not thread safe.
func NewTextField(x int, y int, width int, height int) *TextField {
textFieldID := len(textfields)
textFieldPtr := C.TextField_New(C.int(textFieldID), C.int(x), C.int(y), C.int(width), C.int(height))
tf := &TextField{
textFieldPtr: textFieldPtr,
}
textfields = append(textfields, tf)
return tf
}
// StringValue - returns the string value of the text field
func (textField *TextField) StringValue() string {
return C.GoString(C.TextField_StringValue(textField.textFieldPtr))
}
// SetStringValue sets the string value of the text field
func (textField *TextField) SetStringValue(text string) {
cText := C.CString(text)
defer C.free(unsafe.Pointer(cText))
C.TextField_SetStringValue(textField.textFieldPtr, cText)
}
func (textField *TextField) Enabled() bool {
return C.TextField_Enabled(textField.textFieldPtr) == 1
}
// SetEnabled sets the enabled value of the text field. CANNOT BE CHANGED AT RUNTIME
func (textField *TextField) SetEnabled(enabled bool) {
if enabled {
C.TextField_SetEnabled(textField.textFieldPtr, 1)
} else {
C.TextField_SetEnabled(textField.textFieldPtr, 0)
}
}
func (textField *TextField) Editable() bool {
return C.TextField_Editable(textField.textFieldPtr) == 1
}
func (textField *TextField) SetEditable(editable bool) {
if editable {
C.TextField_SetEditable(textField.textFieldPtr, 1)
} else {
C.TextField_SetEditable(textField.textFieldPtr, 0)
}
}
func (textField *TextField) SetFontFamily(fontFamily string) {
cText := C.CString(fontFamily)
defer C.free(unsafe.Pointer(cText))
C.TextField_SetFontFamily(textField.textFieldPtr, cText)
}
func (textField *TextField) SetFontSize(fontSize int) {
C.TextField_SetFontSize(textField.textFieldPtr, C.int(fontSize))
}
func (textField *TextField) SetColor(hexRGBA string) {
var r, g, b, a = 0, 0, 0, 0
fmt.Sscanf(hexRGBA, "#%02x%02x%02x%02x", &r, &g, &b, &a)
C.TextField_SetColor(textField.textFieldPtr, C.int(r), C.int(g), C.int(b), C.int(a))
}
func (textField *TextField) SetBackgroundColor(hexRGBA string) {
var r, g, b, a = 0, 0, 0, 0
fmt.Sscanf(hexRGBA, "#%02x%02x%02x%02x", &r, &g, &b, &a)
C.TextField_SetBackgroundColor(textField.textFieldPtr, C.int(r), C.int(g), C.int(b), C.int(a))
}
func (textField *TextField) SetBorderColor(hexRGBA string) {
var r, g, b, a = 0, 0, 0, 0
fmt.Sscanf(hexRGBA, "#%02x%02x%02x%02x", &r, &g, &b, &a)
C.TextField_SetBorderColor(textField.textFieldPtr, C.int(r), C.int(g), C.int(b), C.int(a))
}
func (textField *TextField) SetBorderWidth(borderWidth int) {
C.TextField_SetBorderWidth(textField.textFieldPtr, C.int(borderWidth))
}
func (textField *TextField) SetBezeled(bezeled bool) {
if bezeled {
C.TextField_SetBezeled(textField.textFieldPtr, C.int(1))
} else {
C.TextField_SetBezeled(textField.textFieldPtr, C.int(0))
}
}
func (textField *TextField) SetDrawsBackground(drawsBackground bool) {
if drawsBackground {
C.TextField_SetDrawsBackground(textField.textFieldPtr, C.int(1))
} else {
C.TextField_SetDrawsBackground(textField.textFieldPtr, C.int(0))
}
}
func (textField *TextField) SetSelectable(selectable bool) {
if selectable {
C.TextField_SetSelectable(textField.textFieldPtr, C.int(1))
} else {
C.TextField_SetSelectable(textField.textFieldPtr, C.int(0))
}
}