Arranging objects of equal width and height in 'matrix form'
Posted: Sun Jul 17, 2016 1:55 am
Because it's Sunday today here a utility script that may help some of you.
Example: Arranging 36 buttons in a 12x3-'matrix'
Delete example buttons:
Code: Select all
-- Creates a list of rectangles for objects
-- of equal width and height arranged as a
-- 'matrix' (rows and columns).
-- nr = number of rows of the objects
-- nc = number of columns of the objects
-- w = the width of each object
-- h = the height of each object
-- l = the left of the first object
-- t = the top of the first object
-- d = distance between objects
function createRectList nr,nc,w,h,l,t,d
if d is empty then put 1 into d
if t is empty then put d into t
if l is empty then put d into l
repeat with i=1 to nr
put t+(i-1)*h into i0
put (i-1)*d into dv
repeat with j=1 to nc
put l+(j-1)*w into j0
put (j-1)*d into dh
put cr & (j0+dh,i0+dv,j0+dh+w,i0+dv+h) after r
end repeat
end repeat
return char 2 to -1 of r
end createRectList
Code: Select all
-- This sizes/creates 12*3 buttons of width 64 and height 32
-- and arranges them in 12 rows and 3 columns with distance 2
-- [a button's "3d" increases 'visible' distance!]
-- topleft of the first button is (10,20)
on mouseUp
lock screen; lock messages
put createRectList(12,3,64,32,10,20,2) into r
repeat with i=1 to the num of lines of r
put ("b"&i) into b
if there is no btn b then create btn b
set rect of btn b to line i of r
end repeat
unlock screen; unlock messages
end mouseUp
Code: Select all
on mouseUp
lock screen; lock messages
repeat with i=999 down to 1
put ("b"&i) into b
if there is a btn b then delete btn b
end repeat
unlock screen; unlock messages
end mouseUp