summaryrefslogtreecommitdiff
path: root/BBB_GOFILES/entry.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2018-08-26 09:55:07 -0400
committerPietro Gagliardi <[email protected]>2018-08-26 09:55:07 -0400
commit62ac2527732a01dfa6bd2c9523215c0ba3816641 (patch)
tree84244a69e048f79e4d9f134c121f4cf581200986 /BBB_GOFILES/entry.go
parenta5a00c644c08a6e0f52740c3f2a280977929a285 (diff)
Moved all the Go files out of the way again, this time so we can migrate them to more proper cgo usage.
Diffstat (limited to 'BBB_GOFILES/entry.go')
-rw-r--r--BBB_GOFILES/entry.go93
1 files changed, 93 insertions, 0 deletions
diff --git a/BBB_GOFILES/entry.go b/BBB_GOFILES/entry.go
new file mode 100644
index 0000000..52da537
--- /dev/null
+++ b/BBB_GOFILES/entry.go
@@ -0,0 +1,93 @@
+// 12 december 2015
+
+// TODO typing in entry in OS X crashes libui
+// I've had similar issues with checkboxes on libui
+// something's wrong with NSMapTable
+
+package ui
+
+import (
+ "unsafe"
+)
+
+// #include "ui.h"
+// extern void doEntryOnChanged(uiEntry *, void *);
+// // see golang/go#19835
+// typedef void (*entryCallback)(uiEntry *, void *);
+import "C"
+
+// Entry is a Control that represents a space that the user can
+// type a single line of text into.
+type Entry struct {
+ ControlBase
+ e *C.uiEntry
+ onChanged func(*Entry)
+}
+
+func finishNewEntry(ee *C.uiEntry) *Entry {
+ e := new(Entry)
+
+ e.e = ee
+
+ C.uiEntryOnChanged(e.e, C.entryCallback(C.doEntryOnChanged), nil)
+
+ e.ControlBase = NewControlBase(e, uintptr(unsafe.Pointer(e.e)))
+ return e
+}
+
+// NewEntry creates a new Entry.
+func NewEntry() *Entry {
+ return finishNewEntry(C.uiNewEntry())
+}
+
+// NewPasswordEntry creates a new Entry whose contents are
+// visibly obfuscated, suitable for passwords.
+func NewPasswordEntry() *Entry {
+ return finishNewEntry(C.uiNewPasswordEntry())
+}
+
+// NewSearchEntry creates a new Entry suitable for searching with.
+// Changed events may, depending on the system, be delayed
+// with a search Entry, to produce a smoother user experience.
+func NewSearchEntry() *Entry {
+ return finishNewEntry(C.uiNewSearchEntry())
+}
+
+// Text returns the Entry's text.
+func (e *Entry) Text() string {
+ ctext := C.uiEntryText(e.e)
+ text := C.GoString(ctext)
+ C.uiFreeText(ctext)
+ return text
+}
+
+// SetText sets the Entry's text to text.
+func (e *Entry) SetText(text string) {
+ ctext := C.CString(text)
+ C.uiEntrySetText(e.e, ctext)
+ freestr(ctext)
+}
+
+// OnChanged registers f to be run when the user makes a change to
+// the Entry. Only one function can be registered at a time.
+func (e *Entry) OnChanged(f func(*Entry)) {
+ e.onChanged = f
+}
+
+//export doEntryOnChanged
+func doEntryOnChanged(ee *C.uiEntry, data unsafe.Pointer) {
+ e := ControlFromLibui(uintptr(unsafe.Pointer(ee))).(*Entry)
+ if e.onChanged != nil {
+ e.onChanged(e)
+ }
+}
+
+// ReadOnly returns whether the Entry can be changed.
+func (e *Entry) ReadOnly() bool {
+ return tobool(C.uiEntryReadOnly(e.e))
+}
+
+// SetReadOnly sets whether the Entry can be changed.
+func (e *Entry) SetReadOnly(ro bool) {
+ C.uiEntrySetReadOnly(e.e, frombool(ro))
+}