Center text within a field?

Trevor DeVore lists at mangomultimedia.com
Wed Jun 6 17:24:23 EDT 2007


On Jun 6, 2007, at 1:07 PM, J. Landman Gay wrote:

> Does this work? :
>
> on mouseUp
>   set the width of fld 1 to the width of grc 1 -- the circle
>   get the textsize of fld 1
>   set the textheight of fld 1 to it + (it div 3)
>   set the height of fld 1 to the formattedheight of fld 1
>   set the margins of fld 1 to the textheight of fld 1 div 3
>   set the loc of fld 1 to the loc of grc 1
> end mouseUp
>
> The field must have fixedLineHeight set to false. You might have to  
> jiggle the margins and textheight calcs a little bit.

Unfortunately it won't work in all cases. Using a field with the text  
set to "1" and the textfont set to "webdings" is a good test case.  
The problem is that even though you may have the textsize set to 100,  
the vertical space taken up by the character is only 70 pixels (on my  
Mac). Other characters in the font might take up more or less  
vertical space.

While webdings isn't a font that will be used in what I'm doing it  
does illustrate the problem nicely. The textsize of a char does not  
return the actual vertical space taken up by the char so it makes it  
difficult to find the exact center of text that is being displayed.

-- 
Trevor DeVore
Blue Mango Learning Systems
www.bluemangolearning.com    -    www.screensteps.com
trevor at bluemangolearning.com





More information about the use-livecode mailing list