diff options
| author | Pietro Gagliardi <[email protected]> | 2014-02-15 18:14:43 -0500 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-02-15 18:14:43 -0500 |
| commit | 14aaad6be38d6ec23ac6b14d76496f8a38676597 (patch) | |
| tree | acc77ceb440d49ffd23231046558031124f084ad | |
| parent | 3c25b58652b55ee27a8c3c1f09e88a1eb593ca39 (diff) | |
Added Combobox.Delete() and Listbox.Delete() and added some TODOs.
| -rw-r--r-- | combobox.go | 12 | ||||
| -rw-r--r-- | listbox.go | 12 | ||||
| -rw-r--r-- | main.go | 9 | ||||
| -rw-r--r-- | sysdata.go | 3 | ||||
| -rw-r--r-- | sysdata_windows.go | 20 | ||||
| -rw-r--r-- | todo.md | 1 |
6 files changed, 55 insertions, 2 deletions
diff --git a/combobox.go b/combobox.go index 9d55ed3..0659be1 100644 --- a/combobox.go +++ b/combobox.go @@ -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 { @@ -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 @@ -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() @@ -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 diff --git a/sysdata_windows.go b/sysdata_windows.go index 0cbf4de..f0ecbf3 100644 --- a/sysdata_windows.go +++ b/sysdata_windows.go @@ -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 +} @@ -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: |
