Multi Select List

Post Reply
User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Multi Select List

Post by rbytes »

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. :lol:

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()
<
Attachments
Screenshot (99).png
Screenshot (99).png (31.83 KiB) Viewed 2655 times
The only thing that gets me down is gravity...

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Multi Select List

Post by Mr. Kibernetik »

Thank you for the suggestion!

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Multi Select List

Post by Mr. Kibernetik »

In next release multi select will be available.

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: Multi Select List

Post by rbytes »

That will be very useful. :)
The only thing that gets me down is gravity...

Post Reply