[How To] Align objects through script

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
palanolho
Posts: 122
Joined: Sat Apr 27, 2013 11:40 pm

[How To] Align objects through script

Post by palanolho »

Greetings everyone,

I'm struggling with something and maybe someone has an idea how I can pull this one off.

I have 2 objects (lets say 2 rectangles) and I need to align one of them (vertically or horizontally) relatively to the other one.

Anyone know how this can be done? using the tools it would be easy but, how can this be done using a script?

Many thanks in advance
- Miguel Pinto
SparkOut
Posts: 2987
Joined: Sun Sep 23, 2007 4:58 pm

Re: [How To] Align objects through script

Post by SparkOut »

Hi Miguel,
The left, right, top, bottom, width, height, rect and loc of an object are all settable properties.

If you have two rectangles at the correct vertical position on the card and want to align the two to the same horizontal position you can do something like

Code: Select all

set the left of graphic "rectangle2" to the left of graphic "rectangle1"
If they are different widths and you want to align them according to the centre you will have to do a little construction of the new co-ordinates

Code: Select all

put item 1 of the loc of graphic "rectangle1" into item 1 of tNewLoc
put item 2 of the loc of graphic "rectangle2" into item 2 of tNewLoc
set the loc of graphic "rectangle2" to tNewLoc
Hope that helps
palanolho
Posts: 122
Joined: Sat Apr 27, 2013 11:40 pm

Re: [How To] Align objects through script

Post by palanolho »

Cool, It was exactly this I was looking for.

I had read something about the left, right, etc... but didn't know that I could use it like that

Many thanks!
- Miguel
Post Reply