Set Text to the Vertical Center of the field
Sannyasin Brahmanathaswami
brahma at hindu.org
Sat Apr 2 17:09:38 EDT 2016
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?
and this from Jacque
> The formattedheight of the entire field apparently isn't the same as the
> formattedheight of the totals of the lines.
makes no sense to me... or at least it would be good to know the difference in precise terms.
On April 2, 2016 at 8:34:25 AM, Richard Gaskin (ambassador at fourthworld.com(mailto:ambassador at fourthworld.com)) wrote:
> IMNSO if this can't be done in three lines using Jacque's method it's a bug.
>
> put the formattedheight of line 1 to -1 of me into tTotalTextHt
> put ( ( the height of me - tTotalTextHt ) / 2) into tTopMargin
> set topmargin of me to tTopMargin
>
> Logically that should work regardless of text size or fixedLineHeight.
>
> Can anyone here think of a reason it might not be considered a bug?
More information about the use-livecode
mailing list