EWOL: Add Widget in XML access

Objectifs:

  • Create a C++ widget
  • use it in a XML

Declare object in XML

Object can be declared in some XML, (like gui decription), then we need to declare the Object in the system recognition.

Declare Object

In your application "void onCreate(ewol::Context& _context) override" add the function:

YourWidgetClass::createManagerWidget(_context.getWidgetManager());

The simple question is: I does not define this function, where it is done ?

The createManagerWidget is instancuate when you use the macro:

DECLARE_WIDGET_FACTORY(YourWidgetClass, "YourWidgetClass");

it create 2 function: "create(...)" and "createManagerWidget()"

Declare on XML and configuration

in the xml instance simply request it like:

<YourWidgetClass name="jkjkj">
...
</YourWidgetClass>

The xml attribute are automaticaly parsed to configure properties of you object (this is the reason of naming it).

Special case SubParsing XML element

If you want to parse sub-node of the xml just override the function member:

bool loadXML(const exml::Element& _node) override;

Many example are availlable in container widget.

Simple example:

if (_node.exist() == false) {
return false;
}
// parse generic properties:
// parse all the elements:
for (const auto it : _node.nodes) {
exml::Element pNode = it.toElement();
if (pNode.exist() == false) {
// trash here all that is not element
continue;
}
// Get the sub-node name:
std::string widgetName = pNode.getValue();
if (getWidgetManager().exist(widgetName) == false) {
APPL_ERROR("[" << getId() << "] (l "<<pNode->getPos()<<") Unknown basic node='" << widgetName << "' not in : [" << getWidgetManager().list() << "]" );
continue;
}
...
}
return true;