[REBOL] How to count properly slider args solution ....
From: petr::krenzelok::trz::cz at: 30-Aug-2000 13:55
Hi,
as I was receiving unexpected behavior of lists while trying to scroll
it (when using 'supply for dynamic list creation), I played a little bit
with what should be the right arg which should go into slider ...
I surely don't know how /View scrolls internally, but imho following
aproach used even by Carl's file-requestor is imho buggy and will not
show all items. If I am wrong, I will be glad you will correct me please
:-)
Carl uses following technique:
vv: slider 16x400 (to-integer vx/size/y / file-name/size/y)
[print vv/data num: vv/data - 1 show vx]
while num and count being initialised to zero
So, current aproach gave me 58 items of my directory ....
I took another aproach:
1 + (length? files) - (to-integer vx/size/y / file-name/size/y)
Explanation:
1) "1" is the constant - it simply works ;-)))
2) Now we have to count, how many rows our visible list area can display
.... (to-integer vx/size/y / file-name/size/y)
3) We have to substract value 2) from the length? of block we want list
be filled with ...
If I count items in display now, it give more proper result of 154 files
...
Still one file missing though .... :-)
Hmm, what about this one?:
- there's some reminder as a result from 2) (to-integer vx/size/y /
file-name/size/y). Let's say we can ignore those few pixels with small
listings, but - going thru some 5 screens gives me:
reminder vx/size/y file-name/size/y ..... 400 // 14 = 5 pixels ... 5
pixels * 5 screens = 25 displays ... hmm, it's one more item for the
display ...
So:
length? read %. .... 155 files
y-size-of-list / item-size .... 400 / 14 .... 28 items per screen ....
reminder 8 pixels ...
155 files / 28 items .... 5 full screens to display ....
5 screens * 8 pixels .... 40 pixels ...
40 pixels / 14 pixels per item ..... 2 more items ...
so, let's code it:
items-per-screen: to-integer vx/size/y / file-name/size/y
full-screens: to-integer (length? files) / items-per-screen
remainder-per-screen: remainder vx/size/y file-name/size/y
constant: to-integer full-screens * remainder-per-screen /
file-name/size/y
range: constant + (length? files) - items-per-screen
resulting code in file-request.r:
....
do [
items-per-screen: to-integer vx/size/y / file-name/size/y
full-screens: to-integer (length? files) / items-per-screen
remainder-per-screen: remainder vx/size/y file-name/size/y
constant: to-integer full-screens * remainder-per-screen /
file-name/size/y
range: constant + (length? files) - items-per-screen
]
vv: slider 16x400 range
[print vv/data num: vv/data - 1 show vx]
]
Im my aproach si corrent, VID could support some func to count all above
automatically by specifying list-face, block which goes for display,
widest-item(row) ...
Anyone?
PS: aproach with 'constant is not correct ... have no further time to
play with it right now .... :-)
-pekr-