Align baselines of 2 fields

Bob Sneidar bobsneidar at iotecdigital.com
Thu Jun 21 15:58:18 EDT 2018


Okay a newer NEWER version. If no parameters are passed for the fields, it will use the first two hilited objects. Also, I check that pOffset is a number by adding 0 to it in a try/catch statement. 


on alignFieldBaselines pField1, pField2, pOffset
  local tDescent1, tDescent2, tBot1, tBot2, tDiff1, tDiff2, tRef
  local fFormattedBottom1, fFormattedBottom2

   -- check passed parameters
   if pField1 is empty and pField2 is empty then
      put the selectedObjects into pFieldList
      put line 1 of pFieldList into pField1
      put line 2 of pFieldList into pField2
   end if
   

  -- check passed parameters
  try
     if word 1 to 2 of pField1 is not "Field ID" then put the long id of field pField1 into pField1
     if word 1 to 2 of pField2 is not "Field ID" then put the long id of field pField2 into pField2
     if pOffset is empty then put 0 into pOffset
     add 0 to pOffset
  catch theError
     return "Invalid parameter passed."
  end try

  -- get the formatted bottoms of both fields
  put item 4 of the formattedRect of line 1 of pField1 into fFormattedBottom1
  put item 4 of the formattedRect of line 1 of pField2 into fFormattedBottom2

  -- calculate the descents of both fields
  put item 4 of measureText(line 1 of pField1, pField1 ,"bounds") into tDescent1
  put item 4 measureText(line 1 of pField2, pField2 ,"bounds") into tDescent2

  -- get the bottom of both fields
  put the bottom of pField1 into tBot1
  put the bottom of pField2 into tBot2

  -- calculate the differences
  put tBot1 - fFormattedBottom1 + tDescent1 into tDiff1
  put tBot2 - fFormattedBottom2 + tDescent2 into tDiff2

  -- calculate and set the new bottom for field 2
  put the bottom of pField1 -(tDiff1 - tDiff2) into tRef
  set the bottom of pField2 to tRef  + pOffset
end alignFieldBaselines
_______________________________________________
use-livecode mailing list
use-livecode at lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode





More information about the use-livecode mailing list