Hierarchical loading

klumhru

26-02-2010 16:44:29

Hi

I have a component based system and I'd like to load an xml for each component with that component's gui elements. Is there an easy way to track what widgets each MyGUI::Gui::load() method loads? I can track the changes by diffing the widgetenum before and after the load, but that's more than a little bit ugly :)

I've dug through the code a bit and I could just add a Widget::load(string layoutfile) I suppose, but I thought I'd ask if there was such a method somewhere already :)

Regards
Hogni

Altren

26-02-2010 16:54:13

std::vector<Widget*> loadedWIdgets = MyGUI::LayoutManager::getInstance().loadLayout("MyInterface.layout");this return list of root(!) widgets loaded in layout. So if you have some hierarchy in layout then you should also check child widgets.

klumhru

01-03-2010 18:27:59

Thanks


MyGUI::EnumeratorWidgetPtr ew = gui->getEnumerator();
WidgetPtrVector before;
while(ew.next())
{
before.push_back(ew.current());
}
gui->load(c->getLayout());
WidgetPtrVector after;
while(ew.next())
{
after.push_back(ew.current());
}
for(size_t a = 0; a < after.size(); a++)
{
bool existed = false;
for(size_t b = 0; b < before.size(); b++)
{
if(before[b] == after[a])
{
existed = true;
break;
}
}
if(!existed)
{
c->widgets.push_back(after[a]);
bindHandlers(after[a], c->owner);
}
}
componentWidgets[c] = c->widgets;

became
c->widgets = MyGUI::LayoutManager::getInstance().loadLayout(c->getLayout());
So thanks**2 ;)

klumhru

01-03-2010 18:34:34

Oh, by the way

Does LayoutManager::unloadLayout() destroy and clear memory for the given widgetvector items, or do I need to clean out the vector to be sure? I'm assuming it does as it's the companion of loadLayout, but I figured I'd make sure.

Altren

01-03-2010 19:18:27

Actually unloadLayout simply destroy each widget in vector. And vector itself is std::vector<Widget*> so you shouldn't care about it. But your copy of that vector will contain invalid pointer after you unloaded layout so clear() it anyway.

klumhru

02-03-2010 21:16:53

Yep.

The components do a bit of reloading of widgets so I was curious etc.

Thanks again.