How to center a control?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
peaslee
Posts: 20
Joined: Wed Feb 16, 2011 8:36 pm

How to center a control?

Post by peaslee » Sat Feb 19, 2011 12:04 am

Hi,

I'm just getting started and think I'm progressing fairly well, but I cannot find out how to center a control on a card.

Thanks in advance.
Bruce Peaslee
Windows 7 Home Premium (Service Pack 1)
ACPI x-64 based PC 9GB RAM

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: How to center a control?

Post by Dixie » Sat Feb 19, 2011 12:29 am

peaslee...

Well, let's say you want to place a button at the centre of a card...

Code: Select all

set the loc of button 1 to the loc of this card
Have a read of the dictionary... look at 'Location'

be well

Dixie

doc
Posts: 148
Joined: Fri Jun 09, 2006 4:30 pm

Re: How to center a control?

Post by doc » Sat Feb 19, 2011 3:30 am

Is this the peaslee that I know from elsewhere?

-Doc-

peaslee
Posts: 20
Joined: Wed Feb 16, 2011 8:36 pm

Re: How to center a control?

Post by peaslee » Sun Feb 20, 2011 5:14 pm

doc wrote:Is this the peaslee that I know from elsewhere?

-Doc-
Could there be more than one?

Bruce
Bruce Peaslee
Windows 7 Home Premium (Service Pack 1)
ACPI x-64 based PC 9GB RAM

peaslee
Posts: 20
Joined: Wed Feb 16, 2011 8:36 pm

Re: How to center a control?

Post by peaslee » Sun Feb 20, 2011 5:24 pm

Dixie,

Sorry I wasn't clear enough. There are ways in the IDE to align controls against each other. What I want to do is center a control or group of controls vertically and/or horizontally without computing the location.
Bruce Peaslee
Windows 7 Home Premium (Service Pack 1)
ACPI x-64 based PC 9GB RAM

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: How to center a control?

Post by jmburnod » Sun Feb 20, 2011 5:48 pm

Hi peaslee,

Look at the menu "Object", "Aligne Selected Control"

Best

Jean-Marc
https://alternatic.ch

doc
Posts: 148
Joined: Fri Jun 09, 2006 4:30 pm

Re: How to center a control?

Post by doc » Sun Feb 20, 2011 6:22 pm

Could there be more than one?

Bruce
Well, I didn't think so, but ya never now these days... :wink:

Don't know how far or deep you've gotten involved in LiveCode yet Bruce, but if you wait out the "what is crazy stuff all about" syndrome, you'll love it!

I've been an "official user" for about six years now and almost exclusively for the last three or so. There aren't many languages out there that I haven't tried at one time or the other and absolutely NOTHING holds a candle to the productivity I've found using LiveCode. It's opened up a whole range of projects for me that I would have been hesitant to even attempt in years past... These days, If I can envision it, I just dive right in and go at it. :)

Good to see ya here sir, and hope you have fun with it!

-Doc-

doc
Posts: 148
Joined: Fri Jun 09, 2006 4:30 pm

Re: How to center a control?

Post by doc » Sun Feb 20, 2011 6:47 pm

Are you asking about spacing/distributing a group of selected controls equally maybe?
If that's the case, you can access the "align objects" menu from the properties palette once you have more than one control selected.

Image

-Doc-

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: How to center a control?

Post by Dixie » Sun Feb 20, 2011 6:52 pm

Peaslee...

I hope that I have now understood what you want :)
Have a look at the attached stack

be well

Dixie

PS.... now having seen Doc's reply, I obviously didn't understand :(
Attachments
buttonAlign.rev.zip
(1.41 KiB) Downloaded 331 times

peaslee
Posts: 20
Joined: Wed Feb 16, 2011 8:36 pm

Re: How to center a control?

Post by peaslee » Sun Feb 20, 2011 8:24 pm

We're getting closer. I want to center a control horizontally. This dialog editor is from a different system. With Button 1 highlighted, clicking on the button at the end of the arrow centers Button 1 horizontally in the dialog. (Sorry for the size of the arrow.) Can I do the same here or do I have to compute its location?
Attachments
Center.jpg
Center.jpg (40.79 KiB) Viewed 10937 times
Bruce Peaslee
Windows 7 Home Premium (Service Pack 1)
ACPI x-64 based PC 9GB RAM

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Re: How to center a control?

Post by Janschenkel » Mon Feb 21, 2011 6:53 am

You can easily determine the new location of the button by taking the 'x' part of the location of the card and the 'y' part of the location of the button. Here's some example code:

Code: Select all

on mouseUp
   local tNewLocation
   put item 1 of the location of this card & \
          comma & item 2 of the location of me \
          into tNewLocation
   set the location of me to tNewLocation
end mouseUp
HTH,

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

peaslee
Posts: 20
Joined: Wed Feb 16, 2011 8:36 pm

Re: How to center a control?

Post by peaslee » Wed Jun 15, 2011 7:30 pm

I found a way to trick the IDE. If you have three buttons, you can align them across the card with the Inspector, and the middle on gets centered. So I add a button on either side, center them, then delete the extra two.
Bruce Peaslee
Windows 7 Home Premium (Service Pack 1)
ACPI x-64 based PC 9GB RAM

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How to center a control?

Post by Klaus » Thu Jun 16, 2011 11:09 am

Hi Bruce,

you can also use "the loc" of the current card as a reference!

To center an object horizontally AND vertically:
...
set the loc of btn x to the loc of this cd
...
Only horizontally:
...
put item 1 of the loc of this cd into tX
put item 2 of the loc of btn X into tY
set the loc of btn x to tX,tY
...
Only vertically:
...
put item 1 of the loc of btn X into tX
put item 2 of the loc of this cd into tY
set the loc of btn X to tX,tY
...
You get the picture.


Best

Klaus

peaslee
Posts: 20
Joined: Wed Feb 16, 2011 8:36 pm

Re: How to center a control?

Post by peaslee » Thu Jun 16, 2011 7:57 pm

Klaus

It took me about twenty minutes with graph paper and the Dictionary to see why that works, but it was good for my education.

Thanks,

Bruce
Bruce Peaslee
Windows 7 Home Premium (Service Pack 1)
ACPI x-64 based PC 9GB RAM

Post Reply