Set Text to the Vertical Center of the field

J. Landman Gay jacque at hyperactivesw.com
Sat Apr 2 19:06:50 EDT 2016


On 4/2/2016 1:34 PM, Richard Gaskin wrote:
> IMNSO if this can't be done in three lines using Jacque's method it's a
> bug.
>
>    put the formattedheight of line 1 to -1 of me into tTotalTextHt
>    put ( ( the height of me - tTotalTextHt ) / 2) into tTopMargin
>    set topmargin of me to tTopMargin
>
> Logically that should work regardless of text size or fixedLineHeight.
>
> Can anyone here think of a reason it might not be considered a bug?

If there's a bug, it appears to be that the current margins are part of 
the formattedheight, at least in LC 8. But it may not be a bug, I'm not 
sure. Setting the topmargin of a field to 0 gives a different 
formattedheight than a topmargin of a higher value (ditto setting 
bottomMargin or both.) So that's probably why getting the 
formattedheight of the lines instead of the whole field works better.

If my ascender/descender theory is right, then we need to add that 
clearance space back into the calculation. So:

on mouseUp
   put the effective textheight of me * .33 into tPadding
   put the formattedheight of line 1 to -1 of me into tTotalTextHt
   put ( ( the height of me - tTotalTextHt ) / 2) into tTopMargin
   set topmargin of me to tTopMargin + tPadding
end mouseUp

That seems to get us closer. I vaguely recall that the exact fraction of 
the textheight that's used for the padding was posted here a long time 
ago but I can't remember what it was, and .33 seems close.

-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com




More information about the use-livecode mailing list