2018-08-11 18:52:29 -05:00
|
|
|
// 12 december 2015
|
|
|
|
|
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
// #include "ui.h"
|
2018-08-12 08:24:51 -05:00
|
|
|
// extern void doEditableComboboxOnChanged(uiEditableCombobox *, void *);
|
2018-08-12 10:07:33 -05:00
|
|
|
// // see golang/go#19835
|
|
|
|
// typedef void (*editableComboboxCallback)(uiEditableCombobox *, void *);
|
2018-08-11 18:52:29 -05:00
|
|
|
import "C"
|
|
|
|
|
|
|
|
// EditableCombobox is a Control that represents a drop-down list
|
|
|
|
// of strings that the user can choose one of at any time. It also has
|
|
|
|
// an entry field that the user can type an alternate choice into.
|
|
|
|
type EditableCombobox struct {
|
|
|
|
ControlBase
|
|
|
|
c *C.uiEditableCombobox
|
|
|
|
onChanged func(*EditableCombobox)
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewEditableCombobox creates a new EditableCombobox.
|
|
|
|
func NewEditableCombobox() *EditableCombobox {
|
|
|
|
c := new(EditableCombobox)
|
|
|
|
|
|
|
|
c.c = C.uiNewEditableCombobox()
|
|
|
|
|
2018-08-12 10:07:33 -05:00
|
|
|
C.uiEditableComboboxOnChanged(c.c, C.editableComboboxCallback(C.doEditableComboboxOnChanged), nil)
|
2018-08-11 18:52:29 -05:00
|
|
|
|
|
|
|
c.ControlBase = NewControlBase(c, uintptr(unsafe.Pointer(c.c)))
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
|
|
|
// Append adds the named item to the end of the EditableCombobox.
|
|
|
|
func (e *EditableCombobox) Append(text string) {
|
|
|
|
ctext := C.CString(text)
|
|
|
|
C.uiEditableComboboxAppend(e.c, ctext)
|
|
|
|
freestr(ctext)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Text returns the text in the entry of the EditableCombobox, which
|
|
|
|
// could be one of the choices in the list if the user has selected one.
|
|
|
|
func (e *EditableCombobox) Text() string {
|
|
|
|
ctext := C.uiEditableComboboxText(e.c)
|
|
|
|
text := C.GoString(ctext)
|
|
|
|
C.uiFreeText(ctext)
|
|
|
|
return text
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetText sets the text in the entry of the EditableCombobox.
|
2018-08-12 10:07:33 -05:00
|
|
|
func (e *EditableCombobox) SetText(text string) {
|
2018-08-11 18:52:29 -05:00
|
|
|
ctext := C.CString(text)
|
|
|
|
C.uiEditableComboboxSetText(e.c, ctext)
|
|
|
|
freestr(ctext)
|
|
|
|
}
|
|
|
|
|
|
|
|
// OnChanged registers f to be run when the user either selects an
|
|
|
|
// item or changes the text in the EditableCombobox. Only one
|
|
|
|
// function can be registered at a time.
|
|
|
|
func (e *EditableCombobox) OnChanged(f func(*EditableCombobox)) {
|
2018-08-12 10:07:33 -05:00
|
|
|
e.onChanged = f
|
2018-08-11 18:52:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//export doEditableComboboxOnChanged
|
|
|
|
func doEditableComboboxOnChanged(cc *C.uiEditableCombobox, data unsafe.Pointer) {
|
|
|
|
e := ControlFromLibui(uintptr(unsafe.Pointer(cc))).(*EditableCombobox)
|
|
|
|
if e.onChanged != nil {
|
|
|
|
e.onChanged(e)
|
|
|
|
}
|
|
|
|
}
|