Set Text to the Vertical Center of the field

Ralph DiMola rdimola at evergreeninfo.net
Sat Apr 2 20:52:13 EDT 2016


This is working for me but does fall apart when the field gets very small.
Also the font baselines change from Windows to both iOS and Android. Bug
12176 I have had many many variations of this task and this one is the best
I've found so far but I digress, I think there's bug because if the Yoda's
of LC can't get it right.... it's a bug.


Command CenterVert Obj -- for any control
   
   Local tMargins , tHeight , tFheight , tSpace

   put (0,0,0,0) into tMargins
   try
    put item 1 of the margins of obj into item 1 of tMargins
    put item 3 of the margins of obj into item 3 of tMargins
   catch SomeError
    exit CenterVert -- Can't get margins?... do nothing
   end try
   put the height of obj into tHeight
   try
      put the effective formattedheight of char 1 to -1 of obj into tFheight
--for fields. Note the EFFECTIVE.
   catch SomeError
      try
         put the formattedheight of control obj2 into tFheight -- for
buttons
      catch SomeError
         exit CenterVert -- Can't get the text height?... do nothing
      end try
   end try
   
   if tFheight < tHeight then -- make top/bottom margins 0 if text is
clipped
      put tHeight - tFheight into tSpace
      put trunc(tspace/2) into tspace -- This trunc seemed to help at
extremes.
      put tspace into item 2 of tMargins
      put tspace into item 4 of tMargins
   end if
   
   set the margins of Obj to tMargins
   
end CenterVert

Ralph DiMola
IT Director
Evergreen Information Services
rdimola at evergreeninfo.net





More information about the use-livecode mailing list