21 ResourceLayout::ResourceLayout(xml::ElementPtr _node, std::string_view _fileName)
24 deserialization(_node, Version(1, 0, 0));
25 mResourceName = _fileName;
28 void ResourceLayout::deserialization(xml::ElementPtr _node, Version _version)
30 Base::deserialization(_node, _version);
34 for (
auto widget : _node.node().children(
"Widget"))
35 mLayoutData.push_back(parseWidget(widget));
38 WidgetInfo ResourceLayout::parseWidget(xml::ElementPtr _widget)
40 WidgetInfo widgetInfo;
42 widgetInfo.type = _widget.node().attribute(
"type").value();
43 widgetInfo.skin = _widget.node().attribute(
"skin").value();
44 widgetInfo.layer = _widget.node().attribute(
"layer").value();
46 std::string_view tmp{_widget.node().attribute(
"align").value()};
48 widgetInfo.align = Align::parse(tmp);
50 widgetInfo.name = _widget.node().attribute(
"name").value();
52 tmp = _widget.node().attribute(
"style").value();
54 widgetInfo.style = WidgetStyle::parse(tmp);
56 tmp = _widget.node().attribute(
"position").value();
60 widgetInfo.positionType = WidgetInfo::Pixels;
64 tmp = _widget.node().attribute(
"position_real").value();
68 widgetInfo.positionType = WidgetInfo::Relative;
72 for (
auto node : _widget.node())
74 if (node.name() == std::string_view(
"Widget"))
76 widgetInfo.childWidgetsInfo.push_back(parseWidget(node));
78 else if (node.name() == std::string_view(
"Property"))
80 widgetInfo.properties.emplace_back(node.attribute(
"key").value(), node.attribute(
"value").value());
82 else if (node.name() == std::string_view(
"UserString"))
84 std::string_view key = node.attribute(
"key").value();
85 std::string_view value = node.attribute(
"value").value();
86 mapSet(widgetInfo.userStrings, key, value);
88 else if (node.name() == std::string_view(
"Controller"))
90 ControllerInfo controllerInfo;
91 controllerInfo.type = node.attribute(
"type").value();
93 for (
auto prop : node.children(
"Property"))
95 std::string_view key = prop.attribute(
"key").value();
96 std::string_view value = prop.attribute(
"value").value();
97 mapSet(controllerInfo.properties, key, value);
100 widgetInfo.controllers.push_back(controllerInfo);
107 VectorWidgetPtr ResourceLayout::createLayout(std::string_view _prefix, Widget* _parent)
111 for (
auto& iter : mLayoutData)
113 Widget* widget = createWidget(iter, _prefix, _parent);
114 widgets.push_back(widget);
120 Widget* ResourceLayout::createWidget(
121 const WidgetInfo& _widgetInfo,
122 std::string_view _prefix,
126 std::string widgetName;
127 WidgetStyle style = _widgetInfo.style;
128 std::string_view widgetLayer = _widgetInfo.layer;
130 if (!_widgetInfo.name.empty())
132 widgetName = _prefix;
133 widgetName += _widgetInfo.name;
136 if (_parent !=
nullptr && style != WidgetStyle::Popup)
138 if (_parent ==
nullptr && widgetLayer.empty())
142 "Root widget's layer is not specified, widget won't be visible. Specify layer or parent or attach it "
143 "to another widget after load."
144 <<
" [" << LayoutManager::getInstance().getCurrentLayout() <<
"]");
148 if (_widgetInfo.positionType == WidgetInfo::Pixels)
149 coord = _widgetInfo.intCoord;
150 else if (_widgetInfo.positionType == WidgetInfo::Relative)
152 if (_parent ==
nullptr || style == WidgetStyle::Popup)
153 coord = CoordConverter::convertFromRelative(
154 _widgetInfo.floatCoord,
155 RenderManager::getInstance().getViewSize());
157 coord = CoordConverter::convertFromRelative(_widgetInfo.floatCoord, _parent->getClientCoord().size());
161 if (
nullptr == _parent)
162 wid = Gui::getInstance().createWidgetT(
170 wid = _parent->_createSkinWidget(
179 wid = _parent->createWidgetT(
188 for (
const auto& property : _widgetInfo.properties)
190 wid->setProperty(property.first, property.second);
193 for (
const auto& userString : _widgetInfo.userStrings)
195 wid->setUserString(userString.first, userString.second);
197 LayoutManager::getInstance().eventAddUserString(wid, userString.first, userString.second);
200 for (
const auto& iter : _widgetInfo.childWidgetsInfo)
202 createWidget(iter, _prefix, wid);
205 for (
const auto& iter : _widgetInfo.controllers)
207 MyGUI::ControllerItem* item = MyGUI::ControllerManager::getInstance().createItem(iter.type);
210 for (
const auto& property : iter.properties)
212 item->setProperty(property.first, property.second);
214 MyGUI::ControllerManager::getInstance().addItem(wid, item);
218 MYGUI_LOG(Warning,
"Controller '" << iter.type <<
"' not found");
222 LayoutManager::getInstance().eventCreateWidget(wid, _widgetInfo);
#define MYGUI_LOG(level, text)
void mapSet(Map &map, std::string_view key, const Value &value)
std::vector< WidgetInfo > VectorWidgetInfo
types::TCoord< int > IntCoord
std::vector< Widget * > VectorWidgetPtr
static TCoord< int > parse(std::string_view _value)