-
Notifications
You must be signed in to change notification settings - Fork 17
/
textview.go
34 lines (28 loc) · 848 Bytes
/
textview.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
package gocoa
// #cgo CFLAGS: -x objective-c
// #cgo LDFLAGS: -framework Cocoa
// #import "textview.h"
import "C"
import "unsafe"
// TextView - represents a textView control that can trigger actions.
type TextView struct {
textViewPtr C.TextViewPtr
callback func()
}
var textviews []*TextView
// NewTextView - This func is not thread safe.
func NewTextView(x int, y int, width int, height int) *TextView {
textViewID := len(textviews)
textViewPtr := C.TextView_New(C.int(textViewID), C.int(x), C.int(y), C.int(width), C.int(height))
tv := &TextView{
textViewPtr: textViewPtr,
}
textviews = append(textviews, tv)
return tv
}
// SetText sets the text of the text view
func (textview *TextView) SetText(text string) {
cText := C.CString(text)
defer C.free(unsafe.Pointer(cText))
C.TextView_SetText(textview.textViewPtr, cText)
}