List widgets from form.txt?

Started by alvin677, 10 February 2022, 10:44:55

alvin677

How can I list created widgets that I have loaded from a file using gui.loadWidgetsFromFile("form.txt"); ??
I would like to for example loop through all widgets and change the color of them.

texus

Do you want to save the form file with modified values?
I think you want something like this: (code is untested, there might be typos)
Code (cpp) Select
auto group = tgui::Group::create();
group->loadWidgetsFromFile("form.txt");
for (const tgui::Widget::Ptr& widget : group->getWidgets())
{
    auto button = widget->cast<tgui::Button>();
    if (button)  // If widget isn't a Button then 'button' will be nullptr
    {
        button->getRenderer()->setBackgroundColor(tgui::Color::Blue);
    }
}
group->saveWidgetsToFile("modified_form.txt");