Find the scroll location in wrapped field

dunbarx at aol.com dunbarx at aol.com
Tue Nov 18 14:08:38 EST 2014


Richard.


I tried a bunch of stuff like that; your thinking seems sound. I thought mine did as well.  Sometimes it sets a line properly, and sometimes, especially  with small textSize lines near large ones, not at all. In fact, several lines away.


I have a field with widely varied textSizes and ran your handler. It just does not seem to work. Again, I made a small field with:



on mouseUp
   repeat with y = 1 to 100
      put y into line y of fld 1
   end repeat
   repeat with y = 1 to the number of lines of fld 1
      set the textSize of line y of fld 1 to random(20) + 6
   end repeat
end mouseUp


Now if I try to select, say line 44, as Jacque suggested, (never mind which direction you are coming from, let us assume you are always at the bottom of the scroll) it will not position the data nicely. With your code, sometimes it works, and  sometimes it can be three lines off, again, usually when the stringWeAreLookingFor happens to be a small textSize, near very large ones.


Craig





 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)






-----Original Message-----
From: Richard Gaskin <ambassador at fourthworld.com>
To: use-livecode <use-livecode at lists.runrev.com>
Sent: Tue, Nov 18, 2014 10:15 am
Subject: Re: Find the scroll location in wrapped field


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

_______________________________________________
use-livecode mailing list
use-livecode at lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

 



More information about the use-livecode mailing list