From 3c25b58652b55ee27a8c3c1f09e88a1eb593ca39 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sat, 15 Feb 2014 17:59:12 -0500 Subject: Added Listbox.Append() and Listbox.InsertBefore(). --- listbox.go | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'listbox.go') 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 -- cgit v1.2.3