How should center alignment of child components work?

I'm working on a class called "LayoutManager" which provides interface to layout child windows or controls within parent window.

There are several enumerations within a class used to control alignment, ex:
1
2
3
4
5
6
7
8
9
10
/** Alignment options for Horizontal orientation */
enum class HorizontalAlignment
{
	// Child windows are aligned from left to right
	Left,
	// Child windows are centered
	Center,
	// Child windows are aligned from right to left
	Right,
};

Left and Right alignment is self explanatory, for ex. let's say you have 5 buttons,
with Left alignment this means they're aligned like this:
Parent left border, 1,2,3,4,5, empty space...

With the Right alignment they're aligned in reverse order from the right:
Parent right border, empty space, 5,4,3,2,1, parent right border

But with center alignment there is a problem because how exactly should center alignment work? there are 4 possibilities:
Option 1 (from center out):
[window space], 4, 2, 1, 3, 5, [window space]

Option 2 (center left to right)
[window space], 1, 2, 3, 4, 5, [window space]

Option 3 (center right to left)
[window space], 5,4,3,2,1, [window space]

Option 2 further brings a question as to whether center out should favor right over left when centering out, ex:
Option 4 (from center out but slightly different order):
[window space], 5, 3, 1, 2, 4, [window space]

Thus for Center alignment there are in total 4 behaviors on how to implement it, all 4 options center child windows but in different manner.

What would you say, which of these 4 possibilities should be "the right" way to implement Center alignment?
What should be expected behavior?

I would also like to add that numerical order of child windows, ex, 1,2,3,4,5 is well known, the order corresponds to the order in which child windows were created and attached to parent.
Therefore during creation of child window one can have control over alignment order prior to alignment.
But this doesn't help in determining or controlling how center alignment should work.
Last edited on
I don't think I have ever seen an API where alignment affects the order of the elements.
Thank you, that's insightful, therefore child controls should always be left to right ordered?

Left alignment:
[space],1,2,3,4,5

Right alignment:
1,2,3,4,5,[space]

Center alignment:
[space]1,2,3,4,5,[space]

Is this what would be expected or what you're saying?
Last edited on
Yes, that would be my expectation.

If you want you could of course provide a way to specify the order, separate from alignment, but I'm not sure how useful a "center out" order would be. If someone want it they can just add the elements in a different order.
Awesome, this makes perfect sense.

I really don't know why did I consider center out.
Thank you.
Option 1 and Option 4 are to have the odd valued ones on one side and the even ones on the other. Depending upon the usage, this may or may not be valid. If it is, then there is the question of the sort order for each side.
Option 1 and 4 are "left first then right"

That is from the center, put left to center then right to center, and so on, left side always gets it's component before right side.

With 7 buttons it would therefore be:
6,4,2,1,3,5,7

When there is even count of child controls, each side get equal share but ordering is same ex:
5,3,1,2,4,6

But I already got rid of this method, I've implemented layout so that it's always left to right in the order in which controls were attached.

However it's possible that the order is right to left for right alignment and left to right for left alignment, but I don't know how useful it would be, that is whether it would be expected behavior for alignment.
Last edited on
Topic archived. No new replies allowed.