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
Please visit this url to subscribe, unsubscribe and manage your subscription 

Reply via email to