04-01-2011 04:33 PM - edited 04-01-2011 04:39 PM
Can not wrap up my brain around simple centering problem... I guess that becasue it is friday!?
Lets say I have to position 3 Buttons side by side in variable width container, and I want them to be always centered in that container vertically and horizontally. How to acheiwe that with Container?
And we a talking about QNX components only, and 3 bunnons mean [2:n] bumber of buttons
Solved! Go to Solution.
04-01-2011 04:35 PM - edited 04-01-2011 04:35 PM
I'd use an HGroup with verticalAlign and horizontalAlign set to middle and center. Should work for what you're asking for I believe.
04-01-2011 04:36 PM - edited 04-01-2011 04:42 PM
assume container name is container. and button name is button
button.setPosition = ((container.width - button.width/2), (container.height - button.height/2));
I might be a little rusty but that should do the trick.
EDIT: That will actually place it directly in the middle of the container. If you wanted it one to be 25% of the way in, and one 75%, you'd have to use the following
button.setPosition = ((container.width - button.width/4), (container.height - button.height/4));
75% (the math on this might be wrong - maybe someone can chime in and help)
button.setPosition = ((container.width - button.width*.75), (container.height - button.height*.75));
04-01-2011 04:43 PM
Edited my post to avoid layering all of them on top of each other.
04-01-2011 05:15 PM - edited 04-01-2011 05:20 PM
Cup of coffee cleared my mind so here is solution and I'm sorry guys that I didn't think hard enough at the beginning and asked you to think, but I believe this might be helpful to many other people:
Key thing here is SPACER, people never forget about Spacers... LOL
var container:Container = new Container();
var bb1:LabelButton = new LabelButton();
bb1.label = "Knopka1"
bb1.width = 120;
var bb2:LabelButton = new LabelButton();
bb2.label = "Knopka2"
bb2.width = 120;
var bb3:LabelButton = new LabelButton();
bb3.label = "Knopka3"
bb3.width = 120;
container.margins = Vector.<Number>([10,10,10,10]);
container.width = 500;
container.height = 200;
container.debugColor = 0x0033FF;
container.flow = ContainerFlow.HORIZONTAL;
container.align = ContainerAlign.MID;
container.padding = 10;
var sp1:Spacer = new Spacer();
var sp2:Spacer = new Spacer();