question on control aligment by code...

Mark Wieder mwieder at ahsoftware.net
Tue Jun 1 12:01:15 EDT 2004


Andre, Sarah-

Here's what I use more generically. This creates a square grid and
populates it with new buttons. The variable dataTables contains a list
of the new buttons to place on the grid:

on mouseUp
  -- 100 pixel margins
  constant kTheMargin=100
  
  put the number of lines of dataTables into total
  put trunc(sqrt(total)) into hSize
  put trunc(hSize + (total - hSize^2) mod 1) into vSize
  put (the width of theTargetCard) - kTheMargin into theWidth
  put (the height of theTargetCard) - kTheMargin into theHeight
  put trunc(theWidth/hSize) into horizSpacing
  put trunc(theHeight/vSize) into vertSpacing

  repeat with y=0 to vSize-1
    repeat with x=0 to hSize-1
      create button
      put it into newButton
      set the layer of newButton to bottom
      set the loc of newButton to \
          kTheMargin + (x * horizSpacing), \
          kTheMargin + (y * vertSpacing)
      -- button formatting (optional stuff)
      set the name of newButton to line (x + (y * hSize))+1 of dataTables
      set the textFont of newButton to "Arial"
      set the textSize of newButton to 12
      set the textStyle of newButton to "bold"
      set the backgroundColor of newButton to "white"
      -- for variable size buttons
      set the width of newButton to the effective formattedWidth of newButton
    end repeat
  end repeat
end mouseUp

-- 
-Mark Wieder
 mwieder at ahsoftware.net



More information about the use-livecode mailing list