Vertically aligning text in a field

BNig bernd.niggemann at uni-wh.de
Fri Dec 19 17:32:33 EST 2014


Hi Geoff,

I think I found a solution for variable textHeight and different fonts in a
field.

Try this. It is now independent from the textHeight and just uses the
formattedHeight.

And no need to watch out for wrapped text. Should work with any text whose
formattedRect and is reported correctly, which apparently according to Ralph
is not always the case on mobile devices.

This is again  for scrollbar for a field you configure to your liking. You
can optionally have visual feedback when you make 3 horizontal line graphics
and name them as stated in the script. The textSize is only changed for the
lines that don't have their textSize set explicitly. Uncheck "fixed
textHeight" in the properties inspector.
Not extensively tested but seems to work

Kind regards
Bernd

as always: watch out for line breaks
----------------------------------------------------------------------------
-- optionally have visual feedback
-- make 3 horizontal line graphics, "gTop", "gBot", "gCenter"
-- place them near the field

on scrollbarDrag pValue -- tested with values 9 to 36
   lock screen
   put the long id of fld "fTest" into myFld -- change to name of your field
   
   set the textSize of myFld to pValue -- block if you want
   
   CenterTextVertically myFld
   
   if there is a grc "gTop" AND there is a grc "gBot" AND there is a grc
"gCenter" then
      getFeedBack myFld
   end if
   
end scrollbarDrag

on CenterTextVertically myFld
   put the effective textHeight of myFld into tTextHeight
   put item 2 of the loc of myFld into tfieldY
   
   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

on getFeedBack myFld
   put the formattedRect of char 1 to - 1 of myFld into tFormatRect
   put item 2 of the loc of myFld into tfieldY
   set the top of grc "gTop" to item 2 of tFormatRect - 1
   set the top of grc "gBot" to item 4 of tFormatRect - 1
   set the top of grc "gCenter" to tFieldY - 1
end getFeedBack
----------------------------------------------------------------------------




--
View this message in context: http://runtime-revolution.278305.n4.nabble.com/Vertically-aligning-text-in-a-field-tp4686824p4686967.html
Sent from the Revolution - User mailing list archive at Nabble.com.




More information about the use-livecode mailing list