Find the scroll location in wrapped field

Michael Doub mikedoub at gmail.com
Tue Nov 18 12:47:53 EST 2014


Richard,

I don't think the solution works because of a bug in livecode where 
spacebefore and spaceafter are not taken into account.

This is the problem:
put the formattedHeight of line 1 to tLOS of fld 1 into tScroll

I just posted my solution in the forums and I had to manually add them in.

I am also a bit confused about using the topmargin.  I agree with your 
logic but  I when I tried it, things were off, so I did not use in 
calculating the top.

I will post a new version of my MasterLibrary shortly and this will be 
included.

Regards,
    Mike




On 11/18/14 10:14 AM, Richard Gaskin wrote:
> 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)
>





More information about the use-livecode mailing list