Changed Combobox.Append() and Listbox.Append() to accept multiple strings in one call.

This commit is contained in:
Pietro Gagliardi 2014-03-07 15:01:42 -05:00
parent 874a4b9271
commit 20dcc48bee
3 changed files with 26 additions and 8 deletions

View File

@ -2,6 +2,7 @@
package ui
import (
"fmt"
"sync"
)
@ -34,15 +35,21 @@ func NewEditableCombobox(items ...string) *Combobox {
return newCombobox(true, items...)
}
// Append adds an item to the end of the Combobox's list.
func (c *Combobox) Append(what string) (err error) {
// Append adds items to the end of the Combobox's list.
func (c *Combobox) Append(what ...string) (err error) {
c.lock.Lock()
defer c.lock.Unlock()
if c.created {
return c.sysData.append(what)
for i, s := range what {
err := c.sysData.append(s)
if err != nil {
return fmt.Errorf("error adding element %d in Combobox.Append() (%q): %v", i, s, err)
}
}
return nil
}
c.initItems = append(c.initItems, what)
c.initItems = append(c.initItems, what...)
return nil
}

View File

@ -2,6 +2,7 @@
package ui
import (
"fmt"
"sync"
)
@ -25,15 +26,21 @@ func NewListbox(multiple bool, items ...string) (l *Listbox) {
return l
}
// Append adds an item to the end of the Listbox's list.
func (l *Listbox) Append(what string) (err error) {
// Append adds items 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)
for i, s := range what {
err := l.sysData.append(s)
if err != nil {
return fmt.Errorf("error adding element %d in Listbox.Append() (%q): %v", i, s, err)
}
}
return nil
}
l.initItems = append(l.initItems, what)
l.initItems = append(l.initItems, what...)
return nil
}

View File

@ -69,6 +69,8 @@ func myMain() {
i++
}
doAdjustments()
cb1.Append("append multi 1", "append multi 2")
lb2.Append("append multi 1", "append multi 2")
s1 := NewVerticalStack(lb2, lb1)
s1.SetStretchy(0)
s1.SetStretchy(1)
@ -126,6 +128,8 @@ mainloop:
prog = 100
}
pbar.SetProgress(prog)
cb1.Append("append multi 1", "append multi 2")
lb2.Append("append multi 1", "append multi 2")
case <-decButton.Clicked:
prog--
if prog < 0 {