MCPcopy Create free account
hub / github.com/LibreSprite/LibreSprite / convertXmlElementToWidget

Method convertXmlElementToWidget

src/app/widget_loader.cpp:114–514  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

112}
113
114Widget* WidgetLoader::convertXmlElementToWidget(const tinyxml2::XMLElement* elem, Widget* root, Widget* parent, Widget* widget)
115{
116 const std::string elem_name = elem->Value();
117
118 // TODO error handling: add a message if the widget is bad specified
119
120 // Try to use one of the creators.
121 TypeCreatorsMap::iterator it = m_typeCreators.find(elem_name);
122
123 if (it != m_typeCreators.end()) {
124 if (!widget)
125 widget = it->second->createWidgetFromXml(elem);
126 }
127 else if (elem_name == "panel") {
128 if (!widget)
129 widget = new Panel();
130 }
131 else if (elem_name == "box") {
132 bool horizontal = bool_attr_is_true(elem, "horizontal");
133 bool vertical = bool_attr_is_true(elem, "vertical");
134 int align = (horizontal ? HORIZONTAL: vertical ? VERTICAL: 0);
135
136 if (!widget)
137 widget = new Box(align);
138 else
139 widget->setAlign(widget->align() | align);
140 }
141 else if (elem_name == "vbox") {
142 if (!widget)
143 widget = new VBox();
144 }
145 else if (elem_name == "hbox") {
146 if (!widget)
147 widget = new HBox();
148 }
149 else if (elem_name == "boxfiller") {
150 if (!widget)
151 widget = new BoxFiller();
152 }
153 else if (elem_name == "button") {
154 const char* icon_name = elem->Attribute("icon");
155
156 if (!widget) {
157 if (icon_name) {
158 SkinPartPtr part = SkinTheme::instance()->getPartById(icon_name);
159 if (!part)
160 throw base::Exception("<button> element found with invalid 'icon' attribute '%s'",
161 icon_name);
162
163 widget = new IconButton(part->bitmap(0));
164 }
165 else {
166 widget = new Button("");
167 }
168 }
169
170 bool left = bool_attr_is_true(elem, "left");
171 bool right = bool_attr_is_true(elem, "right");

Callers

nothing calls this directly

Calls 15

bool_attr_is_trueFunction · 0.85
instanceFunction · 0.85
ExceptionClass · 0.85
base_strdupFunction · 0.85
base_freeFunction · 0.85
setup_bevelsFunction · 0.85
guiscaleFunction · 0.85
int_attrFunction · 0.85
getPartByIdMethod · 0.80
setSuffixMethod · 0.80
setUrlMethod · 0.80

Tested by

no test coverage detected