Added Listbox.Append() and Listbox.InsertBefore().

This commit is contained in:
Pietro Gagliardi 2014-02-15 17:59:12 -05:00
parent ca1c513159
commit 3c25b58652
2 changed files with 35 additions and 8 deletions

View File

@ -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

16
main.go
View File

@ -12,18 +12,20 @@ func main() {
c := NewCheckbox("Check Me")
cb1 := NewCombobox(true, "You can edit me!", "Yes you can!", "Yes you will!")
cb2 := NewCombobox(false, "You can't edit me!", "No you can't!", "No you won't!")
i := 0
doAdjustments := func() {
cb1.Append("append")
cb2.InsertBefore(fmt.Sprintf("before %d", i), 1)
i++
}
doAdjustments()
e := NewLineEdit("Enter text here too")
l := NewLabel("This is a label")
s0 := NewStack(Vertical, b, c, cb1, cb2, e, l)
lb := NewListbox(true, "Select One", "Or More", "To Continue")
lb2 := NewListbox(false, "Select", "Only", "One", "Please")
i := 0
doAdjustments := func() {
cb1.Append("append")
cb2.InsertBefore(fmt.Sprintf("before %d", i), 1)
lb.InsertBefore(fmt.Sprintf("%d", i), 2)
lb2.Append("Please")
i++
}
doAdjustments()
s1 := NewStack(Vertical, lb2, lb)
s := NewStack(Horizontal, s1, s0)
err := w.Open(s)