[DEV] add an API to create widget with XML
This commit is contained in:
parent
632fafaa3d
commit
7273b617ff
@ -11,6 +11,7 @@
|
||||
#include <ewol/widget/Composer.h>
|
||||
#include <etk/os/FSNode.h>
|
||||
#include <ewol/widget/Manager.h>
|
||||
#include <ewol/context/Context.h>
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "ewol::widget::Composer"
|
||||
@ -20,6 +21,60 @@ ewol::widget::Composer::Composer() {
|
||||
// nothing to do ...
|
||||
}
|
||||
|
||||
std::shared_ptr<ewol::Widget> ewol::widget::composerGenerate(enum ewol::widget::Composer::composerMode _mode, const std::string& _data) {
|
||||
ewol::widget::Manager& widgetManager = ewol::getContext().getWidgetManager();
|
||||
if (_data == "") {
|
||||
return nullptr;
|
||||
}
|
||||
std::shared_ptr<exml::Document> doc = exml::Document::create();
|
||||
switch(_mode) {
|
||||
case ewol::widget::Composer::None:
|
||||
EWOL_ERROR("Not specify the type for compositing dynamic creation");
|
||||
return nullptr;
|
||||
case ewol::widget::Composer::String:
|
||||
if (doc->parse(_data) == false) {
|
||||
EWOL_ERROR(" can not load file XML string...");
|
||||
return nullptr;
|
||||
}
|
||||
break;
|
||||
case ewol::widget::Composer::file:
|
||||
if (doc->load(_data) == false) {
|
||||
EWOL_ERROR(" can not load file XML : " << _data);
|
||||
return nullptr;
|
||||
}
|
||||
break;
|
||||
}
|
||||
std::shared_ptr<const exml::Element> root = doc->toElement();
|
||||
if (root->size() == 0) {
|
||||
EWOL_ERROR(" (l ?) No node in the XML file/string.");
|
||||
return nullptr;
|
||||
}
|
||||
if (root->size() > 1) {
|
||||
EWOL_WARNING(" (l ?) More than 1 node in the XML file/string. (JUST parse the first)");
|
||||
}
|
||||
std::shared_ptr<const exml::Element> pNode = root->getElement(0);
|
||||
if (pNode == nullptr) {
|
||||
EWOL_ERROR(" (l ?) No node in the XML file/string. {2}");
|
||||
return nullptr;
|
||||
}
|
||||
std::string widgetName = pNode->getValue();
|
||||
if (widgetManager.exist(widgetName) == false) {
|
||||
EWOL_ERROR("(l "<<pNode->getPos()<<") Unknown basic node=\"" << widgetName << "\" not in : [" << widgetManager.list() << "]" );
|
||||
return nullptr;
|
||||
}
|
||||
EWOL_DEBUG("try to create subwidget : '" << widgetName << "'");
|
||||
std::shared_ptr<ewol::Widget> tmpWidget = widgetManager.create(widgetName);
|
||||
if (tmpWidget == nullptr) {
|
||||
EWOL_ERROR ("(l "<<pNode->getPos()<<") Can not create the widget : \"" << widgetName << "\"");
|
||||
return nullptr;
|
||||
}
|
||||
if (tmpWidget->loadXML(pNode) == false) {
|
||||
EWOL_ERROR ("(l "<<pNode->getPos()<<") can not load widget properties : \"" << widgetName << "\"");
|
||||
}
|
||||
return tmpWidget;
|
||||
}
|
||||
|
||||
|
||||
void ewol::widget::Composer::init(enum composerMode _mode, const std::string& _fileName) {
|
||||
ewol::widget::Container::init();
|
||||
switch(_mode) {
|
||||
|
@ -36,7 +36,7 @@ namespace ewol {
|
||||
* @param[in] _mode mode of parsing the string
|
||||
* @param[in] _data file/directString data to generate compositing of the widget..
|
||||
*/
|
||||
void init(enum composerMode _mode = ewol::widget::Composer::None, const std::string& _data = "");
|
||||
void init(enum ewol::widget::Composer::composerMode _mode = ewol::widget::Composer::None, const std::string& _data = "");
|
||||
public:
|
||||
DECLARE_WIDGET_FACTORY(Composer, "Composer");
|
||||
/**
|
||||
@ -58,6 +58,7 @@ namespace ewol {
|
||||
*/
|
||||
bool loadFromString(const std::string& _composerXmlString);
|
||||
};
|
||||
std::shared_ptr<ewol::Widget> composerGenerate(enum ewol::widget::Composer::composerMode _mode = ewol::widget::Composer::None, const std::string& _data = "");
|
||||
};
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user