Example #1
0
    void WidgetLoader::load(Container::Ptr parent, std::stringstream& stream)
    {
        auto rootNode = DataIO::parse(stream);

        if (rootNode->propertyValuePairs.size() != 0)
            loadWidget(rootNode, parent);

        for (auto& node : rootNode->children)
        {
            auto nameSeparator = node->name.find('.');
            auto widgetType = node->name.substr(0, nameSeparator);
            auto& loadFunction = m_loadFunctions[toLower(widgetType)];
            if (loadFunction)
            {
                std::string className;
                if (nameSeparator != std::string::npos)
                {
                    if ((node->name.size() >= nameSeparator + 2) && (node->name[nameSeparator+1] == '"') && (node->name.back() == '"'))
                        className = Deserializer::deserialize(ObjectConverter::Type::String, node->name.substr(nameSeparator + 1)).getString();
                    else
                        className = node->name.substr(nameSeparator + 1);
                }

                tgui::Widget::Ptr widget = loadFunction(node);
                parent->add(widget, className);
            }
            else
                throw Exception{"No load function exists for widget type '" + widgetType + "'."};
        }
    }
Example #2
0
    TGUI_API Widget::Ptr loadContainer(std::shared_ptr<DataIO::Node> node, Container::Ptr container)
    {
        assert(container != nullptr);
        loadWidget(node, container);

        for (auto& childNode : node->children)
        {
            auto nameSeparator = childNode->name.find('.');
            auto widgetType = childNode->name.substr(0, nameSeparator);
            auto& loadFunction = WidgetLoader::getLoadFunction(toLower(widgetType));
            if (loadFunction)
            {
                std::string className;
                if (nameSeparator != std::string::npos)
                {
                    if ((childNode->name.size() >= nameSeparator + 2) && (childNode->name[nameSeparator+1] == '"') && (childNode->name.back() == '"'))
                        className = Deserializer::deserialize(ObjectConverter::Type::String, childNode->name.substr(nameSeparator + 1)).getString();
                    else
                        className = childNode->name.substr(nameSeparator + 1);
                }

                tgui::Widget::Ptr childWidget = loadFunction(childNode);
                container->add(childWidget, className);
            }
            else
                throw Exception{"No load function exists for widget type '" + widgetType + "'."};
        }

        return container;
    }