How do I obtain font metric information, such as the width of a formatted string, baseline, ascent, etc.
For example, how would I manually resize a button to accommodate a change to its label font and size?
Font Metrics
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Dear Leximatica,
Kind regards,
Mark
Code: Select all
set the height of btn 1 to (the formattedHeight of btn 1) + 16
set the width of btn 1 to (the formattedWidth of btn 1) + 16
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
-
- VIP Livecode Opensource Backer
- Posts: 10049
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Font Metrics
To set the size of a button to fit its text:Leximatica wrote:How do I obtain font metric information, such as the width of a formatted string, baseline, ascent, etc.
For example, how would I manually resize a button to accommodate a change to its label font and size?
Code: Select all
set the width of me to (the formattedWidth of me + 24)
set the height of me to (the effective textHeight of me + 12)
The "effective" keyword is a useful habit for many text properties like textHeight, because it returns the value used to render the control rather than the actual setting in the control itself.
Text and color properties are inherited, and if you set those properties to empty they assume those of their owner. Using "the effective textHeight" will return the textHeight used to render the control, even if the control's own textHeight property is empty.
The formattedWidth and formattedHeight properties work for most objects, returning the value needed to contain a control's contents.
In a button, it returns the width of the button after accounting for its text rendered at whatever its effective textFont, textSize, textFont and contents are, plus the borders and margins of the button.
For groups and cards, the formattedWidth and formattedHeight return the bounding rect comprised of all objects contained in that group or card.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn