From 20821c26eb32b4f5772cf3e2ba13d36d424731c3 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 26 Jun 2014 21:54:14 -0400 Subject: [PATCH] Implemented Checkbox.SetChecked() on Mac OS X and updated the README. --- README.md | 5 +++-- objc_darwin.h | 1 + sysdata_darwin.go | 10 ++++++++++ sysdata_darwin.m | 10 ++++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4de00a4..ff8f5f4 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,9 @@ Woah, lots of attention! Thanks! ## Updates - **26 June 2014** - - Controls in Windows can now be spaced apart more naturally. Call `w.SetSpaced(true)` to opt in. **Whether this will remain opt-in or whether the name will change is still unknown at this point.** - - There's a new function `Layout()` which provides high-level layout creation. The function was written by [boppreh](https://github.com/boppreh) and details can be found [here](https://github.com/andlabs/ui/pull/19). **Whether this function will stay in the main package or be moved to a subpackage is still unknown.** +-- Controls in Windows can now be spaced apart more naturally. Call `w.SetSpaced(true)` to opt in. **Whether this will remain opt-in or whether the name will change is still unknown at this point.** +-- There's a new function `Layout()` which provides high-level layout creation. The function was written by [boppreh](https://github.com/boppreh) and details can be found [here](https://github.com/andlabs/ui/pull/19). **Whether this function will stay in the main package or be moved to a subpackage is still unknown.** +-- There is now `Checkbox.SetChecked()` to set the check state of a Checkbox programmatically. - **25 June 2014**
Labels by default now align themselves relative to the control they are next to. There is a new function `NewStandaloneLabel()` which returns a label whose text is aligned to the top-left corner of the alloted space regardless. diff --git a/objc_darwin.h b/objc_darwin.h index 87acea2..22bafb1 100644 --- a/objc_darwin.h +++ b/objc_darwin.h @@ -123,6 +123,7 @@ extern void windowSetContentSize(id, intptr_t, intptr_t); extern void setProgress(id, intptr_t); extern void setAreaSize(id, intptr_t, intptr_t); extern void center(id); +extern void setCheckboxChecked(id, BOOL); /* combobox_darwin.m */ extern id makeCombobox(BOOL); diff --git a/sysdata_darwin.go b/sysdata_darwin.go index 26bcd98..48b7d44 100644 --- a/sysdata_darwin.go +++ b/sysdata_darwin.go @@ -422,3 +422,13 @@ func (s *sysData) center() { } <-ret } + +func (s *sysData) setChecked(checked bool) { + ret := make(chan struct{}) + defer close(ret) + uitask <- func() { + C.setCheckboxChecked(s.id, toBOOL(checked)) + ret <- struct{}{} + } + <-ret +} diff --git a/sysdata_darwin.m b/sysdata_darwin.m index 1119255..fc1f270 100644 --- a/sysdata_darwin.m +++ b/sysdata_darwin.m @@ -228,3 +228,13 @@ void center(id w) { [toNSWindow(w) center]; } + +void setCheckboxChecked(id checkbox, BOOL check) +{ + // -[NSButton setState:] takes a NSInteger but the state constants are NSCellStateValue which is NSUInteger (despite NSMixedState being -1); let's play it safe here + if (check) { + [toNSButton(checkbox) setState:NSOnState]; + return; + } + [toNSButton(checkbox) setState:NSOffState]; +}