Added Listbox.Selection() and Listbox.SelectedIndices(). Also fixed a bug involving sysData.selectedIndices() with nothing selected.
This commit is contained in:
parent
2d97a24463
commit
992d43ac7b
22
listbox.go
22
listbox.go
|
@ -65,9 +65,27 @@ func (l *Listbox) Delete(index int) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Selection
|
// Selection returns a list of strings currently selected in the Listbox, or an empty list if none have been selected. This list will have at most one item on a single-selection Listbox.
|
||||||
|
func (l *Listbox) Selection() []string {
|
||||||
|
l.lock.Lock()
|
||||||
|
defer l.lock.Unlock()
|
||||||
|
|
||||||
// TODO SelectedIndices
|
if l.created {
|
||||||
|
return l.sysData.selectedTexts()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SelectedIndices returns a list of the currently selected indexes in the Listbox, or an empty list if none have been selected. This list will have at most one item on a single-selection Listbox.
|
||||||
|
func (l *Listbox) SelectedIndices() []int {
|
||||||
|
l.lock.Lock()
|
||||||
|
defer l.lock.Unlock()
|
||||||
|
|
||||||
|
if l.created {
|
||||||
|
return l.sysData.selectedIndices()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (l *Listbox) make(window *sysData) (err error) {
|
func (l *Listbox) make(window *sysData) (err error) {
|
||||||
l.lock.Lock()
|
l.lock.Lock()
|
||||||
|
|
14
main.go
14
main.go
|
@ -19,18 +19,18 @@ func main() {
|
||||||
b3 := NewButton("List Info")
|
b3 := NewButton("List Info")
|
||||||
s3 := NewStack(Horizontal, l, b3)
|
s3 := NewStack(Horizontal, l, b3)
|
||||||
s0 := NewStack(Vertical, s2, c, cb1, cb2, e, s3)
|
s0 := NewStack(Vertical, s2, c, cb1, cb2, e, s3)
|
||||||
lb := NewListbox(true, "Select One", "Or More", "To Continue")
|
lb1 := NewListbox(true, "Select One", "Or More", "To Continue")
|
||||||
lb2 := NewListbox(false, "Select", "Only", "One", "Please")
|
lb2 := NewListbox(false, "Select", "Only", "One", "Please")
|
||||||
i := 0
|
i := 0
|
||||||
doAdjustments := func() {
|
doAdjustments := func() {
|
||||||
cb1.Append("append")
|
cb1.Append("append")
|
||||||
cb2.InsertBefore(fmt.Sprintf("before %d", i), 1)
|
cb2.InsertBefore(fmt.Sprintf("before %d", i), 1)
|
||||||
lb.InsertBefore(fmt.Sprintf("%d", i), 2)
|
lb1.InsertBefore(fmt.Sprintf("%d", i), 2)
|
||||||
lb2.Append("Please")
|
lb2.Append("Please")
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
doAdjustments()
|
doAdjustments()
|
||||||
s1 := NewStack(Vertical, lb2, lb)
|
s1 := NewStack(Vertical, lb2, lb1)
|
||||||
s := NewStack(Horizontal, s1, s0)
|
s := NewStack(Horizontal, s1, s0)
|
||||||
err := w.Open(s)
|
err := w.Open(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -55,13 +55,15 @@ mainloop:
|
||||||
case <-b2.Clicked:
|
case <-b2.Clicked:
|
||||||
cb1.Delete(1)
|
cb1.Delete(1)
|
||||||
cb2.Delete(2)
|
cb2.Delete(2)
|
||||||
lb.Delete(3)
|
lb1.Delete(3)
|
||||||
lb2.Delete(4)
|
lb2.Delete(4)
|
||||||
case <-b3.Clicked:
|
case <-b3.Clicked:
|
||||||
MsgBox("List Info",
|
MsgBox("List Info",
|
||||||
"cb1: %d %q\ncb2: %d %q",
|
"cb1: %d %q\ncb2: %d %q\nlb1: %d %q\nlb2: %d %q",
|
||||||
cb1.SelectedIndex(), cb1.Selection(),
|
cb1.SelectedIndex(), cb1.Selection(),
|
||||||
cb2.SelectedIndex(), cb2.Selection())
|
cb2.SelectedIndex(), cb2.Selection(),
|
||||||
|
lb1.SelectedIndices(), lb1.Selection(),
|
||||||
|
lb2.SelectedIndices(), lb2.Selection())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
w.Hide()
|
w.Hide()
|
||||||
|
|
|
@ -385,6 +385,9 @@ func (s *sysData) selectedIndices() []int {
|
||||||
if r.ret == uintptr(_LB_ERR) {
|
if r.ret == uintptr(_LB_ERR) {
|
||||||
panic("UI library internal error: LB_ERR from LB_GETSELCOUNT in what we know is a multi-selection listbox")
|
panic("UI library internal error: LB_ERR from LB_GETSELCOUNT in what we know is a multi-selection listbox")
|
||||||
}
|
}
|
||||||
|
if r.ret == 0 { // nothing selected
|
||||||
|
return nil
|
||||||
|
}
|
||||||
indices := make([]int, r.ret)
|
indices := make([]int, r.ret)
|
||||||
uitask <- &uimsg{
|
uitask <- &uimsg{
|
||||||
call: _sendMessage,
|
call: _sendMessage,
|
||||||
|
|
Loading…
Reference in New Issue