Home   Archive   Permalink


In text-list, how can I display one of the elements highlited / selected ?
I tried something like this...
d: ["aaa" "bbb" "ccc" "ddd"]
view layout [t: text-list data d do[t/picked: d/1]]

posted by:   iontab       27-Sep-2017/7:03:53-7:00

That works :)

posted by:   Nick       27-Sep-2017/21:29:18-7:00

Yes, that works, but look what's happened when you select another element from list... That's my problem in fact

posted by:   iontab       27-Sep-2017/23:50:55-7:00

Add 'copy:
view layout [t: text-list data d do[t/picked: copy d/1]

posted by:   Nick       28-Sep-2017/1:55:39-7:00

Thanks, it worked! :)
If you don't mind, a short explanation for a newbie... What was wrong with first version and why, after selecting other elements from list, my data d block was modified? Seems 't/picked' is 'bidirectional': first is set with d/1 value, then sets the d values.

posted by:   iontab       28-Sep-2017/3:36:19-7:00

Now there is a perfect example of how once you think you finally understand something you find out that you are all wrong.
I see this:
R E B O L []
d: ["aaa" "bbb" "ccc" "ddd"]
view layout [
     t: text-list data d
     do [t/picked: copy d/1]
I thought that the stuff inside the block being fed to the "layout" function describes a window, and yet I see "do [t/picked: copy d/1]" inside that block. Is that "do" function executed only one time when the "layout" function is generating a window? Obviously not since it seems to be executed every time an item is picked.
If the "do" function is code that is executed every time an item is picked, why is that code not in its own brackets, in the same way you would put button code in brackets?
If the "do" function is executed when an item is picked, why is the picked item not changed to the first item of "d" which would be "aaa"? If you put a button on the layout to halt the script and then probe "t/picked" you see that it is whatever you picked and not "aaa" (unless you picked "aaa" of course).    
I still marvel at how one line of REBOL code can be so hard to understand. I do suppose it is better than regular expressions.

posted by:   Steven White       28-Sep-2017/9:19:49-7:00

Yes you're right, the 'd data does apparently get bound to the displayed fields in the 'text-list. I really don't know why Carl/whoever made that design decision in some of VID's widgets, but that's one of the little gotchas in VID that can catch you if you don't know to look for it. I do know that the first version of Rebol used copies of all series by default, but they changed that behavior to improve performance. I don't remember if RebGUI or R3-GUI or RED's GUI does such a binding, but if so, just remember to use a copy. You'll develop some intuition about when when to use 'copy just by dealing with more series in Rebol.
Yes, your initial understanding is correct. The 'do function only gets evaluated once, when the layout is evaluated (the designers of R3-GUI did remove 'do entirely from the layout block, BTW). It's just used in the example above to set an initial state for the picked item in the text list. After that, the text-list properties are set as you'd expect (/picked is the value which the user has currently picked).

posted by:   Nick       28-Sep-2017/10:04:08-7:00