I'm trying to resize and vertically center text in a field.
For text resizing I'm using this code (on the stack level):
Code: Select all
on resizeText
## Check if the text fits in the field
put the textSize of field "oneline" into tTextSize
if the formattedHeight of field "oneline" > the height of field "oneline" then
## Make the text smaller until it fits
repeat until the formattedHeight of field "oneline" <= the height of field "oneline"
subtract 1 from tTextSize
## Check that the text size is not less that the minimum size
if tTextSize >= the cMinimumTextSize of field "oneline" then
set the textSize of field "oneline" to tTextSize
else
exit repeat
end if
end repeat
else if the formattedHeight of field "oneline" < the height of field "oneline" then
## Make the text as large as possible
repeat until the formattedHeight of field "oneline" >= the height of field "oneline"
add 1 to tTextSize
## Check that the text size is not bigger that the maximum size
if tTextSize<= the cMaximumTextSize of field "oneline" then
set the textSize of field "oneline" to tTextSize
else
exit repeat
end if
end repeat
end if
end resizeText
cMaximumTextSize 24
cMinimumTextSize 14
and for vertical centering I'm using Bernd's code (on the stack level) - thanks Bernd!:
Code: Select all
## centering the text vertically
put the long id of fld "oneline" into myFld
put the effective textSize of myFld into tTextSize
put round (((tTextSize - 22) * 1/3)) into tKorr
put the formattedheight of char 1 to - 1 of myFld into myFormattedHeight
put (the height of myFld - myFormattedHeight) / 2 into myVerticalMargins
put myVerticalMargins - tKorr into tTopMargin
put myVerticalMargins + tKorr into tBotMargin
set the margins of myFld to 8,tTopMargin,8,tBotMargin
I can navigate with buttons (First, Previous, Random, Next and Last - code in the buttons) to display the respective lines.
When clicking on Next or Previous buttons time after time the display is reasonably OK. But when clicking for example on Random button few times it gets unpredictable.
Also when for example clicking buttons in this sequence:
First, Next, Previous (check the display!), Last, First (check the display again!) the display of the 1st line is not the same, not consistent.
How to make this display when navigating reliably resizing and vertically centering so that the whole line is visible without scrolling and the text size is such as to fill the good portion of the field?
The stack is attached.
Thanks!
keram