diff options
| author | Pietro Gagliardi <[email protected]> | 2018-08-11 21:29:20 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2018-08-11 21:29:20 -0400 |
| commit | 68ffb808678159b8810c8ed093c0458316d3f8f2 (patch) | |
| tree | 5bda3855b4b6cafc1f39bdbc66204a44493896e3 /radiobuttons.go | |
| parent | 5ab5777d4cbfe6490760ef4e618bd5fe80a20bea (diff) | |
More control migration.
Diffstat (limited to 'radiobuttons.go')
| -rw-r--r-- | radiobuttons.go | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/radiobuttons.go b/radiobuttons.go new file mode 100644 index 0000000..bbf28d3 --- /dev/null +++ b/radiobuttons.go @@ -0,0 +1,65 @@ +// 12 december 2015 + +package ui + +import ( + "unsafe" +) + +// #include "ui.h" +// extern void doRadioButtonsOnSelected(uiRadioButtons *, void *); +import "C" + +// RadioButtons is a Control that represents a set of checkable +// buttons from which exactly one may be chosen by the user. +type RadioButtons struct { + ControlBase + r *C.uiRadioButtons + onSelected func(*RadioButtons) +} + +// NewRadioButtons creates a new RadioButtons. +func NewRadioButtons() *RadioButtons { + r := new(RadioButtons) + + r.r = C.uiNewRadioButtons() + + C.uiRadioButtonsOnChanged(r.r, C.doRadioButtonsOnChanged, nil) + + r.ControlBase = NewControlBase(r, uintptr(unsafe.Pointer(r.r))) + return r +} + +// Append adds the named button to the end of the RadioButtons. +// If this button is the first button, it is automatically selected. +func (r *RadioButtons) Append(text string) { + ctext := C.CString(text) + C.uiRadioButtonsAppend(r.r, ctext) + freestr(ctext) +} + +// Selected returns the index of the currently selected option in the +// RadioButtons, or -1 if there are no items. +func (r *RadioButtons) Selected() int { + return int(C.uiRadioButtonsSelected(r.r)) +} + +// SetSelected sets the currently selected option in the RadioButtons +// to index. +func (r *RadioButtons) SetSelected(index int) { + C.uiRadioButtonsSetSelected(r.r, C.int(index)) +} + +// OnSelected registers f to be run when the user selects an option in +// the RadioButtons. Only one function can be registered at a time. +func (r *RadioButtons) OnSelected(f func(*RadioButtons)) { + r.onSelected = f +} + +//export doRadioButtonsOnSelected +func doRadioButtonsOnSelected(rr *C.uiRadioButtons, data unsafe.Pointer) { + r := ControlFromLibui(uintptr(unsafe.Pointer(rr))).(*RadioButtons) + if r.onSelected != nil { + r.onSelected(r) + } +} |
