summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-02-15 18:27:34 -0500
committerPietro Gagliardi <[email protected]>2014-02-15 18:27:34 -0500
commit2d97a2446304daa1d57121d13143cce2ceaf69a3 (patch)
tree920a6b86d1f405af0ed9e1b0953e50f3ad9f9bad
parent8be17f087b0cb1706df837b3f956dcca2ced4568 (diff)
Added Combobox.SelectedIndex().
-rw-r--r--combobox.go11
-rw-r--r--main.go9
-rw-r--r--sysdata_windows.go3
3 files changed, 19 insertions, 4 deletions
diff --git a/combobox.go b/combobox.go
index 0659be1..241c81e 100644
--- a/combobox.go
+++ b/combobox.go
@@ -76,7 +76,16 @@ func (c *Combobox) Selection() string {
return ""
}
-// TODO SelectedIndex
+// SelectedIndex returns the index of the current selection in the Combobox. It returns -1 either if no selection was made or if text was manually entered in an editable Combobox.
+func (c *Combobox) SelectedIndex() int {
+ c.lock.Lock()
+ defer c.lock.Unlock()
+
+ if c.created {
+ return c.sysData.selectedIndex()
+ }
+ return -1
+}
func (c *Combobox) make(window *sysData) (err error) {
c.lock.Lock()
diff --git a/main.go b/main.go
index 49ff4f1..c110e99 100644
--- a/main.go
+++ b/main.go
@@ -16,7 +16,9 @@ func main() {
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, s2, c, cb1, cb2, e, l)
+ b3 := NewButton("List Info")
+ s3 := NewStack(Horizontal, l, b3)
+ s0 := NewStack(Vertical, s2, c, cb1, cb2, e, s3)
lb := NewListbox(true, "Select One", "Or More", "To Continue")
lb2 := NewListbox(false, "Select", "Only", "One", "Please")
i := 0
@@ -55,6 +57,11 @@ mainloop:
cb2.Delete(2)
lb.Delete(3)
lb2.Delete(4)
+ case <-b3.Clicked:
+ MsgBox("List Info",
+ "cb1: %d %q\ncb2: %d %q",
+ cb1.SelectedIndex(), cb1.Selection(),
+ cb2.SelectedIndex(), cb2.Selection())
}
}
w.Hide()
diff --git a/sysdata_windows.go b/sysdata_windows.go
index f0ecbf3..52e2806 100644
--- a/sysdata_windows.go
+++ b/sysdata_windows.go
@@ -340,7 +340,6 @@ func (s *sysData) insertBefore(what string, index int) (err error) {
return nil
}
-// TODO differentiate between nothing selected and custom text entered for a Combobox
func (s *sysData) selectedIndex() int {
ret := make(chan uiret)
defer close(ret)
@@ -355,7 +354,7 @@ func (s *sysData) selectedIndex() int {
ret: ret,
}
r := <-ret
- if r.ret == uintptr(classTypes[s.ctype].selectedIndexErr) { // no selection
+ if r.ret == uintptr(classTypes[s.ctype].selectedIndexErr) { // no selection or manually entered text (apparently, for the latter)
return -1
}
return int(r.ret)