Added Combobox.Delete() and Listbox.Delete() and added some TODOs.

This commit is contained in:
Pietro Gagliardi 2014-02-15 18:14:43 -05:00
parent 3c25b58652
commit 14aaad6be3
6 changed files with 55 additions and 2 deletions

View File

@ -53,7 +53,17 @@ func (c *Combobox) InsertBefore(what string, before int) (err error) {
return nil
}
// TODO Delete
// Delete removes the given item from the Combobox.
func (c *Combobox) Delete(index int) error {
c.lock.Lock()
defer c.lock.Unlock()
if c.created {
return c.sysData.delete(index)
}
c.initItems = append(c.initItems[:index], c.initItems[index + 1:]...)
return nil
}
// Selection returns the current selection.
func (c *Combobox) Selection() string {

View File

@ -53,6 +53,18 @@ func (l *Listbox) InsertBefore(what string, before int) (err error) {
return nil
}
// Delete removes the given item from the Listbox.
func (l *Listbox) Delete(index int) error {
l.lock.Lock()
defer l.lock.Unlock()
if l.created {
return l.sysData.delete(index)
}
l.initItems = append(l.initItems[:index], l.initItems[index + 1:]...)
return nil
}
// TODO Selection
// TODO SelectedIndices

View File

@ -9,12 +9,14 @@ func main() {
w := NewWindow("Main Window", 320, 240)
w.Closing = make(chan struct{})
b := NewButton("Click Me")
b2 := NewButton("Or Me")
s2 := NewStack(Horizontal, b, b2)
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)
s0 := NewStack(Vertical, s2, c, cb1, cb2, e, l)
lb := NewListbox(true, "Select One", "Or More", "To Continue")
lb2 := NewListbox(false, "Select", "Only", "One", "Please")
i := 0
@ -48,6 +50,11 @@ mainloop:
panic(err)
}
doAdjustments()
case <-b2.Clicked:
cb1.Delete(1)
cb2.Delete(2)
lb.Delete(3)
lb2.Delete(4)
}
}
w.Hide()

View File

@ -51,6 +51,9 @@ func (c *cSysData) selectedTexts() []string {
func (c *cSysData) setWindowSize(int, int) error {
panic(runtime.GOOS + " sysData does not define setWindowSize()")
}
func (c *cSysData) delete(int) error {
panic(runtime.GOOS + " sysData does not define delete()")
}
const (
c_window = iota

View File

@ -467,3 +467,23 @@ func (s *sysData) setWindowSize(width int, height int) error {
}
return nil
}
func (s *sysData) delete(index int) (err error) {
ret := make(chan uiret)
defer close(ret)
uitask <- &uimsg{
call: _sendMessage,
p: []uintptr{
uintptr(s.hwnd),
uintptr(classTypes[s.ctype].deleteMsg),
uintptr(_WPARAM(index)),
uintptr(0),
},
ret: ret,
}
r := <-ret
if r.ret == uintptr(classTypes[s.ctype].selectedIndexErr) {
return fmt.Errorf("failed to delete item from combobox/listbox (last error: %v)", r.err)
}
return nil
}

View File

@ -17,6 +17,7 @@ so I don't forget:
- Combobox/Listbox.DeleteAll
- Combobox/Listbox.Select (with Listbox.Select allowing bulk)
- Listbox.SelectAll
- have Combobox.InsertBefore, Listbox.InsertBefore, Combobox.Delete, and Listbox.Delete return an error on invalid index
super ultra important things:
- the windows build appears to be unstable: