Vertically aligning text in a field
BNig
bernd.niggemann at uni-wh.de
Fri Dec 19 17:59:28 EST 2014
Hi Ralph,
I have not tried this all on mobile devices. But on desktops the baseline of
the first line is consistently found with this piece of code. I had the need
for a starting point for a gradient behind the text and had difficulties
finding a consitent reference point. I found the base line of line 1 and
from then on the textHeight is ok.
There is something in the first line that is not exactly the textHeight. Or
I haven't found it.
Anyways here is the code for a field with fixedTextHeight. TextHeight can be
manually/by script set to be different from the automatic textHeight when
choosing a textSize.
Margins border are taken into account. This piece of code is surpisingly
robust...
this is on mouseEnter for a a field, make a horizontal line graphic
"gBaseLine" to see where it is and turn in the Properties Inspector -> Table
-> hGrid on to see the base lines
as always watch out for line breaks
---------------------------------------------
on mouseEnter
-- now calculate the position of the first base line of the first line of
the field.
-- = first horizontal divider from top
-- the gradient should go there
-- find out difference between automatic textheight and manually set
textHeight
-- formula according to documentation
put the effective textSize of me into tTextSize
put trunc(4/3*tTextSize) into tRegularTextHeight
put the effective textHeight of me - tRegularTextHeight into tDiff
-- the first line is not the formattedHeight but changes according to the
font size
-- formula found by experimentation
put round (((tTextSize - 22) * 1/3)) into tKorr
-- NOTE added 1 to the calculated From
-- the vertical coordinate of the gradient from
put the top of me + the effective textSize of me + the borderWidth of me
\
+ the topMargin of me + tKorr + tDiff into tFirstBaseLineY
put the vScroll of me into tVScroll
subtract tVScroll from tYofFirstBaseLine
if there is a graphic "gBaseLine" then
set the top of grc "gBaseLine" to tFirstBaseLineY
end if
end mouseEnter
---------------------------------------------
Ralph DiMola wrote
> I have been working on this for a while. I found out that the base line is
> different on various platforms. This makes the calculation change on
> various
> platforms. See bugs http://quality.runrev.com/show_bug.cgi?id=13551 and
> http://quality.runrev.com/show_bug.cgi?id=12176 .
>
> Ralph DiMola
> IT Director
--
View this message in context: http://runtime-revolution.278305.n4.nabble.com/Vertically-aligning-text-in-a-field-tp4686824p4686969.html
Sent from the Revolution - User mailing list archive at Nabble.com.
More information about the use-livecode
mailing list