Added Listbox.Append() and Listbox.InsertBefore().
This commit is contained in:
parent
ca1c513159
commit
3c25b58652
27
listbox.go
27
listbox.go
|
@ -26,7 +26,32 @@ func NewListbox(multiple bool, items ...string) (l *Listbox) {
|
||||||
return l
|
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
|
// TODO Selection
|
||||||
|
|
||||||
|
|
16
main.go
16
main.go
|
@ -12,18 +12,20 @@ func main() {
|
||||||
c := NewCheckbox("Check Me")
|
c := NewCheckbox("Check Me")
|
||||||
cb1 := NewCombobox(true, "You can edit me!", "Yes you can!", "Yes you will!")
|
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!")
|
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")
|
e := NewLineEdit("Enter text here too")
|
||||||
l := NewLabel("This is a label")
|
l := NewLabel("This is a label")
|
||||||
s0 := NewStack(Vertical, b, c, cb1, cb2, e, l)
|
s0 := NewStack(Vertical, b, c, cb1, cb2, e, l)
|
||||||
lb := NewListbox(true, "Select One", "Or More", "To Continue")
|
lb := NewListbox(true, "Select One", "Or More", "To Continue")
|
||||||
lb2 := NewListbox(false, "Select", "Only", "One", "Please")
|
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)
|
s1 := NewStack(Vertical, lb2, lb)
|
||||||
s := NewStack(Horizontal, s1, s0)
|
s := NewStack(Horizontal, s1, s0)
|
||||||
err := w.Open(s)
|
err := w.Open(s)
|
||||||
|
|
Loading…
Reference in New Issue