ewol/doc/tutorial/051_AddWidgetCustumInXML.md

89 lines
2.4 KiB
Markdown
Raw Normal View History

EWOL: Add Widget in XML access {#ewol_tutorial_add_widget_custum_in_xml}
==============================
@tableofcontents
Objectifs: {#ewol_tutorial_add_widget_custum_in_xml_objectif}
==========
- Create a C++ widget
- use it in a XML
Declare object in XML {#ewol_tutorial_add_widget_custum_in_xml_declare}
=====================
Object can be declared in some XML, (like gui decription), then we need to declare the Object in the system recognition.
Declare Object
--------------
2016-03-24 21:54:13 +01:00
In your application "void onCreate(ewol::Context& _context) override" add the function:
```{.cpp}
2016-03-24 21:54:13 +01:00
YourWidgetClass::createManagerWidget(_context.getWidgetManager());
```
2016-03-24 21:54:13 +01:00
The simple question is: I does not define this function, where it is done ?
The createManagerWidget is instancuate when you use the macro:
```{.cpp}
2016-03-24 21:54:13 +01:00
DECLARE_WIDGET_FACTORY(YourWidgetClass, "YourWidgetClass");
```
2016-03-24 21:54:13 +01:00
it create 2 function: "create(...)" and "createManagerWidget()"
Declare on XML and configuration {#ewol_tutorial_add_widget_custum_in_xml_dec2}
================================
2016-03-24 21:54:13 +01:00
in the xml instance simply request it like:
```{.xml}
2016-03-24 21:54:13 +01:00
<YourWidgetClass name="jkjkj">
...
</YourWidgetClass>
```
2016-03-24 21:54:13 +01:00
The xml attribute are automaticaly parsed to configure properties of you object (this is the reason of naming it).
Special case SubParsing XML element {#ewol_tutorial_add_widget_custum_in_xml_parse}
===================================
2016-03-24 21:54:13 +01:00
If you want to parse sub-node of the xml just override the function member:
```{.cpp}
bool loadXML(const exml::Element& _node) override;
```
2016-03-24 21:54:13 +01:00
Many example are availlable in container widget.
Simple example:
```{.cpp}
if (_node.exist() == false) {
2016-03-24 21:54:13 +01:00
return false;
}
// parse generic properties:
ewol::Widget::loadXML(_node);
// parse all the elements:
for (const auto it : _node.nodes) {
exml::Element pNode = it.toElement();
if (pNode.exist() == false) {
2016-03-24 21:54:13 +01:00
// trash here all that is not element
continue;
}
// Get the sub-node name:
2017-09-14 00:59:21 +02:00
etk::String widgetName = pNode.getValue();
2016-03-24 21:54:13 +01:00
if (getWidgetManager().exist(widgetName) == false) {
APPL_ERROR("[" << getId() << "] (l "<<pNode->getPos()<<") Unknown basic node='" << widgetName << "' not in : [" << getWidgetManager().list() << "]" );
continue;
}
...
}
return true;
```
2016-03-24 21:54:13 +01:00