Multi Select List
Posted: Sat Oct 14, 2017 7:59 pm
This program demonstrates how a list can have multiple selections. I used the same technique in Smart Basic to create a shopping list program called Listful. Eventually I will recreate that program in SPL.
While my technique works, I can definitely see how much better it would be for SPL lists to have a choice of single or multiple list selections built into the function. And the selected indicator could be something a little more stylish than an asterisk.
While my technique works, I can definitely see how much better it would be for SPL lists to have a choice of single or multiple list selections built into the function. And the selected indicator could be something a little more stylish than an asterisk.
Code: Select all
''
Multi Select List by rbytes
October 2017
#.listbox is an list box. Clicking an item registers an action. Group elements are:
height - list box height;
index - currently selected item index. If 0 then nothing is selected;
source - one-dimensional array with text objects which is the source of list items;
width - list box width;
x - offset from left screen border;
y - offset from top screen border.
''
#.scrclear(1,1,1)
' create an array of food items
c = [" bread"," buns"," butter"," cake"," carrots"," cheese"," cream"," lettuce"," meat"," milk"," potatoes"," soup"," sugar"," tomatoes"]
temp3 = ""
sz = #.size(c,1)
#.fontsize(30)
#.drawtext(480,50,"Multi Selection List")
#.fontsize(20)
a = #.listbox
a.height = 250
a.width = 200
a.x = 350
a.y = 200
a.source = c
#.drawrect(348,198,552,452)
b = #.textbox
b.multi = 1
b.text = temp3
b.height = 250
b.width = 200
b.x = 650
b.y = 200
#.drawrect(648,198,852,452)
#.show(a,b)
#.drawtext(350,160,"Choose From This List")
#.drawtext(650,160," Grocery Shopping")
' main program loop
>
? a.index > 0
temp3 = ""
in = a.index
a.index = 0
temp = c[in]
temp2 = #.mid(temp,1,1)
? temp2 = " "
c[in] = "*" + #.mid(temp,2,#.size(temp))
!
c[in] = " " + #.mid(temp,2,#.size(temp))
.
a.source = c
> t, 1..sz
? #.mid(c[t],1,1) = "*"
temp3 += #.mid(c[t],3,50) + #.lf
.
<
b.text = temp3
.
'#.show(a,b)
'#.output(temp3)
#.relax()
<