From 300835a1b45b0b59951baa28e69e886aa72fc38f Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 22 Jul 2014 23:32:32 -0400 Subject: Implemented Checkbox on Mac OS X. Also untested; will test next. --- redo/controls_darwin.go | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'redo/controls_darwin.go') diff --git a/redo/controls_darwin.go b/redo/controls_darwin.go index 6d5edf8..9fef658 100644 --- a/redo/controls_darwin.go +++ b/redo/controls_darwin.go @@ -43,17 +43,22 @@ type button struct { clicked *event } -func newButton(text string) *button { +func finishNewButton(id C.id, text string) *button { ctext := C.CString(text) defer C.free(unsafe.Pointer(ctext)) b := &button{ - widgetbase: newWidget(C.newButton(ctext)), + widgetbase: newWidget(id), clicked: newEvent(), } + C.buttonSetText(b.id, ctext) C.buttonSetDelegate(b.id, unsafe.Pointer(b)) return b } +func newButton(text string) *button { + return finishNewButton(C.newButton(), text) +} + func (b *button) OnClicked(e func()) { b.clicked.set(e) } @@ -74,3 +79,24 @@ func (b *button) SetText(text string) { defer C.free(unsafe.Pointer(ctext)) C.buttonSetText(b.id, ctext) } + +type checkbox struct { + *button +} + +func newCheckbox(text string) *checkbox { + return &checkbox{ + button: finishNewButton(C.newCheckbox(), text), + } +} + +// we don't need to define our own event here; we can just reuse Button's +// (it's all target-action anyway) + +type (c *checkbox) Checked() bool { + return fromBOOL(C.checkboxChecked(c.id)) +} + +type (c *checkbox) SetChecked(checked bool) { + C.checkboxSetChecked(c.id, toBOOL(checked)) +} -- cgit v1.2.3