diff options
| author | Pietro Gagliardi <[email protected]> | 2018-08-11 19:52:29 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2018-08-11 19:54:07 -0400 |
| commit | 5ab5777d4cbfe6490760ef4e618bd5fe80a20bea (patch) | |
| tree | dcbf3e07665b1918b2c36fbcbb419ef370437810 /combobox.go | |
| parent | 97c3d186f1bc249d77e1084d127e06f9f198685d (diff) | |
More control conversion and syncing.
Diffstat (limited to 'combobox.go')
| -rw-r--r-- | combobox.go | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/combobox.go b/combobox.go new file mode 100644 index 0000000..5da5f35 --- /dev/null +++ b/combobox.go @@ -0,0 +1,65 @@ +// 12 december 2015 + +package ui + +import ( + "unsafe" +) + +// #include "ui.h" +// extern void doComboboxOnSelected(uiCombobox *, void *); +import "C" + +// Combobox is a Control that represents a drop-down list of strings +// that the user can choose one of at any time. For a Combobox that +// users can type values into, see EditableCombobox. +type Combobox struct { + ControlBase + c *C.uiCombobox + onSelected func(*Combobox) +} + +// NewCombobox creates a new Combobox. +func NewCombobox() *Combobox { + c := new(Combobox) + + c.c = C.uiNewCombobox() + + C.uiComboboxOnSelected(c.c, C.doComboboxOnSelected, nil) + + c.ControlBase = NewControlBase(c, uintptr(unsafe.Pointer(c.c))) + return c +} + +// Append adds the named item to the end of the Combobox. +func (c *Combobox) Append(text string) { + ctext := C.CString(text) + C.uiComboboxAppend(c.c, ctext) + freestr(ctext) +} + +// Selected returns the index of the currently selected item in the +// Combobox, or -1 if nothing is selected. +func (c *Combobox) Selected() int { + return int(C.uiComboboxSelected(c.c)) +} + +// SetChecked sets the currently select item in the Combobox +// to index. If index is -1 no item will be selected. +func (c *Combobox) SetSelected(index int) { + C.uiComboboxSetSelected(c.c, C.intmax_t(index)) +} + +// OnSelected registers f to be run when the user selects an item in +// the Combobox. Only one function can be registered at a time. +func (c *Combobox) OnSelected(f func(*Combobox)) { + c.onSelected = f +} + +//export doComboboxOnSelected +func doComboboxOnSelected(cc *C.uiCombobox, data unsafe.Pointer) { + c := ControlFromLibui(uintptr(unsafe.Pointer(cc))).(*Combobox) + if c.onSelected != nil { + c.onSelected(c) + } +} |
