Automatic object resizing on card changes
Mark Schonewille
m.schonewille at economy-x-talk.com
Fri Nov 4 07:44:26 EDT 2011
Hi John,
This really depends on the situation. Here's a very simple example:
on resizeStack
put the rect if this cd into myRect
add 16 to item 1 of myRect
add 16 to item 2 of myRect
subtract 16 from item 3 of myRect
subtract 16 from item 4 of myRect
set the rect of fld 1 to myRect
end resizeStack
By setting object sizes and positions relative to the card rect, you avoid many problems. If e.g. you calculate the new points based on the current points relative to the card rect, your objects will slowly change location:
// wrong
on resizeStack theOldW,theOldH,theNewW,theNewH
put the loc of fld 1 into myLoc
put item 1 of fld myLoc / theOldW into myRatio
put myRatio * theNewW & comma & item 2 of myLoc into myNewLoc
set the loc of fld 1 to myNewLoc
end resizeStack
The script above will eventually round off the loc of the object and the location may be off by one pixel. Instead, try to find a way to set the location directly:
// correct
on resizeStack
set the loc of fld 1 to item 1 of the loc of this cd & comma & item 2 of the loc of fld 1
end resizeStack
The second (quite obvious) approach will never cause rounding problems. Btw, the second and third script change the location of a field horizontally, relative to the right side of a card, keeping the field horizontally centered.
--
Best regards,
Mark Schonewille
Economy-x-Talk Consulting and Software Engineering
Homepage: http://economy-x-talk.com
Twitter: http://twitter.com/xtalkprogrammer
KvK: 50277553
Become our partner in sales http://qery.us/16r Start selling Color Converter today. 20% commission!
On 3 nov 2011, at 18:46, John Brozycki wrote:
> Hello,
>
> Given a resizable stack with, say, two cards that both have objects that have their geometry set to scale on resize (like a text field) what is the best way to get objects on card 2 to automatically resize when card one is resized and then a button is selected to go to card 2? It doesn't do this automatically- you have to resize the second card. Make the second card much larger than the first was, and when you go back the objects on the first card are all off. With each card, you have to manually resize for the objects to adjust properly. Shouldn't this happen automatically when you configure the geometry settings? I've tried using revWChangeWindowSize on my button to the next card, but it doesn't appear to do anything for object sizing. Sorry if this is a basic question, but I can't find how to do this.
>
> Much thanks,
> John
>
More information about the use-livecode
mailing list