summaryrefslogtreecommitdiff
path: root/prev/button_darwin.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2015-12-11 20:37:59 -0500
committerPietro Gagliardi <[email protected]>2015-12-11 20:37:59 -0500
commitf8e3f12ab02b528f2a05a4f713d7af7ea8e44b42 (patch)
tree82dedf4d37f0f6d31e88ebb2ca1ce6499dead261 /prev/button_darwin.go
parente34c561ed5bedeb180437ec165882b98d70d38c1 (diff)
LET'S GET THIS FINAL REWRITE EVER STARTED
Diffstat (limited to 'prev/button_darwin.go')
-rw-r--r--prev/button_darwin.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/prev/button_darwin.go b/prev/button_darwin.go
new file mode 100644
index 0000000..1a0cd1b
--- /dev/null
+++ b/prev/button_darwin.go
@@ -0,0 +1,47 @@
+// 16 july 2014
+
+package ui
+
+import (
+ "unsafe"
+)
+
+// #include "objc_darwin.h"
+import "C"
+
+type button struct {
+ *controlSingleObject
+ clicked *event
+}
+
+func newButton(text string) *button {
+ ctext := C.CString(text)
+ defer C.free(unsafe.Pointer(ctext))
+ b := &button{
+ controlSingleObject: newControlSingleObject(C.newButton()),
+ clicked: newEvent(),
+ }
+ C.buttonSetText(b.id, ctext)
+ C.buttonSetDelegate(b.id, unsafe.Pointer(b))
+ return b
+}
+
+func (b *button) OnClicked(e func()) {
+ b.clicked.set(e)
+}
+
+func (b *button) Text() string {
+ return C.GoString(C.buttonText(b.id))
+}
+
+func (b *button) SetText(text string) {
+ ctext := C.CString(text)
+ defer C.free(unsafe.Pointer(ctext))
+ C.buttonSetText(b.id, ctext)
+}
+
+//export buttonClicked
+func buttonClicked(xb unsafe.Pointer) {
+ b := (*button)(unsafe.Pointer(xb))
+ b.clicked.fire()
+}