Line numbers for soft-wrapped styled text?

Alex Tweedly alex at tweedly.net
Tue Mar 28 16:13:29 EDT 2017


There is a bit of a problem I encountered trying to code this up.

I'm not 100% sure yet if it's a bug, though I think it must be. Comments 
anyone ?


If I set the 'spacebelow' of the last (Nth) line of a field, and get the 
formattedheight of the field, that includes the spacebelow value just set.

However, none of

   the formattedheight of line N of fld ...

   the formattedheight of line 1 to N of fld ...

   the formattedheight of line 1 to -1 of fld ...

include it.  The same is true of 'internal' lines - it's not just the 
last one in the field - the formattedheight of a chunk doesn't include 
any spacebelow set on the last line of the chunk.

This makes it near impossible to use a binary search accurately (or 
indeed to reliably use "the formattedheight of chunk xx of fld yy").

So now that I've describe it like that, I'm pretty sure it is a bug .... 
but comments welcome before I report it.

-- Alex.


On 28/03/2017 05:30, hh via use-livecode wrote:
> The solution of Alex T. was the first example I saw of a useful
> usage of the styledText array. TMHO this is the way to go for the
> future of more and more complicated styled text.
>
> As was said elsewhere, there could be a considerable speed up if
> first the visible range of lines, say numbers L1 to L2, is determined.
>
> We had once a thread in the forum about that. The fastest method:
>
> Compare the formattedHeight of line 1 to L of fld T to the vscroll v0
> of fld T. Not by walking with L up from one, but by using a binary
> search for L1 and then starting from there to find L2 by comparing to
> v0+the height of fld T. This needs only a few millisecs even for large
> chunks.
>
> Then use Alex's method with the styledText array of these lines. Or,
> quick and dirty, save the selectedChunk, select before each line L
> in the range L1 to L1 and collect the selectedLocs and then restore
> the selectedChunk.
>
> Now draw the line numbers each into an own freshly created field or
> use Alex's space below method.
>
> p.s. Hopefully you will share your final code.
>
>
> _______________________________________________
> 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