2016-09-16 22:35:06 +02:00
|
|
|
EWOL: Add Widget in XML access {#ewol_tutorial_add_widget_custum_in_xml}
|
|
|
|
==============================
|
2014-03-04 21:18:41 +01:00
|
|
|
|
2016-09-16 22:35:06 +02:00
|
|
|
@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}
|
|
|
|
=====================
|
2014-03-04 21:18:41 +01:00
|
|
|
|
|
|
|
Object can be declared in some XML, (like gui decription), then we need to declare the Object in the system recognition.
|
|
|
|
|
2016-09-16 22:35:06 +02:00
|
|
|
Declare Object
|
|
|
|
--------------
|
2014-03-04 21:18:41 +01:00
|
|
|
|
2016-03-24 21:54:13 +01:00
|
|
|
In your application "void onCreate(ewol::Context& _context) override" add the function:
|
|
|
|
|
2016-09-16 22:35:06 +02:00
|
|
|
```{.cpp}
|
2016-03-24 21:54:13 +01:00
|
|
|
YourWidgetClass::createManagerWidget(_context.getWidgetManager());
|
2016-09-16 22:35:06 +02:00
|
|
|
```
|
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:
|
|
|
|
|
2016-09-16 22:35:06 +02:00
|
|
|
```{.cpp}
|
2016-03-24 21:54:13 +01:00
|
|
|
DECLARE_WIDGET_FACTORY(YourWidgetClass, "YourWidgetClass");
|
2016-09-16 22:35:06 +02:00
|
|
|
```
|
2016-03-24 21:54:13 +01:00
|
|
|
|
|
|
|
it create 2 function: "create(...)" and "createManagerWidget()"
|
2014-03-04 21:18:41 +01:00
|
|
|
|
2016-09-16 22:35:06 +02:00
|
|
|
Declare on XML and configuration {#ewol_tutorial_add_widget_custum_in_xml_dec2}
|
|
|
|
================================
|
2014-03-04 21:18:41 +01:00
|
|
|
|
2016-03-24 21:54:13 +01:00
|
|
|
in the xml instance simply request it like:
|
|
|
|
|
2016-09-16 22:35:06 +02:00
|
|
|
```{.xml}
|
2016-03-24 21:54:13 +01:00
|
|
|
<YourWidgetClass name="jkjkj">
|
|
|
|
...
|
|
|
|
</YourWidgetClass>
|
2016-09-16 22:35:06 +02:00
|
|
|
```
|
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).
|
|
|
|
|
2016-09-16 22:35:06 +02:00
|
|
|
Special case SubParsing XML element {#ewol_tutorial_add_widget_custum_in_xml_parse}
|
|
|
|
===================================
|
2014-03-04 21:18:41 +01:00
|
|
|
|
2016-03-24 21:54:13 +01:00
|
|
|
If you want to parse sub-node of the xml just override the function member:
|
|
|
|
|
2016-09-16 22:35:06 +02:00
|
|
|
```{.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:
|
|
|
|
|
2016-09-16 22:35:06 +02:00
|
|
|
```{.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:
|
2016-09-16 22:35:06 +02:00
|
|
|
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-09-16 22:35:06 +02:00
|
|
|
```
|
2016-03-24 21:54:13 +01:00
|
|
|
|
2014-03-04 21:18:41 +01:00
|
|
|
|
|
|
|
|