Tech Tip: Shrink Font Size to Fit while Anchoring Text
PRODUCT: 4D | VERSION: 20 | PLATFORM: Mac & Win
Published On: June 24, 2024
To shrink the font of an input box to fit while anchoring the text, the following code can be used whenever the input text is updated:
Form.result:="1"+Form.result // update the text field $size:=40 // starting font size $input_width:=200 // Adjust font size Repeat OBJECT GET BEST SIZE(*; "Input"; $bestWidth;$bestHeight; $input_width) If ($bestHeight>=49) $size:=$size-1 OBJECT SET FONT SIZE(*; "Input"; $size) End if Until ($bestHeight<50) // Anchor text to the bottom OBJECT GET COORDINATES(*; "Input"; $left; $top; $right; $bottom) OBJECT SET COORDINATES(*; "Input"; $left; $top-$bestHeight; $right; $bottom) |