Page 1 of 1

How to center a control?

Posted: Sat Feb 19, 2011 12:04 am
by peaslee
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.

Re: How to center a control?

Posted: Sat Feb 19, 2011 12:29 am
by Dixie
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

Re: How to center a control?

Posted: Sat Feb 19, 2011 3:30 am
by doc
Is this the peaslee that I know from elsewhere?

-Doc-

Re: How to center a control?

Posted: Sun Feb 20, 2011 5:14 pm
by peaslee
doc wrote:Is this the peaslee that I know from elsewhere?

-Doc-
Could there be more than one?

Bruce

Re: How to center a control?

Posted: Sun Feb 20, 2011 5:24 pm
by peaslee
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.

Re: How to center a control?

Posted: Sun Feb 20, 2011 5:48 pm
by jmburnod
Hi peaslee,

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

Best

Jean-Marc

Re: How to center a control?

Posted: Sun Feb 20, 2011 6:22 pm
by doc
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-

Re: How to center a control?

Posted: Sun Feb 20, 2011 6:47 pm
by doc
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-

Re: How to center a control?

Posted: Sun Feb 20, 2011 6:52 pm
by Dixie
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 :(

Re: How to center a control?

Posted: Sun Feb 20, 2011 8:24 pm
by peaslee
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?

Re: How to center a control?

Posted: Mon Feb 21, 2011 6:53 am
by Janschenkel
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.

Re: How to center a control?

Posted: Wed Jun 15, 2011 7:30 pm
by peaslee
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.

Re: How to center a control?

Posted: Thu Jun 16, 2011 11:09 am
by Klaus
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

Re: How to center a control?

Posted: Thu Jun 16, 2011 7:57 pm
by peaslee
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