fixed textheight affects scrolling?
Mark Waddingham
mark at livecode.com
Thu Jul 9 05:22:24 EDT 2020
On 2020-07-09 09:54, Klaus major-k via use-livecode wrote:
> Hi all,
>
>> Am 08.07.2020 um 17:51 schrieb Klaus major-k via use-livecode
>> <use-livecode at lists.runrev.com>:
>>
>> Hi friends,
>>
>> strange phenomenon, maybe I am missing something!?
>> LC 9.6 on macOS 10.14.6
>>
>> I have two fields with all available fonts and each line is formatted
>> directly
>> in the appropriate font it reads.
>>
>> I set the FixedLineHeight for ONE field to 28, doesn't matter
>> actually.
>>
>> Now I want to select a specific line in the fields with this script:
>> -------------------------------
>> on mouseUp pMouseButton
>> set the wholematches to TRUE
>> put lineoffset("Lucida Grande",fld "fonts") into tLine
>> ## Which is 366 in my fields!
>>
>> put the effective textheight of fld "fonts" into tTH
>> set the scroll of fld "fonts" to tLine*tTH + the height of fld
>> "fonts"
>> set the hilitedlines of fld "fonts" to tLine
>> end mouseUp
>> -------------------------------
>>
>> Works fine for the field WITHOUT fixedlineheigt and selects the line
>> -> Lucida Grande
>> However the same script used with the field WITH fixedlineheight, it
>> selects -> Lucida Grande Bold
>> which is the line AFTER "Lucida Grande" and actually line 367!?
>>
>> What am I overlooking?
>> Thanks for any hints!
I suspect the fact it works in the non-fixedline height case is
serendipity in this specific case - if line height isn't fixed then each
line will have a different height based on the fonts (although most will
be the same if the fontSize is the same)...
LineOffset is 1-based - so the first line has scroll 0ish (ish because
of field margins etc.) - that's probably the issue with your existing
code.
There's an easier way I think though which should be independent of any
field styling (size, font, wrapping)...
You can get the formattedTop of a line - which gives you the
card-relative y co-ordinate of the top of the including the fields top
and scroll. So this should do the trick:
set the scroll of field "fonts" to the scroll of field "fonts" + \
the formattedTop of line tLine of
field "fonts" - \
the top of field "fonts"
The adjustment is necessary because the scroll value is relative to the
top-left of the 'content' of the field.
Hope this helps!
Mark.
--
Mark Waddingham ~ mark at livecode.com ~ http://www.livecode.com/
LiveCode: Everyone can create apps
More information about the use-livecode
mailing list