[DEV] add menu loading with xml data

This commit is contained in:
Edouard DUPIN 2017-02-07 21:28:54 +01:00
parent 3acf0bd148
commit 1a930f5886
4 changed files with 49 additions and 3 deletions

View File

@ -27,6 +27,7 @@
#include <ewol/widget/Composer.hpp>
#include <ewol/widget/Select.hpp>
#include <ewol/widget/Spin.hpp>
#include <ewol/widget/Menu.hpp>
#include <vector>
ewol::widget::Manager::Manager() :
@ -44,6 +45,7 @@ ewol::widget::Manager::Manager() :
ewol::widget::Image::createManagerWidget(*this);
ewol::widget::Gird::createManagerWidget(*this);
ewol::widget::Entry::createManagerWidget(*this);
ewol::widget::Menu::createManagerWidget(*this);
ewol::widget::CheckBox::createManagerWidget(*this);
ewol::widget::Scroll::createManagerWidget(*this);
ewol::widget::ContextMenu::createManagerWidget(*this);

View File

@ -246,4 +246,47 @@ void ewol::widget::Menu::onButtonPressed(ewol::widget::ButtonWeak _button) {
}
}
bool ewol::widget::Menu::loadXML(const exml::Element& _node) {
if (_node.exist() == false) {
return false;
}
// parse generic properties:
ewol::Widget::loadXML(_node);
// parse all the elements :
for (const auto nodeIt : _node.nodes) {
const exml::Element pNode = nodeIt.toElement();
if (pNode.exist() == false) {
// trash here all that is not element
continue;
}
std::string widgetName = pNode.getValue();
EWOL_INFO("Get node : " << pNode);
if (widgetName == "elem") {
// <elem title="_T{Title of the button}" image="DATA:List.svg" event="menu:exit">
int32_t idMenu = addTitle(pNode.attributes["title"], pNode.attributes["image"], pNode.attributes["event"]);
for (const auto nodeIt2 : pNode.nodes) {
const exml::Element pNode2 = nodeIt2.toElement();
if (pNode2.exist() == false) {
// trash here all that is not element
continue;
}
std::string widgetName2 = pNode2.getValue();
EWOL_INFO("Get node : " << pNode2);
if (widgetName2 == "elem") {
// <elem title="_T{Title of the button}" image="DATA:List.svg" event="menu:exit">
add(idMenu, pNode2.attributes["title"], pNode2.attributes["image"], pNode2.attributes["event"]);
} else if (widgetName2 == "separator") {
addSpacer();
} else {
EWOL_ERROR("[" << getId() << "] {" << getObjectType() << "} (l " << pNode2.getPos() << ") Unknown basic node='" << widgetName2 << "' not in : [elem,separator]" );
}
}
} else if (widgetName == "separator") {
addSpacer();
} else {
EWOL_ERROR("[" << getId() << "] {" << getObjectType() << "} (l " << pNode.getPos() << ") Unknown basic node='" << widgetName << "' not in : [elem,separator]" );
}
}
return true;
}

View File

@ -43,6 +43,7 @@ namespace ewol {
int32_t subWidgetAdd(ewol::WidgetShared _newWidget) override;
void subWidgetRemove(ewol::WidgetShared _newWidget) override;
void subWidgetUnLink(ewol::WidgetShared _newWidget) override;
bool loadXML(const exml::Element& _node) override;
private:
std::vector<ewol::widget::MenuElement> m_listElement;
int32_t m_staticId; // unique ID for every element of the menu ...

View File

@ -22,12 +22,12 @@ namespace ewol {
*
* Fist global static declaration and inclusion:
* [code style=c++]
* #include <ewol/widget/meta/FileChooser.h>
* #include <ewol/widget/meta/FileChooser.hpp>
* [/code]
*
* The first step is to create the file chooser pop-up : (never in the constructor!!!)
* [code style=c++]
* ewol::widget::FileChooserShared tmpWidget = ewol::Widget::FileChooser::create();
* ewol::widget::FileChooserShared tmpWidget = ewol::widget::FileChooser::create();
* if (tmpWidget == nullptr) {
* APPL_ERROR("Can not open File chooser !!! ");
* return -1;