[SOLVED] How do I get an XML-defined child widget?


03-02-2009 13:24:12

I have the following layout:

<Skin name="HUD" size="300 200">
<Child type="Progress" skin="MyProgressSkin" offset="13 146 65 12" align="ALIGN_LEFT ALIGN_BOTTOM" name="HealthBar"/>

Create with:

MyGUI::WidgetPtr hud;
hud = mGUI->createWidget<MyGUI::Widget>
("HUD", 0, 0, mWidth, mHeight, MyGUI::ALIGN_LEFT | MyGUI::ALIGN_TOP, "Back");

How can I pick out the progress bar widget from the HUD? I would expect hud->findWidget("HealthBar") to work, but it doesn't. Apparently, the 'name' tag isn't meant for this purpose, although this would be the intuitive behavior.

I've also tried iterating through hud's child widgets with getEnumerator(), but the list is empty.

Is this possible? As it stands now, it looks like it's impossible to define the HUD without hard-coding all the positions.


03-02-2009 15:04:25

use Layouts


03-02-2009 15:35:22

Child widgets in skin used for internal widget use. You can create custom widget and make back end to get your widget, but usually you should do it another way:
We use layout and wrapper around it. You can look at BaseLayout class (better update svn first) that used in almost all MyGUI demos.

If you need only one widget it's easier to keep single ProgressBar and nothing more.


04-02-2009 01:02:08

Thanks, layouts did the trick! Not sure how I managed to miss that...