problem with scrolling fields

Wouter wouter.abraham at pi.be
Sun Nov 30 09:45:40 EST 2003


Hi all,

Rereading the "iTunes-type alternate colored lines in scrolling list 
field" thread form early march 2003 and by experimenting
with it, I had to conclude the following (please correct me if I am 
wrong):

The problem is caused by scroll increments which are not equal to the 
value of the lineInc of the scrollbar due to:
     - use of the mouse scrollwheel
     - dragging the scrollThumb
     - clicking in the area between the thumb and the arrows
     - the last increment  when using the arrows on the scrollbar.

  All this is accentuated when the height of a scrolling field is not 
conform to the following ratio:
      effective textheight * the number of lines visible in the field +  
margin

To see increments at work, try the following handler in the script of a 
height adjusted and a not height adjusted scrolling field:

on scrollbardrag x
   put (the number of lines in me - (the height of me div the effective 
textheight of me)) * (the effective textheight of me) into maxscroll
   put x && x mod (the effective textheight of me) && maxscroll
end scrollbardrag

When the font of a scrolling field is set, its lineInc value is 
automatically set to the effective textheight of the field.
But its pageInc value is not always set to an adjusted value. (If the 
possibility of changing the properties of a scrollbar of a scrolling 
field is implemented and someone knows how to set these then please 
share the knowledge.)
A workaround for me in the meantime are the following handlers, 
sometimes combined with the use of a separate scrollbar (in which all 
the properties can be reached) :

on scrollBarDrag x
   set the scroll of fld <fieldname> to x - (x mod the effective 
textheight of fld <fieldname>)
end scrollBarDrag

on rawKeyDown x
   if x = 65308 or x = 65309 then
     lock screen
     get the scroll of fld <fieldname>
     switch x
     case 65308
       add the effective textheight of field <fieldname>to it
       break
     case 65309
       subtract the effective textheight of field <fieldname> from it
       break
     end switch
     set the scroll of fld <fieldname> to it - (it mod the effective 
textheight of fld <fieldname>)
     unlock screen
   else pass rawKeyDown
end rawKeyDown

For the purists:

on scrollBarDrag x
   put (the number of lines in fld <fieldname> - (the height of fld 
<fieldname> div effective textheight of fld <fieldname>)) * (effective 
textheight of fld <fieldname>) into maxscroll
   if x >= maxscroll then set the scroll of fld <fieldname> to maxscroll
   else set the scroll of fld <fieldname> to x - (x mod the effective 
textheight of fld <fieldname>)
end scrollBarDrag


on rawKeyDown x
   if x = 65308 or x = 65309 then
     lock screen
     get the scroll of fld <fieldname>
     switch x
     case 65308
       add the effective textheight of field <fieldname> to it
       break
     case 65309
       subtract the effective textheight of field <fieldname> from it
       break
     end switch
   put (the number of lines in fld <fieldname> - (the height of fld 
<fieldname> div effective textheight of fld <fieldname>)) * (effective 
textheight of fld <fieldname>) into maxscroll
   if x >= maxscroll then set the scroll of fld <fieldname> to maxscroll
     else set the scroll of fld <fieldname> to it - (it mod the 
effective textheight of fld <fieldname>)
     unlock screen
   else pass rawKeyDown
end rawKeyDown

If the height of the scrolling field is not adjusted and the lowest 
visible line in the field is only showing its upper part then one has 
to add a trailing <cr> to the text in the field to be able to see the 
last line completely.

So another way to make an "iTunes-type alternate colored lines in 
scrolling list field" :
    Make a scrollable list field.
    Set its script to the scrollBarDrag handler.
    Cover the text part with a transparent locked field to trap the 
mouseclicks.
    Set its script to the rawKeyDown handler.
    And colorize the alternate lines of the list field by:

on mouseUp
    put 0 into x
   put x  into a
   repeat (the number of lines of fld <fieldname> div 2)
     add 2 to x
     put "," & x after a
   end repeat
   set the hilitedline of fld <fieldname> to a
end mouseUp

All this is working on Mac OS X but is not tested on other platforms by 
lack of them.
Sorry for the lengthy mail.
Greetings,
WA



More information about the Use-livecode mailing list