Find the scroll location in wrapped field

Richard Gaskin ambassador at fourthworld.com
Tue Nov 18 10:14:54 EST 2014


dunbarx wrote:
 >> James Hale wrote:
 >>
 >> So if you have the linenumber of the line contains the text you wish
 >> to see at the top of the field then...
 >>
 >>    select line  -1 of  field "TextToScroll"
 >>    select line linenumber of  field "TextToScroll"
 >>
 >> And line linenumber will now be at the top of the field.
 >
 >
 > The field will scroll to the desired line, but if the textSizes
 > of those lines are variable, the scroll will not come out right.
 >
 >
 > The discussion here and on the forum is how to make that happen.
 > So far, no solution. The OP wanted to find text, and this is
 > straightforward, in that the foundline can be used to set the
 > line selection. But his data was with mixed textSizes, and that
 > is how this all started.

If James were suggesting doing calculations based on textHeight you'd be 
spot-on, but by using selection he's relying on the engine's 
understanding of the text as rendered - testing here it seems to work 
quite well.

If we needed to do this with calculations only (if for some reason 
selection would be problematic), we could use the formattedHeight of 
line 1 to the desired line, subtracting the effective textheight of the 
desired line itself (and accounting for the topmargin), e.g.:

    put lineoffset("stringWeAreLookingFor", fld 1) into tLOS
    put the effective textheight of line tLOS of fld 1 into tHt
    put the formattedHeight of line 1 to tLOS of fld 1 into tScroll
    set the vscroll of fld 1 to (tScroll-tHt-the topmargin of fld 1)

-- 
  Richard Gaskin
  Fourth World Systems
  Software Design and Development for the Desktop, Mobile, and the Web
  ____________________________________________________________________
  Ambassador at FourthWorld.com                http://www.FourthWorld.com




More information about the use-livecode mailing list