10 bugs in 2 minutes time!

Richard Gaskin ambassador at fourthworld.com
Thu Feb 12 11:23:16 EST 2004


Thomas McGrath III wrote:

> Is there a way to 'see' the scripts generated by the GM??
> 
> I would like to learn some of it's tricks to hand script some objects.

Poke around in the backscripts.

Learning from that might be useful in a general sense, but it's very
generalized so it's less valuable for understanding resizing.

Perhaps better for learning resizing is to make a stack with a few objects
and experiment.  You'll learn more in an hour of hands-on experimentation
than reading code that works very differently from how you'd solve the
problem yourself.

The most useful thing about the resizeStack message is that it comes with
two params, which give you the new width and height of the stack. So to make
a text field which conforms to Apple's 20-pixel boundry at the edge of
windows you could write:

on resizeStack x,y
  set the rect of fld 1 to 20,20,x-20,y-20
end resizeStack

When you have a lot of objects you may not want to hard-wire all
coordinates, just those that change.  One way to help with that is to use
handler that takes an object reference and a list of four points, ignoring
empty slots and using values present in other slots to adjust the rect:


on SetObjRect pObj
  put the rect of pObj into r
  repeat with i = 1 to 4
    get param(i+1)
    if it is not empty then put it into item i of r
  end repeat
   put r
  set the rect of pObj to r
end SetObjRect


To call it you just pass it an object reference and a list of new
coordinates, allowing you to write just one line per object even for
object-relative positioning:


on resizeStack x,y
  set the bottomright of btn "OK" to x-20,y-20
  set the bottomright of btn "Cancel" to (the left of btn "OK"-8),y-20
  SetObjRect the long ID of fld 1,"","",x-20,the top of btn "OK"-12
end resizeStack


-- 
 Richard Gaskin 
 Fourth World Media Corporation
 ___________________________________________________________
 Ambassador at FourthWorld.com       http://www.FourthWorld.com



More information about the use-livecode mailing list