FormattedHeight of a field and its contents

Ralph DiMola rdimola at evergreeninfo.net
Sat Feb 3 12:12:53 EST 2018


David,

Nice.... I've been wrestling with this. I am going to see how your observations translate into mobile. I'm going to apply your of findings to my app and see if I get better results than I get now. There have been a few threads in the past few years addressing vertically centering text in a field. None of them seem to address all font size cases. This 6px thingy might explain a lot! 

Thanks again for all your work.

Ralph DiMola
IT Director
Evergreen Information Services
rdimola at evergreeninfo.net

-----Original Message-----
From: use-livecode [mailto:use-livecode-bounces at lists.runrev.com] On Behalf Of David Epstein via use-livecode
Sent: Friday, February 02, 2018 9:38 PM
To: use-livecode at lists.runrev.com
Cc: David Epstein
Subject: Re: FormattedHeight of a field and its contents

Thanks for the responses on this.  I used Bernd’s tool and did some more tests, and found some things that may be helpful to others.

While the left and right margins of a field are meant literally (a 5 pixel left margin leaves 5 white pixels to the left of the text), the top margin is more complicated, no doubt owing to the variety of textHeights that need to be accommodated.  For example, a margin of "0" will often clip the top of the text--as if "0" meant a "negative margin".

6 seems to be a magic default value for a field's top margin, which avoids clipping the content.  With horizontal gridlines visible, a 6 pixel buffer makes the top row the same height as the other rows.  And with a 6 pixel buffer the formattedHeight of the field will exactly match the formattedHeight of the field's content (although a non-zero borderwidth or a horizontal scrollbar changes this).

Thus--what I wondered about in my original post--with a margin less than 6 the formattedHeight of the field is less than the formattedHeight of the content; the content is in effect clipped.  At smaller textHeights this will be visible, while at larger textHeights only white space above the characters is clipped.

I was trying to answer two questions, and I think I'm pretty close.

1. How do I make sure that the field's contents are all visible if I set the field's height to the formattedHeight?  Answer: Set the top and bottom margins to 6. For the left and right margins, even 1 pixel should be enough to keep everything visible.

2. What margins will provide a symmetrical look for a text box?
A top margin of 6 doesn’t look like a 6 pixel margin; how it looks depends on the textHeight.  I estimate that its apparent height is one fourth of the effective textHeight, and I use this to size the other margins in the “tightMargins” handler below.
While the top margin of 6 looks good with horizontal gridlines, without them (and especially if you show a text baseline) it looks too small compared to the space between subsequent lines.  To match that larger space, in effect doubling the apparent top margin, add one third of the effective textHeight.  See “niceMargins” handler below.

Example of usage:
set the margins of fld 1 to the niceMargins of fld 1 set the height of fld 1 to the formattedHeight of fld 1

getProp niceMargins
   put the effective textHeight of the target into t
   put round(t*7/12) into m1
   put round(t/3) into m2
   return m1,6+m2,m1,m1
end niceMargins

getProp tightMargins
   put round(.25*the effective textHeight of the target) into m
   return m,6,m,max(6,m)
end tightMargins

Improvements to these are welcomed.

David Epstein


_______________________________________________
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