summaryrefslogtreecommitdiff
path: root/checkbox.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2018-08-26 09:55:07 -0400
committerPietro Gagliardi <[email protected]>2018-08-26 09:55:07 -0400
commit62ac2527732a01dfa6bd2c9523215c0ba3816641 (patch)
tree84244a69e048f79e4d9f134c121f4cf581200986 /checkbox.go
parenta5a00c644c08a6e0f52740c3f2a280977929a285 (diff)
Moved all the Go files out of the way again, this time so we can migrate them to more proper cgo usage.
Diffstat (limited to 'checkbox.go')
-rw-r--r--checkbox.go76
1 files changed, 0 insertions, 76 deletions
diff --git a/checkbox.go b/checkbox.go
deleted file mode 100644
index 8177226..0000000
--- a/checkbox.go
+++ /dev/null
@@ -1,76 +0,0 @@
-// 12 december 2015
-
-package ui
-
-import (
- "unsafe"
-)
-
-// #include "ui.h"
-// extern void doCheckboxOnToggled(uiCheckbox *, void *);
-// // see golang/go#19835
-// typedef void (*checkboxCallback)(uiCheckbox *, void *);
-import "C"
-
-// Checkbox is a Control that represents a box with a text label at its
-// side. When the user clicks the checkbox, a check mark will appear
-// in the box; clicking it again removes the check.
-type Checkbox struct {
- ControlBase
- c *C.uiCheckbox
- onToggled func(*Checkbox)
-}
-
-// NewCheckbox creates a new Checkbox with the given text as its
-// label.
-func NewCheckbox(text string) *Checkbox {
- c := new(Checkbox)
-
- ctext := C.CString(text)
- c.c = C.uiNewCheckbox(ctext)
- freestr(ctext)
-
- C.uiCheckboxOnToggled(c.c, C.checkboxCallback(C.doCheckboxOnToggled), nil)
-
- c.ControlBase = NewControlBase(c, uintptr(unsafe.Pointer(c.c)))
- return c
-}
-
-// Text returns the Checkbox's text.
-func (c *Checkbox) Text() string {
- ctext := C.uiCheckboxText(c.c)
- text := C.GoString(ctext)
- C.uiFreeText(ctext)
- return text
-}
-
-// SetText sets the Checkbox's text to text.
-func (c *Checkbox) SetText(text string) {
- ctext := C.CString(text)
- C.uiCheckboxSetText(c.c, ctext)
- freestr(ctext)
-}
-
-// OnToggled registers f to be run when the user clicks the Checkbox.
-// Only one function can be registered at a time.
-func (c *Checkbox) OnToggled(f func(*Checkbox)) {
- c.onToggled = f
-}
-
-//export doCheckboxOnToggled
-func doCheckboxOnToggled(cc *C.uiCheckbox, data unsafe.Pointer) {
- c := ControlFromLibui(uintptr(unsafe.Pointer(cc))).(*Checkbox)
- if c.onToggled != nil {
- c.onToggled(c)
- }
-}
-
-// Checked returns whether the Checkbox is checked.
-func (c *Checkbox) Checked() bool {
- return tobool(C.uiCheckboxChecked(c.c))
-}
-
-// SetChecked sets whether the Checkbox is checked.
-func (c *Checkbox) SetChecked(checked bool) {
- C.uiCheckboxSetChecked(c.c, frombool(checked))
-}