Set Text to the Vertical Center of the field

Sannyasin Brahmanathaswami brahma at hindu.org
Sat Apr 2 00:08:23 EDT 2016


 
lc8 16

I thought this should work to set the text of a field to vertical center

(in a behavior)

on mouseup
set the textsize of me to 28
put the formattedheight of me into tTotalTextHeight
put ( ( the height of me - tTotalTextHeight ) / 2) into tTopBottomMargins
set topmargin of me to tTopBottomMargins
end mouseUp

But it doesn't and the vertical position varies depending on the number of lines. field is 122 px high

1 line# rides very high in the field
2 Lines # rides high but not so much
3 lines # centered perfectly vertically.

Futher testing reveals that I'm getting variations of responses from for the formattedHeight in three different fields which

a) same number of lines
b) same text size
c) same text height
d) different words

go stack url "http://wiki.hindu.org/screenshots/formattedheights.livecode"

if you do "put the formattedheight of selected object()"

into the msg box, and select the two fields you get different values for each one, even though, obviously, they take exactly the same vertical space. And, to make matters more interesting. if you set 0 margins in both fields, set the top to the same, the text rides higher in the right field.

Am I doing something wrong or do we have something to report?










More information about the use-livecode mailing list