diff options
| author | Pietro Gagliardi <[email protected]> | 2014-07-16 13:25:09 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-07-16 13:25:09 -0400 |
| commit | 1953f2d748a097e7a0e6ecfd2a2db2acf5fbca10 (patch) | |
| tree | 006a71c97602608a54b11baa14b5948e6ca8321d /redo/controls_darwin.go | |
| parent | d154a2d74d01be34561b2959864ce9302043c27f (diff) | |
Added Button and control adding to the Mac OS X backend.
Diffstat (limited to 'redo/controls_darwin.go')
| -rw-r--r-- | redo/controls_darwin.go | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/redo/controls_darwin.go b/redo/controls_darwin.go new file mode 100644 index 0000000..91dcb65 --- /dev/null +++ b/redo/controls_darwin.go @@ -0,0 +1,92 @@ +// 16 july 2014 + +package ui + +import ( + "unsafe" +) + +// #include "objc_darwin.h" +import "C" + +// TODO move to common_darwin.go +func toBOOL(b bool) C.BOOL { + if b == true { + return C.YES + } + return C.NO +} + +type widgetbase struct { + id C.id + parentw *window + floating bool +} + +func newWidget(id C.id) *widgetbase { + return &widgetbase{ + id: id, + } +} + +// these few methods are embedded by all the various Controls since they all will do the same thing + +func (w *widgetbase) unparent() { + if w.parentw != nil { + C.unparent(w.id) + w.floating = true + w.parentw = nil + } +} + +func (w *widgetbase) parent(win *window) { + C.parent(w.id, win.id, toBOOL(w.floating)) + w.floating = false + w.parentw = win +} + +type button struct { + *widgetbase +} + +func newButton(text string) *Request { + c := make(chan interface{}) + return &Request{ + op: func() { + ctext := C.CString(text) + defer C.free(unsafe.Pointer(ctext)) + c <- &button{ + widgetbase: newWidget(C.newButton(ctext)), + } + }, + resp: c, + } +} + +func (b *button) OnClicked(e func(c Doer)) *Request { + // TODO + return nil +} + +func (b *button) Text() *Request { + c := make(chan interface{}) + return &Request{ + op: func() { + c <- C.GoString(C.buttonText(b.id)) + }, + resp: c, + } +} + +func (b *button) SetText(text string) *Request { + c := make(chan interface{}) + return &Request{ + op: func() { + ctext := C.CString(text) + defer C.free(unsafe.Pointer(ctext)) + C.buttonSetText(b.id, ctext) + c <- struct{}{} + }, + resp: c, + } +} |
