Set Text to the Vertical Center of the field
Richard Gaskin
ambassador at fourthworld.com
Sat Apr 2 17:42:09 EDT 2016
Sannyasin Brahmanathaswami wrote:
> Someone sent me this solution off line..
>
> on mouseUp
> CenterTextVertically "field 2"
> end mouseUp
>
> on CenterTextVertically myFld
> put the effective textHeight of myFld into tTextHeight
> put item 2 of the loc of myFld into tfield
> put the formattedRect of line 1 to - 1 of myFld into tFormatRect
> put item 4 of tFormatRect - item 2 of tFormatRect into tFormatHeight
> put tFormatHeight div 2 into tFormatHalfHeight
> put item 2 of tFormatRect into tCurrFormatTop
> put tfieldY - tCurrFormatTop into tCenterField_To_TopTextDiff
> set the topMargin of myFld to the topMargin of myFld +
tCenterField_To_TopTextDiff - tFormatHalfHeight
> end CenterTextVertically
>
> But, agreed, it should be a 3 liner will you "bug it" for us?
The first executable line there sets a value in tTextHeight but doesn't
use it later on, so it's really fewer lines than it appears. :)
The number of lines isn't as important as that it's possible.
That one's just a longer version of Jacque's algo, which gets the
difference between the formatted height of the text from the field, and
set the topMargin to half of that.
That's logical and should work, but trying my version this morning and
later Jacque's and this one, all of them are a bit off and more than a
bit funky: if you click the button multiple times the text moves up and
down in ever smaller increments before settling into a position that's
somewhat close the vertically centered, but too high in tall fields and
too low in short fields.
So a bug report wouldn't be for any specific number of lines, but merely
that either the topMargin and/or formattedHeight be fixed so it can be
possible to apply good logic to get good results.
--
Richard Gaskin
Fourth World Systems
Software Design and Development for the Desktop, Mobile, and the Web
____________________________________________________________________
Ambassador at FourthWorld.com http://www.FourthWorld.com
More information about the use-livecode
mailing list