summaryrefslogtreecommitdiff
path: root/listbox.go
diff options
context:
space:
mode:
Diffstat (limited to 'listbox.go')
-rw-r--r--listbox.go27
1 files changed, 26 insertions, 1 deletions
diff --git a/listbox.go b/listbox.go
index 20f1ffd..681c972 100644
--- a/listbox.go
+++ b/listbox.go
@@ -26,7 +26,32 @@ func NewListbox(multiple bool, items ...string) (l *Listbox) {
return l
}
-// TODO Append, InsertBefore, Delete
+// Append adds an item to the end of the Listbox's list.
+func (l *Listbox) Append(what string) (err error) {
+ l.lock.Lock()
+ defer l.lock.Unlock()
+
+ if l.created {
+ return l.sysData.append(what)
+ }
+ l.initItems = append(l.initItems, what)
+ return nil
+}
+
+// InsertBefore inserts a new item in the Listbox before the item at the given position.
+func (l *Listbox) InsertBefore(what string, before int) (err error) {
+ l.lock.Lock()
+ defer l.lock.Unlock()
+
+ if l.created {
+ return l.sysData.insertBefore(what, before)
+ }
+ m := make([]string, 0, len(l.initItems) + 1)
+ m = append(m, l.initItems[:before]...)
+ m = append(m, what)
+ l.initItems = append(m, l.initItems[before:]...)
+ return nil
+}
// TODO Selection