summaryrefslogtreecommitdiff
path: root/checkbox.go
diff options
context:
space:
mode:
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