A little rant on the alignment behaviour


30-12-2009 02:23:27

I'll start by explaining what i'm doing. I'm using MyGUI 2.2.3. I have a backgroung image that should take the whole screen. Then i have a few panels that are childs of that background StaticImage widged. Those panels should be centered on the screen and keep a defined distance to the bottom.

So I started by defining the background size as a percentage "0 0 100 100" and it's alignment to "Stretch". Afterwards I set the panels align to "HCenter Bottom". The big surprise arrived when I started changing the window's size. The panels kept centered, but their Y position wasn't affected at all. So I kept wondering what the hell that "Bottom" meant... It seemed not to be having any effect at all.

After a good while of playing with the alignment settings and stuff I figured a way to get the results I wanted. The problem is it looks kinda weird. I ended up setting the background's image size in pixels and calling this code after loading the layout:

mGUI->findWidgetT("MainMenu")->setSize(mWindow->getWidth(), mWindow->getHeight());
So, setting the background's image in pixels allows their childs to align properly, but doing it in with percentages does not. What am I doing wrong? Is this thing as bugged as it seems?


31-12-2009 00:21:47

setRealSize(0, 0, 1, 1);
press "pix" button in LayoutEditor and write "0 0 1 1"


31-12-2009 01:46:24

The only way it works properly is with the widget set as follows:
<Widget type="StaticImage" skin="StaticImage" position="0 0 1024 768" align="Stretch" layer="Back" name="MainMenu"> and then using either setSize or setRealSize after loading the layout.

To my understanding, I should get the same results with just setting the widget as:
<Widget type="StaticImage" skin="StaticImage" position_real="0 0 1 1" align="Stretch" layer="Back" name="MainMenu"> but the fact is that the child's alignment does not work properly in that case.

Oh, and the editor takes percentages in the range 0-100. That's why i said "0 0 100 100" on my first post.


31-12-2009 03:44:39

float percent = ...
float real_value = percent / 100f;

Alignment is behaviour instead of a command.