Added Combobox.Append() and Combobox.InsertBefore().
This commit is contained in:
parent
430eac563a
commit
8c30cae462
29
combobox.go
29
combobox.go
|
@ -26,7 +26,34 @@ func NewCombobox(editable bool, items ...string) (c *Combobox) {
|
|||
return c
|
||||
}
|
||||
|
||||
// TODO Append, InsertBefore, Delete
|
||||
// Append adds an item 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)
|
||||
}
|
||||
c.initItems = append(c.initItems, what)
|
||||
return nil
|
||||
}
|
||||
|
||||
// InsertBefore inserts a new item in the Combobox before the item at the given position.
|
||||
func (c *Combobox) InsertBefore(what string, before int) (err error) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
if c.created {
|
||||
return c.sysData.insertBefore(what, before)
|
||||
}
|
||||
m := make([]string, 0, len(c.initItems) + 1)
|
||||
m = append(m, c.initItems[:before]...)
|
||||
m = append(m, what)
|
||||
c.initItems = append(m, c.initItems[before:]...)
|
||||
return nil
|
||||
}
|
||||
|
||||
// TODO Delete
|
||||
|
||||
// Selection returns the current selection.
|
||||
func (c *Combobox) Selection() string {
|
||||
|
|
8
main.go
8
main.go
|
@ -12,6 +12,13 @@ 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)
|
||||
|
@ -38,6 +45,7 @@ mainloop:
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
doAdjustments()
|
||||
}
|
||||
}
|
||||
w.Hide()
|
||||
|
|
Loading…
Reference in New Issue