forked from czkoko/ui
-
Notifications
You must be signed in to change notification settings - Fork 1
/
editablecombobox.go
69 lines (56 loc) · 1.83 KB
/
editablecombobox.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// 12 december 2015
package ui
import (
"unsafe"
)
// #include "pkgui.h"
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()
C.pkguiEditableComboboxOnChanged(c.c)
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.
func (e *EditableCombobox) SetText(text string) {
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)) {
e.onChanged = f
}
//export pkguiDoEditableComboboxOnChanged
func pkguiDoEditableComboboxOnChanged(cc *C.uiEditableCombobox, data unsafe.Pointer) {
e := ControlFromLibui(uintptr(unsafe.Pointer(cc))).(*EditableCombobox)
if e.onChanged != nil {
e.onChanged(e)
}
}