Пример #1
0
    TGUI_API std::shared_ptr<DataIO::Node> saveWidget(Widget::Ptr widget)
    {
        std::string widgetName;
        if (widget->getParent())
            widget->getParent()->getWidgetName(widget, widgetName);

        auto node = std::make_shared<DataIO::Node>();
        if (widgetName.empty())
            node->name = widget->getWidgetType();
        else
            node->name = widget->getWidgetType() + "." + widgetName;

        if (!widget->isVisible())
            SET_PROPERTY("Visible", "false");
        if (!widget->isEnabled())
            SET_PROPERTY("Enabled", "false");
        if (widget->getPosition() != sf::Vector2f{})
            SET_PROPERTY("Position", emitLayout(widget->getPositionLayout()));
        if (widget->getSize() != sf::Vector2f{})
            SET_PROPERTY("Size", emitLayout(widget->getSizeLayout()));
        if (widget->getOpacity() != 255)
            SET_PROPERTY("Opacity", tgui::to_string(widget->getOpacity()));

        /// TODO: Font and ToolTip

        if (widget->getRenderer())
        {
            node->children.emplace_back(std::make_shared<DataIO::Node>());
            node->children.back()->name = "Renderer";
            for (auto& pair : widget->getRenderer()->getPropertyValuePairs())
                node->children.back()->propertyValuePairs[pair.first] = std::make_shared<DataIO::ValueNode>(node->children.back().get(), Serializer::serialize(std::move(pair.second)));
        }

        return node;
    }
Пример #2
0
    TGUI_API Widget::Ptr loadWidget(std::shared_ptr<DataIO::Node> node, Widget::Ptr widget)
    {
        assert(widget != nullptr);

        if (node->propertyValuePairs["visible"])
        {
            bool visible = parseBoolean(node->propertyValuePairs["visible"]->value);
            if (visible)
                widget->show();
            else
                widget->hide();
        }
        if (node->propertyValuePairs["enabled"])
        {
            bool enabled = parseBoolean(node->propertyValuePairs["enabled"]->value);
            if (enabled)
                widget->enable();
            else
                widget->disable();
        }
        if (node->propertyValuePairs["position"])
            widget->setPosition(parseLayout(node->propertyValuePairs["position"]->value));
        if (node->propertyValuePairs["size"])
            widget->setSize(parseLayout(node->propertyValuePairs["size"]->value));
        if (node->propertyValuePairs["opacity"])
            widget->setOpacity(tgui::stof(node->propertyValuePairs["opacity"]->value));

        /// TODO: Font and ToolTip (and Theme?)

        for (auto& childNode : node->children)
        {
            if (toLower(childNode->name) == "renderer")
            {
                for (auto& pair : childNode->propertyValuePairs)
                    widget->getRenderer()->setProperty(pair.first, pair.second->value);
            }
        }
        REMOVE_CHILD("renderer");

        return widget;
    }