diff options
| -rw-r--r-- | listbox.go | 27 | ||||
| -rw-r--r-- | main.go | 12 |
2 files changed, 33 insertions, 6 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 @@ -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!") + 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() - 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") s1 := NewStack(Vertical, lb2, lb) s := NewStack(Horizontal, s1, s0) err := w.Open(s) |
