diff options
| author | Pietro Gagliardi <[email protected]> | 2014-02-15 17:59:12 -0500 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-02-15 17:59:12 -0500 |
| commit | 3c25b58652b55ee27a8c3c1f09e88a1eb593ca39 (patch) | |
| tree | 7f1bbbc1e182c7d6c9826867a9dfcae8d2f35867 /listbox.go | |
| parent | ca1c5131593442a8bbf2f81caa989d54cab885aa (diff) | |
Added Listbox.Append() and Listbox.InsertBefore().
Diffstat (limited to 'listbox.go')
| -rw-r--r-- | listbox.go | 27 |
1 files changed, 26 insertions, 1 deletions
@@ -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 |
