summaryrefslogtreecommitdiff
path: root/AAA_GOFILES/entry.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2018-08-11 16:18:01 -0400
committerPietro Gagliardi <[email protected]>2018-08-11 16:18:01 -0400
commit308e253e0f7873710bf77312d7a12c576aaa9781 (patch)
treefd20704da886ce82a3621ec1502897a8766b11be /AAA_GOFILES/entry.go
parent0f75ebb5fa7a12bd1df26622ed3f5544a9d1d32b (diff)
Moved the existing .go files out of the way and replaced ui.h with the alpha4 ui.h.
Diffstat (limited to 'AAA_GOFILES/entry.go')
-rw-r--r--AAA_GOFILES/entry.go125
1 files changed, 125 insertions, 0 deletions
diff --git a/AAA_GOFILES/entry.go b/AAA_GOFILES/entry.go
new file mode 100644
index 0000000..ee14fc8
--- /dev/null
+++ b/AAA_GOFILES/entry.go
@@ -0,0 +1,125 @@
+// 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 *);
+// static inline void realuiEntryOnChanged(uiEntry *b)
+// {
+// uiEntryOnChanged(b, doEntryOnChanged, NULL);
+// }
+import "C"
+
+// no need to lock this; only the GUI thread can access it
+var entries = make(map[*C.uiEntry]*Entry)
+
+// Entry is a Control that represents a space that the user can
+// type a single line of text into.
+type Entry struct {
+ c *C.uiControl
+ e *C.uiEntry
+
+ onChanged func(*Entry)
+}
+
+// NewEntry creates a new Entry.
+func NewEntry() *Entry {
+ e := new(Entry)
+
+ e.e = C.uiNewEntry()
+ e.c = (*C.uiControl)(unsafe.Pointer(e.e))
+
+ C.realuiEntryOnChanged(e.e)
+ entries[e.e] = e
+
+ return e
+}
+
+// Destroy destroys the Entry.
+func (e *Entry) Destroy() {
+ delete(entries, e.e)
+ C.uiControlDestroy(e.c)
+}
+
+// LibuiControl returns the libui uiControl pointer that backs
+// the Window. This is only used by package ui itself and should
+// not be called by programs.
+func (e *Entry) LibuiControl() uintptr {
+ return uintptr(unsafe.Pointer(e.c))
+}
+
+// Handle returns the OS-level handle associated with this Entry.
+// On Windows this is an HWND of a standard Windows API EDIT
+// class (as provided by Common Controls version 6).
+// On GTK+ this is a pointer to a GtkEntry.
+// On OS X this is a pointer to a NSTextField.
+func (e *Entry) Handle() uintptr {
+ return uintptr(C.uiControlHandle(e.c))
+}
+
+// Show shows the Entry.
+func (e *Entry) Show() {
+ C.uiControlShow(e.c)
+}
+
+// Hide hides the Entry.
+func (e *Entry) Hide() {
+ C.uiControlHide(e.c)
+}
+
+// Enable enables the Entry.
+func (e *Entry) Enable() {
+ C.uiControlEnable(e.c)
+}
+
+// Disable disables the Entry.
+func (e *Entry) Disable() {
+ C.uiControlDisable(e.c)
+}
+
+// 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 := entries[ee]
+ 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))
+}