I need to be able to vertically center text in a wrapping text field after a user has entered the text and clicked the appropriate button. The user can vary the text size before centering. The following script is associated with the button. Field height varies so it is passed via a global variable, and the other two variables are used elsewhere in the app.
global gThumbText, gPoke, gFieldHeight
on mouseUp
put field "TextEntry" into gThumbText
put number of lines in field "TextEntry" into tTextLines
put the effective textHeight of field "TextEntry" into tHeight
put (gFieldHeight/tHeight) into tMaxLines
put (tMaxLines - tTextLines)/2 into tReturns
put trunc(tReturns) into gPoke
repeat with x = 1 to gPoke
put return before field "TextEntry"
end repeat
end mouseUp
The above would work if "number of lines" returned the actual number of lines in the field, but it uses a CR to determine where a line ends. So a sentence that runs over six lines is reported as only one line.
I can't see a way to do what I want, so any help would be appreciated.
TIA
Don
Vertical centering by script
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Re: Vertical centering by script
Check out the "formattedText" property.
Used correctly, it will reformat wrapped lines in a field with hard CR's, making the number of visible lines equal to the number of actual lines. You can pre-store the wrapped text in a custom property if you need to restore the original.
Craig Newman
Used correctly, it will reformat wrapped lines in a field with hard CR's, making the number of visible lines equal to the number of actual lines. You can pre-store the wrapped text in a custom property if you need to restore the original.
Craig Newman
Re: Vertical centering by script
Thanks Craig
I had looked at the formatted text entry in the dictionary but did not twig how to use it for what I wanted. Now you have encouraged me to take a closer look, I realise it just needs something like:
put the number of lines of formattedtext of the field "myText" into tLines
etc.
Cheers
Don
I had looked at the formatted text entry in the dictionary but did not twig how to use it for what I wanted. Now you have encouraged me to take a closer look, I realise it just needs something like:
put the number of lines of formattedtext of the field "myText" into tLines
etc.
Cheers
Don