summaryrefslogtreecommitdiff
path: root/checkbox.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-06-30 09:57:44 -0400
committerPietro Gagliardi <[email protected]>2014-06-30 09:57:44 -0400
commit33155f7496a818a1ed83fe49cccb63be7842bc81 (patch)
treebbb14af3d92becf7d5ca5abfb28630a2b413ad93 /checkbox.go
parente032807546a96e6489d18a0e42ced51b7c31a55c (diff)
Reverted everything back to the old API.
Diffstat (limited to 'checkbox.go')
-rw-r--r--checkbox.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/checkbox.go b/checkbox.go
index 1293dfc..934da90 100644
--- a/checkbox.go
+++ b/checkbox.go
@@ -2,8 +2,13 @@
package ui
+import (
+ "sync"
+)
+
// A Checkbox is a clickable square with a label. The square can be either checked or unchecked. Checkboxes start out unchecked.
type Checkbox struct {
+ lock sync.Mutex
created bool
sysData *sysData
initText string
@@ -20,6 +25,9 @@ func NewCheckbox(text string) (c *Checkbox) {
// SetText sets the checkbox's text.
func (c *Checkbox) SetText(text string) {
+ c.lock.Lock()
+ defer c.lock.Unlock()
+
if c.created {
c.sysData.setText(text)
return
@@ -29,6 +37,9 @@ func (c *Checkbox) SetText(text string) {
// Text returns the checkbox's text.
func (c *Checkbox) Text() string {
+ c.lock.Lock()
+ defer c.lock.Unlock()
+
if c.created {
return c.sysData.text()
}
@@ -37,6 +48,9 @@ func (c *Checkbox) Text() string {
// SetChecked() changes the checked state of the Checkbox.
func (c *Checkbox) SetChecked(checked bool) {
+ c.lock.Lock()
+ defer c.lock.Unlock()
+
if c.created {
c.sysData.setChecked(checked)
return
@@ -46,6 +60,9 @@ func (c *Checkbox) SetChecked(checked bool) {
// Checked() returns whether or not the Checkbox has been checked.
func (c *Checkbox) Checked() bool {
+ c.lock.Lock()
+ defer c.lock.Unlock()
+
if c.created {
return c.sysData.isChecked()
}
@@ -53,6 +70,9 @@ func (c *Checkbox) Checked() bool {
}
func (c *Checkbox) make(window *sysData) error {
+ c.lock.Lock()
+ defer c.lock.Unlock()
+
err := c.sysData.make(window)
if err != nil {
return err