[DEBUG/DEV] correct the loading of the composer and add the spacer in menu
This commit is contained in:
parent
1a930f5886
commit
e61234d586
@ -111,7 +111,7 @@ bool ewol::Object::isTypeCompatible(const std::string& _type) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ewol::Object::loadXML(const exml::Element& _node) {
|
||||
bool ewol::Object::loadXMLAttributes(const exml::Element& _node) {
|
||||
if (_node.exist() == false) {
|
||||
return false;
|
||||
}
|
||||
@ -129,6 +129,10 @@ bool ewol::Object::loadXML(const exml::Element& _node) {
|
||||
return errorOccured;
|
||||
}
|
||||
|
||||
bool ewol::Object::loadXML(const exml::Element& _node) {
|
||||
return true; //loadXMLAttributes(_node);
|
||||
}
|
||||
|
||||
bool ewol::Object::storeXML(exml::Element& _node) const {
|
||||
if (_node.exist() == false) {
|
||||
return false;
|
||||
|
@ -74,6 +74,19 @@ exit_on_error:
|
||||
EWOL_CRITICAL("Object Is not correctly init : " << #className ); \
|
||||
} \
|
||||
return object; \
|
||||
} \
|
||||
static ememory::SharedPtr<className> createXml(const exml::Element& _node) { \
|
||||
ememory::SharedPtr<className> object(new className()); \
|
||||
if (object == nullptr) { \
|
||||
EWOL_ERROR("Factory error"); \
|
||||
return nullptr; \
|
||||
} \
|
||||
object->loadXMLAttributes(_node); \
|
||||
object->init(); \
|
||||
if (object->objectHasBeenCorectlyInit() == false) { \
|
||||
EWOL_CRITICAL("Object Is not correctly init : " << #className ); \
|
||||
} \
|
||||
return object; \
|
||||
}
|
||||
|
||||
#define DECLARE_SINGLE_FACTORY(className, uniqueName) \
|
||||
@ -222,16 +235,23 @@ namespace ewol {
|
||||
// TODO : Rework the position on this function ... This is a convignent function ...
|
||||
bool propertySetOnWidgetNamed(const std::string& _objectName, const std::string& _config, const std::string& _value);
|
||||
public:
|
||||
/**
|
||||
* @brief load attribute properties with an XML node.
|
||||
* @param[in] _node Reference on the XML node.
|
||||
* @return true : All has been done corectly.
|
||||
* @return false : An error occured.
|
||||
*/
|
||||
bool loadXMLAttributes(const exml::Element& _node);
|
||||
/**
|
||||
* @brief load properties with an XML node.
|
||||
* @param[in] _node Pointer on the tinyXML node.
|
||||
* @param[in] _node Reference on the XML node.
|
||||
* @return true : All has been done corectly.
|
||||
* @return false : An error occured.
|
||||
*/
|
||||
virtual bool loadXML(const exml::Element& _node);
|
||||
/**
|
||||
* @brief store properties in this XML node.
|
||||
* @param[in,out] _node Pointer on the tinyXML node.
|
||||
* @param[in,out] _node Reference on the XML node.
|
||||
* @return true : All has been done corectly.
|
||||
* @return false : An error occured.
|
||||
*/
|
||||
|
@ -12,37 +12,31 @@
|
||||
#include <ewol/context/Context.hpp>
|
||||
|
||||
ewol::widget::Composer::Composer() :
|
||||
propertyRemoveIfUnderRemove(this, "remove-if-under-remove", true, "Demand the remove iof the widget if the subObject demand a remove") {
|
||||
propertyRemoveIfUnderRemove(this, "remove-if-under-remove", true, "Demand the remove iof the widget if the subObject demand a remove"),
|
||||
propertySubFile(this, "sub-file", "", "compose with a subXML file", &ewol::widget::Composer::onChangePropertySubFile) {
|
||||
addObjectType("ewol::widget::Composer");
|
||||
// nothing to do ...
|
||||
}
|
||||
|
||||
static ewol::WidgetShared composerGenerate(bool _modeFile, const std::string& _data, uint64_t _id) {
|
||||
ewol::WidgetShared ewol::widget::composerGenerateFile(const std::string& _fileName, uint64_t _id) {
|
||||
std::string tmpData = etk::FSNodeReadAllData(_fileName);
|
||||
return ewol::widget::composerGenerateString(tmpData, _id);
|
||||
}
|
||||
|
||||
ewol::WidgetShared ewol::widget::composerGenerateString(const std::string& _data, uint64_t _id) {
|
||||
ewol::widget::Manager& widgetManager = ewol::getContext().getWidgetManager();
|
||||
if (_data == "") {
|
||||
return nullptr;
|
||||
}
|
||||
exml::Document doc;
|
||||
if (_modeFile == true) {
|
||||
std::string tmpData = etk::FSNodeReadAllData(_data);
|
||||
// replace all elements:
|
||||
if (_id != 0) {
|
||||
tmpData = etk::replace(tmpData, "{ID}", etk::to_string(_id));
|
||||
}
|
||||
if (doc.parse(tmpData) == false) {
|
||||
EWOL_ERROR(" can not load file XML : " << _data);
|
||||
return nullptr;
|
||||
}
|
||||
} else {
|
||||
std::string tmpData = _data;
|
||||
// replace all elements:
|
||||
if (_id != 0) {
|
||||
tmpData = etk::replace(tmpData, "{ID}", etk::to_string(_id));
|
||||
}
|
||||
if (doc.parse(tmpData) == false) {
|
||||
EWOL_ERROR(" can not load file XML string...");
|
||||
return nullptr;
|
||||
}
|
||||
std::string tmpData = _data;
|
||||
// replace all elements:
|
||||
if (_id != 0) {
|
||||
tmpData = etk::replace(tmpData, "{ID}", etk::to_string(_id));
|
||||
}
|
||||
if (doc.parse(tmpData) == false) {
|
||||
EWOL_ERROR(" can not load file XML string...");
|
||||
return nullptr;
|
||||
}
|
||||
exml::Element root = doc.toElement();
|
||||
if (root.nodes.size() == 0) {
|
||||
@ -74,46 +68,13 @@ static ewol::WidgetShared composerGenerate(bool _modeFile, const std::string& _d
|
||||
return tmpWidget;
|
||||
}
|
||||
|
||||
ewol::WidgetShared ewol::widget::composerGenerateFile(const std::string& _data, uint64_t _id) {
|
||||
return composerGenerate(true, _data, _id);
|
||||
}
|
||||
|
||||
ewol::WidgetShared ewol::widget::composerGenerateString(const std::string& _data, uint64_t _id) {
|
||||
return composerGenerate(false, _data, _id);
|
||||
}
|
||||
|
||||
ewol::widget::Composer::~Composer() {
|
||||
|
||||
}
|
||||
|
||||
bool ewol::widget::Composer::loadFromFile(const std::string& _fileName, uint64_t _id) {
|
||||
exml::Document doc;
|
||||
std::string tmpData = etk::FSNodeReadAllData(_fileName);
|
||||
// replace all elements:
|
||||
if (_id != 0) {
|
||||
tmpData = etk::replace(tmpData, "{ID}", etk::to_string(_id));
|
||||
}
|
||||
if (doc.parse(tmpData) == false) {
|
||||
EWOL_ERROR(" can not load file XML : " << _fileName);
|
||||
return false;
|
||||
}
|
||||
exml::Element root = doc.nodes["composer"];
|
||||
if (root.exist() == false) {
|
||||
// Maybe a multiple node XML for internal config:
|
||||
root = doc.toElement();
|
||||
if (root.exist() == false) {
|
||||
EWOL_ERROR("[" << getId() << "] {" << getObjectType() << "} (l ?) main node not find: 'composer' ...");
|
||||
return false;
|
||||
}
|
||||
if (root.nodes.size() == 0) {
|
||||
EWOL_ERROR("[" << getId() << "] {" << getObjectType() << "} (l ?) no node in the Container XML element.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// call upper class to parse his elements ...
|
||||
ewol::widget::Container::loadXML(root);
|
||||
|
||||
return true;
|
||||
return loadFromString(tmpData, _id);
|
||||
}
|
||||
|
||||
bool ewol::widget::Composer::loadFromString(const std::string& _composerXmlString, uint64_t _id) {
|
||||
@ -142,6 +103,13 @@ bool ewol::widget::Composer::loadFromString(const std::string& _composerXmlStrin
|
||||
}
|
||||
// call upper class to parse his elements ...
|
||||
ewol::widget::Container::loadXML(root);
|
||||
if (m_subWidget == nullptr) {
|
||||
EWOL_WARNING("Load data from composer and have no under Widget after loading");
|
||||
if (_composerXmlString.size() != 0) {
|
||||
EWOL_ERROR("Error Loading XML data : " << _composerXmlString);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
requestUpdateSize();
|
||||
return true;
|
||||
}
|
||||
@ -153,3 +121,32 @@ void ewol::widget::Composer::requestDestroyFromChild(const ewol::ObjectShared& _
|
||||
autoDestroy();
|
||||
}
|
||||
}
|
||||
|
||||
void ewol::widget::Composer::onChangePropertySubFile() {
|
||||
EWOL_INFO("Load compositing form external file : " << propertySubFile);
|
||||
if (*propertySubFile == "") {
|
||||
// remove all elements:
|
||||
subWidgetRemove();
|
||||
return;
|
||||
}
|
||||
if (loadFromFile(*propertySubFile, getId()) == false) {
|
||||
EWOL_ERROR("Can not load Player GUI from file ... " << propertySubFile);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
bool ewol::widget::Composer::loadXML(const exml::Element& _node) {
|
||||
//EWOL_VERBOSE("[" << getId() << "] t=" << getObjectType() << " Load XML (start)");
|
||||
if (_node.exist() == false) {
|
||||
return false;
|
||||
}
|
||||
// parse generic properties:
|
||||
ewol::Widget::loadXML(_node);
|
||||
// parse all the elements:
|
||||
if (_node.nodes.size() != 0) {
|
||||
EWOL_ERROR("a composer Node Can not have Sub-element in XML ==> must be done in an external file and load it with attribute: 'sub-file'");
|
||||
}
|
||||
//drawWidgetTree();
|
||||
//EWOL_VERBOSE("[" << getId() << "] t=" << getObjectType() << " Load XML (stop)");
|
||||
return true;
|
||||
}
|
@ -21,6 +21,7 @@ namespace ewol {
|
||||
class Composer : public ewol::widget::Container {
|
||||
public:
|
||||
eproperty::Value<bool> propertyRemoveIfUnderRemove; //!< Remove the composer if sub element request a remove
|
||||
eproperty::Value<std::string> propertySubFile; //!< If loading a sub-file, we must do it here ==> permit to con,figure it in the xml and not have wrong display
|
||||
protected:
|
||||
/**
|
||||
* @brief Constructor
|
||||
@ -50,6 +51,10 @@ namespace ewol {
|
||||
bool loadFromString(const std::string& _composerXmlString, uint64_t _id=0);
|
||||
private:
|
||||
void requestDestroyFromChild(const ewol::ObjectShared& _child) override;
|
||||
public:
|
||||
bool loadXML(const exml::Element& _node) override;
|
||||
protected:
|
||||
virtual void onChangePropertySubFile();
|
||||
};
|
||||
ewol::WidgetShared composerGenerateString(const std::string& _data = "", uint64_t _id=0);
|
||||
ewol::WidgetShared composerGenerateFile(const std::string& _data = "", uint64_t _id=0);
|
||||
|
@ -87,7 +87,10 @@ void ewol::widget::Container::systemDraw(const ewol::DrawProperty& _displayProp)
|
||||
if (m_subWidget != nullptr) {
|
||||
ewol::DrawProperty prop = _displayProp;
|
||||
prop.limit(m_origin, m_size);
|
||||
//EWOL_INFO("Draw : [" << propertyName << "] t=" << getObjectType() << " o=" << m_origin << " s=" << m_size);
|
||||
m_subWidget->systemDraw(prop);
|
||||
} else {
|
||||
EWOL_INFO("[" << getId() << "] ++++++ : [nullptr]");
|
||||
}
|
||||
}
|
||||
|
||||
@ -151,6 +154,7 @@ bool ewol::widget::Container::loadXML(const exml::Element& _node) {
|
||||
continue;
|
||||
}
|
||||
std::string widgetName = pNode.getValue();
|
||||
EWOL_VERBOSE("[" << getId() << "] t=" << getObjectType() << " Load node name : '" << widgetName << "'");
|
||||
if (getWidgetManager().exist(widgetName) == false) {
|
||||
EWOL_ERROR("(l " << pNode.getPos() << ") Unknown basic node='" << widgetName << "' not in : [" << getWidgetManager().list() << "]" );
|
||||
continue;
|
||||
@ -160,7 +164,7 @@ bool ewol::widget::Container::loadXML(const exml::Element& _node) {
|
||||
continue;
|
||||
}
|
||||
EWOL_DEBUG("try to create subwidget : '" << widgetName << "'");
|
||||
ewol::WidgetShared tmpWidget = getWidgetManager().create(widgetName);
|
||||
ewol::WidgetShared tmpWidget = getWidgetManager().create(widgetName, pNode);
|
||||
if (tmpWidget == nullptr) {
|
||||
EWOL_ERROR ("(l " << pNode.getPos() << ") Can not create the widget : '" << widgetName << "'");
|
||||
continue;
|
||||
@ -172,6 +176,10 @@ bool ewol::widget::Container::loadXML(const exml::Element& _node) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ( _node.nodes.size() != 0
|
||||
&& m_subWidget == nullptr) {
|
||||
EWOL_WARNING("Load container with no data inside");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -194,3 +202,11 @@ void ewol::widget::Container::requestDestroyFromChild(const ewol::ObjectShared&
|
||||
m_subWidget.reset();
|
||||
markToRedraw();
|
||||
}
|
||||
|
||||
void ewol::widget::Container::drawWidgetTree(int32_t _level) {
|
||||
ewol::Widget::drawWidgetTree(_level);
|
||||
_level++;
|
||||
if (m_subWidget != nullptr) {
|
||||
m_subWidget->drawWidgetTree(_level);
|
||||
}
|
||||
}
|
||||
|
@ -67,6 +67,7 @@ namespace ewol {
|
||||
bool loadXML(const exml::Element& _node) override;
|
||||
void setOffset(const vec2& _newVal) override;
|
||||
void requestDestroyFromChild(const ewol::ObjectShared& _child) override;
|
||||
void drawWidgetTree(int32_t _level=0) override;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
@ -96,6 +96,7 @@ void ewol::widget::Container2::systemDraw(const ewol::DrawProperty& _displayProp
|
||||
}
|
||||
ewol::Widget::systemDraw(_displayProp);
|
||||
if (m_subWidget[m_idWidgetDisplayed] != nullptr) {
|
||||
//EWOL_INFO("Draw : [" << propertyName << "] t=" << getObjectType() << " o=" << m_origin << " s=" << m_size);
|
||||
m_subWidget[m_idWidgetDisplayed]->systemDraw(_displayProp);
|
||||
}
|
||||
}
|
||||
@ -199,7 +200,7 @@ bool ewol::widget::Container2::loadXML(const exml::Element& _node) {
|
||||
}
|
||||
}
|
||||
EWOL_DEBUG("try to create subwidget : '" << widgetName << "'");
|
||||
ewol::WidgetShared tmpWidget = getWidgetManager().create(widgetName);
|
||||
ewol::WidgetShared tmpWidget = getWidgetManager().create(widgetName, pNode);
|
||||
if (tmpWidget == nullptr) {
|
||||
EWOL_ERROR ("(l " << pNode.getPos() << ") Can not create the widget: '" << widgetName << "'");
|
||||
continue;
|
||||
@ -245,4 +246,13 @@ void ewol::widget::Container2::requestDestroyFromChild(const ewol::ObjectShared&
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ewol::widget::Container2::drawWidgetTree(int32_t _level) {
|
||||
ewol::Widget::drawWidgetTree(_level);
|
||||
_level++;
|
||||
if (m_subWidget[0] != nullptr) {
|
||||
m_subWidget[0]->drawWidgetTree(_level);
|
||||
}
|
||||
if (m_subWidget[1] != nullptr) {
|
||||
m_subWidget[1]->drawWidgetTree(_level);
|
||||
}
|
||||
}
|
||||
|
@ -168,6 +168,7 @@ namespace ewol {
|
||||
bool loadXML(const exml::Element& _node) override;
|
||||
void setOffset(const vec2& _newVal) override;
|
||||
void requestDestroyFromChild(const ewol::ObjectShared& _child) override;
|
||||
void drawWidgetTree(int32_t _level=0) override;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
@ -176,6 +176,7 @@ void ewol::widget::ContainerN::systemDraw(const ewol::DrawProperty& _displayProp
|
||||
prop.limit(m_origin, m_size);
|
||||
for (auto it(m_subWidget.rbegin()); it!=m_subWidget.rend(); ++it) {
|
||||
if (*it != nullptr) {
|
||||
//EWOL_INFO(" ***** : [" << (*it)->propertyName << "] t=" << (*it)->getObjectType() << " o=" << (*it)->m_origin << " s=" << (*it)->m_size);
|
||||
(*it)->systemDraw(prop);
|
||||
}
|
||||
}
|
||||
@ -273,12 +274,13 @@ bool ewol::widget::ContainerN::loadXML(const exml::Element& _node) {
|
||||
continue;
|
||||
}
|
||||
std::string widgetName = pNode.getValue();
|
||||
EWOL_VERBOSE(" t=" << getObjectType() << " Load node name : '" << widgetName << "'");
|
||||
if (getWidgetManager().exist(widgetName) == false) {
|
||||
EWOL_ERROR("[" << getId() << "] {" << getObjectType() << "} (l " << pNode.getPos() << ") Unknown basic node='" << widgetName << "' not in : [" << getWidgetManager().list() << "]" );
|
||||
continue;
|
||||
}
|
||||
EWOL_DEBUG("[" << getId() << "] {" << getObjectType() << "} load new element : '" << widgetName << "'");
|
||||
ewol::WidgetShared subWidget = getWidgetManager().create(widgetName);
|
||||
ewol::WidgetShared subWidget = getWidgetManager().create(widgetName, pNode);
|
||||
if (subWidget == nullptr) {
|
||||
EWOL_ERROR ("[" << getId() << "] {" << getObjectType() << "} (l " << pNode.getPos() << ") Can not create the widget : '" << widgetName << "'");
|
||||
continue;
|
||||
@ -326,3 +328,12 @@ void ewol::widget::ContainerN::requestDestroyFromChild(const ewol::ObjectShared&
|
||||
}
|
||||
}
|
||||
|
||||
void ewol::widget::ContainerN::drawWidgetTree(int32_t _level) {
|
||||
ewol::Widget::drawWidgetTree(_level);
|
||||
_level++;
|
||||
for (auto &it: m_subWidget) {
|
||||
if (it != nullptr) {
|
||||
it->drawWidgetTree(_level);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -98,6 +98,7 @@ namespace ewol {
|
||||
bool loadXML(const exml::Element& _node) override;
|
||||
void setOffset(const vec2& _newVal) override;
|
||||
void requestDestroyFromChild(const ewol::ObjectShared& _child) override;
|
||||
void drawWidgetTree(int32_t _level=0) override;
|
||||
protected:
|
||||
virtual void onChangePropertyLockExpand();
|
||||
};
|
||||
|
@ -165,20 +165,37 @@ bool ewol::widget::Manager::isDrawingNeeded() {
|
||||
|
||||
// element that generate the list of elements
|
||||
void ewol::widget::Manager::addWidgetCreator(const std::string& _name,
|
||||
ewol::widget::Manager::widgetCreatorFunction _pointer) {
|
||||
if (_pointer == nullptr) {
|
||||
ewol::widget::Manager::widgetCreatorFunction _pointer,
|
||||
ewol::widget::Manager::widgetCreatorFunctionXml _pointerXml) {
|
||||
if ( _pointer == nullptr
|
||||
|| _pointerXml == nullptr) {
|
||||
return;
|
||||
}
|
||||
//Keep name in lower case :
|
||||
std::string nameLower = etk::tolower(_name);
|
||||
auto it = m_creatorList.find(nameLower);
|
||||
if (it != m_creatorList.end()) {
|
||||
EWOL_WARNING("Replace Creator of a specify widget : " << nameLower);
|
||||
it->second = _pointer;
|
||||
bool find = false;
|
||||
{
|
||||
auto it = m_creatorList.find(nameLower);
|
||||
if (it != m_creatorList.end()) {
|
||||
EWOL_WARNING("Replace Creator of a specify widget : " << nameLower);
|
||||
it->second = _pointer;
|
||||
find = true;
|
||||
}
|
||||
}
|
||||
{
|
||||
auto it = m_creatorListXml.find(nameLower);
|
||||
if (it != m_creatorListXml.end()) {
|
||||
EWOL_WARNING("Replace CreatorXml of a specify widget : " << nameLower);
|
||||
it->second = _pointerXml;
|
||||
find = true;
|
||||
}
|
||||
}
|
||||
if (find == true) {
|
||||
return;
|
||||
}
|
||||
EWOL_INFO("Add Creator of a specify widget : " << nameLower);
|
||||
m_creatorList.insert(make_pair(nameLower, _pointer));
|
||||
m_creatorListXml.insert(make_pair(nameLower, _pointerXml));
|
||||
}
|
||||
|
||||
ewol::WidgetShared ewol::widget::Manager::create(const std::string& _name) {
|
||||
@ -193,6 +210,18 @@ ewol::WidgetShared ewol::widget::Manager::create(const std::string& _name) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ewol::WidgetShared ewol::widget::Manager::create(const std::string& _name, const exml::Element& _node) {
|
||||
std::string nameLower = etk::tolower(_name);
|
||||
auto it = m_creatorListXml.find(nameLower);
|
||||
if (it != m_creatorListXml.end()) {
|
||||
if (it->second != nullptr) {
|
||||
return it->second(_node);
|
||||
}
|
||||
}
|
||||
EWOL_WARNING("try to create an UnExistant widget : " << nameLower);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool ewol::widget::Manager::exist(const std::string& _name) {
|
||||
std::string nameLower = etk::tolower(_name);
|
||||
auto it = m_creatorList.find(nameLower);
|
||||
|
@ -48,21 +48,31 @@ namespace ewol {
|
||||
// ---------------------------------------------
|
||||
public:
|
||||
using widgetCreatorFunction = std::function<ewol::WidgetShared()>; //!< funtion factory basic definition
|
||||
using widgetCreatorFunctionXml = std::function<ewol::WidgetShared(const exml::Element& _node)>; //!< funtion factory basic definition
|
||||
private:
|
||||
std::unordered_map<std::string, widgetCreatorFunction> m_creatorList; //!< List of factory of a widget
|
||||
std::unordered_map<std::string, widgetCreatorFunctionXml> m_creatorListXml; //!< List of factory of a widget
|
||||
public:
|
||||
/**
|
||||
* @brief add a factory of a specific widget.
|
||||
* @param[in] _name Name of the widget that is associated of the factory.
|
||||
* @param[in] _factory Function pointer to create the widget
|
||||
* @param[in] _factoryXml Function pointer to create the widget with XML node for parsing of XML
|
||||
*/
|
||||
void addWidgetCreator(const std::string& _name, widgetCreatorFunction _factory);
|
||||
void addWidgetCreator(const std::string& _name, widgetCreatorFunction _factory, widgetCreatorFunctionXml _factoryXml);
|
||||
/**
|
||||
* @brief Create a widget with his name.
|
||||
* @param[in] _name Name of the widget to create.
|
||||
* @return The widget created (nullptr if it does not exist).
|
||||
*/
|
||||
ewol::WidgetShared create(const std::string& _name);
|
||||
/**
|
||||
* @brief Create a widget with his name.
|
||||
* @param[in] _name Name of the widget to create.
|
||||
* @param[in] _node Reference on the XML node.
|
||||
* @return The widget created (nullptr if it does not exist).
|
||||
*/
|
||||
ewol::WidgetShared create(const std::string& _name, const exml::Element& _node);
|
||||
/**
|
||||
* @brief Check if an Widget exist
|
||||
* @param[in] _name Name of the widget to check.
|
||||
|
@ -12,11 +12,13 @@
|
||||
#include <ewol/widget/Composer.hpp>
|
||||
#include <ewol/widget/Label.hpp>
|
||||
#include <ewol/widget/Windows.hpp>
|
||||
#include <ewol/widget/Spacer.hpp>
|
||||
|
||||
ewol::widget::Menu::Menu() :
|
||||
signalSelect(this, "select", "") {
|
||||
addObjectType("ewol::widget::Menu");
|
||||
m_staticId = 666;
|
||||
propertyLockExpand.setDirect(bvec2(true,true));
|
||||
}
|
||||
|
||||
ewol::widget::Menu::~Menu() {
|
||||
@ -66,7 +68,7 @@ int32_t ewol::widget::Menu::add(int32_t _parent,
|
||||
const std::string& _label,
|
||||
const std::string& _image,
|
||||
const std::string& _message) {
|
||||
// try to find one already created :
|
||||
// try to find one already created:
|
||||
int32_t previous = get(_label);
|
||||
if (previous != -1) {
|
||||
return previous;
|
||||
@ -77,7 +79,7 @@ int32_t ewol::widget::Menu::add(int32_t _parent,
|
||||
tmpObject.m_label = _label;
|
||||
tmpObject.m_image = _image;
|
||||
tmpObject.m_message = _message;
|
||||
if (-1 == tmpObject.m_parentId) {
|
||||
if (tmpObject.m_parentId == -1) {
|
||||
ewol::widget::ButtonShared myButton = ewol::widget::Button::create();
|
||||
if (myButton == nullptr) {
|
||||
EWOL_ERROR("Allocation button error");
|
||||
@ -113,9 +115,29 @@ void ewol::widget::Menu::remove(int32_t _id) {
|
||||
}
|
||||
|
||||
|
||||
int32_t ewol::widget::Menu::addSpacer() {
|
||||
EWOL_TODO("NOT addSpacer...");
|
||||
return -1;
|
||||
int32_t ewol::widget::Menu::addSpacer(int32_t _parent) {
|
||||
ewol::widget::MenuElement tmpObject;
|
||||
tmpObject.m_localId = m_staticId++;
|
||||
tmpObject.m_parentId = _parent;
|
||||
tmpObject.m_label = "";
|
||||
tmpObject.m_image = "";
|
||||
tmpObject.m_message = "";
|
||||
if (tmpObject.m_parentId == -1) {
|
||||
ewol::widget::SpacerShared mySpacer = ewol::widget::Spacer::create();
|
||||
if (mySpacer == nullptr) {
|
||||
EWOL_ERROR("Allocation spacer error");
|
||||
return tmpObject.m_localId;
|
||||
}
|
||||
mySpacer->propertyExpand.set(bvec2(true,true));
|
||||
mySpacer->propertyFill.set(bvec2(true,true));
|
||||
mySpacer->propertyMinSize.set(gale::Dimension(vec2(2,0), gale::distance::pixel));
|
||||
mySpacer->propertyMaxSize.set(gale::Dimension(vec2(2,10000), gale::distance::pixel));
|
||||
mySpacer->propertyColor.set(etk::Color<>(0,0,0,0xFF));
|
||||
// add it in the widget list
|
||||
ewol::widget::Sizer::subWidgetAdd(mySpacer);
|
||||
}
|
||||
m_listElement.push_back(tmpObject);
|
||||
return tmpObject.m_localId;
|
||||
}
|
||||
|
||||
void ewol::widget::Menu::onButtonPressed(ewol::widget::ButtonWeak _button) {
|
||||
@ -192,48 +214,63 @@ void ewol::widget::Menu::onButtonPressed(ewol::widget::ButtonWeak _button) {
|
||||
if (it.m_localId != it2->m_parentId) {
|
||||
continue;
|
||||
}
|
||||
myButton = ewol::widget::Button::create();
|
||||
if (myButton == nullptr) {
|
||||
EWOL_ERROR("Allocation Error");
|
||||
continue;
|
||||
}
|
||||
myButton->propertyExpand.set(bvec2(true,true));
|
||||
myButton->propertyFill.set(bvec2(true,true));
|
||||
// set callback
|
||||
myButton->signalPressed.connect(sharedFromThis(), &ewol::widget::Menu::onButtonPressed, ewol::widget::ButtonWeak(myButton));
|
||||
// add it in the widget list
|
||||
mySizer->subWidgetAdd(myButton);
|
||||
if (it2->m_image.size() != 0) {
|
||||
std::string composeString;
|
||||
composeString+= " <sizer mode='hori' expand='true,false' fill='true,true' lock='true'>\n";
|
||||
if (etk::end_with(it2->m_image, ".edf") == true) {
|
||||
composeString+=" <image src='" + it2->m_image + "' size='8,8mm' distance-field='true'/>\n";
|
||||
} else {
|
||||
composeString+=" <image src='" + it2->m_image + "' size='8,8mm'/>\n";
|
||||
if (it2->m_message == "" && it2->m_label == "") {
|
||||
ewol::widget::SpacerShared mySpacer = ewol::widget::Spacer::create();
|
||||
if (mySpacer == nullptr) {
|
||||
EWOL_ERROR("Allocation spacer error");
|
||||
continue;
|
||||
}
|
||||
composeString+=" <label exand='true,true' fill='true,true'><left>" + it2->m_label + "</left></label>\n";
|
||||
composeString+=" </sizer>\n";
|
||||
myButton->setSubWidget(ewol::widget::composerGenerateString(composeString));
|
||||
mySpacer->propertyExpand.set(bvec2(true,true));
|
||||
mySpacer->propertyFill.set(bvec2(true,true));
|
||||
mySpacer->propertyMinSize.set(gale::Dimension(vec2(0,2), gale::distance::pixel));
|
||||
mySpacer->propertyMaxSize.set(gale::Dimension(vec2(10000,2), gale::distance::pixel));
|
||||
mySpacer->propertyColor.set(etk::Color<>(0,0,0,0xFF));
|
||||
// add it in the widget list
|
||||
mySizer->subWidgetAdd(mySpacer);
|
||||
} else {
|
||||
if (menuHaveImage == true) {
|
||||
myButton->setSubWidget(ewol::widget::composerGenerateString(
|
||||
std::string() +
|
||||
" <sizer mode='hori' expand='true,false' fill='true,true' lock='true'>\n"
|
||||
" <spacer min-size='8,0mm'/>\n"
|
||||
" <label exand='true,true' fill='true,true'><![CDATA[<left>" + it2->m_label + "</left>]]></label>\n"
|
||||
" </sizer>\n")
|
||||
);
|
||||
myButton = ewol::widget::Button::create();
|
||||
if (myButton == nullptr) {
|
||||
EWOL_ERROR("Allocation Error");
|
||||
continue;
|
||||
}
|
||||
myButton->propertyExpand.set(bvec2(true,true));
|
||||
myButton->propertyFill.set(bvec2(true,true));
|
||||
// set callback
|
||||
myButton->signalPressed.connect(sharedFromThis(), &ewol::widget::Menu::onButtonPressed, ewol::widget::ButtonWeak(myButton));
|
||||
// add it in the widget list
|
||||
mySizer->subWidgetAdd(myButton);
|
||||
if (it2->m_image.size() != 0) {
|
||||
std::string composeString;
|
||||
composeString+= " <sizer mode='hori' expand='true,false' fill='true,true' lock='true'>\n";
|
||||
if (etk::end_with(it2->m_image, ".edf") == true) {
|
||||
composeString+=" <image src='" + it2->m_image + "' size='8,8mm' distance-field='true'/>\n";
|
||||
} else {
|
||||
composeString+=" <image src='" + it2->m_image + "' size='8,8mm'/>\n";
|
||||
}
|
||||
composeString+=" <label exand='true,true' fill='true,true'><left>" + it2->m_label + "</left></label>\n";
|
||||
composeString+=" </sizer>\n";
|
||||
myButton->setSubWidget(ewol::widget::composerGenerateString(composeString));
|
||||
} else {
|
||||
ewol::widget::LabelShared tmpLabel = widget::Label::create();
|
||||
if (tmpLabel != nullptr) {
|
||||
tmpLabel->propertyValue.set(std::string("<left>") + it2->m_label + "</left>\n");
|
||||
tmpLabel->propertyExpand.set(bvec2(true,false));
|
||||
tmpLabel->propertyFill.set(bvec2(true,true));
|
||||
myButton->setSubWidget(tmpLabel);
|
||||
if (menuHaveImage == true) {
|
||||
myButton->setSubWidget(ewol::widget::composerGenerateString(
|
||||
std::string() +
|
||||
" <sizer mode='hori' expand='true,false' fill='true,true' lock='true'>\n"
|
||||
" <spacer min-size='8,0mm'/>\n"
|
||||
" <label exand='true,true' fill='true,true'><![CDATA[<left>" + it2->m_label + "</left>]]></label>\n"
|
||||
" </sizer>\n")
|
||||
);
|
||||
} else {
|
||||
ewol::widget::LabelShared tmpLabel = widget::Label::create();
|
||||
if (tmpLabel != nullptr) {
|
||||
tmpLabel->propertyValue.set(std::string("<left>") + it2->m_label + "</left>\n");
|
||||
tmpLabel->propertyExpand.set(bvec2(true,false));
|
||||
tmpLabel->propertyFill.set(bvec2(true,true));
|
||||
myButton->setSubWidget(tmpLabel);
|
||||
}
|
||||
}
|
||||
}
|
||||
it2->m_widgetPointer = myButton;
|
||||
}
|
||||
it2->m_widgetPointer = myButton;
|
||||
}
|
||||
}
|
||||
ewol::widget::WindowsShared currentWindows = getWindows();
|
||||
@ -272,12 +309,11 @@ bool ewol::widget::Menu::loadXML(const exml::Element& _node) {
|
||||
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();
|
||||
addSpacer(idMenu);
|
||||
} else {
|
||||
EWOL_ERROR("[" << getId() << "] {" << getObjectType() << "} (l " << pNode2.getPos() << ") Unknown basic node='" << widgetName2 << "' not in : [elem,separator]" );
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ namespace ewol {
|
||||
void clear();
|
||||
int32_t addTitle(const std::string& _label, const std::string& _image="", const std::string& _message = "");
|
||||
int32_t add(int32_t _parent, const std::string& _label, const std::string& _image="", const std::string& _message = "");
|
||||
int32_t addSpacer();
|
||||
int32_t addSpacer(int32_t _parent=-1);
|
||||
void remove(int32_t _id);
|
||||
private:
|
||||
void onButtonPressed(ewol::widget::ButtonWeak _button);
|
||||
|
@ -233,6 +233,7 @@ void ewol::widget::WSlider::systemDraw(const ewol::DrawProperty& _displayProp) {
|
||||
std::advance(it, m_windowsDestination);
|
||||
if ( it != m_subWidget.end()
|
||||
&& *it != nullptr) {
|
||||
//EWOL_INFO("Draw : [" << propertyName << "] t=" << getObjectType() << "o=" << m_origin << " s=" << m_size);
|
||||
(*it)->systemDraw(prop);
|
||||
}
|
||||
} else {
|
||||
|
@ -151,6 +151,7 @@ void ewol::Widget::setOffset(const vec2& _newVal) {
|
||||
(0,0)
|
||||
*/
|
||||
void ewol::Widget::systemDraw(const ewol::DrawProperty& _displayProp) {
|
||||
//EWOL_INFO("[" << getId() << "] Draw : [" << propertyName << "] t=" << getObjectType() << " o=" << m_origin << " s=" << m_size << " hide=" << propertyHide);
|
||||
if (*propertyHide == true){
|
||||
// widget is hidden ...
|
||||
return;
|
||||
@ -658,4 +659,13 @@ bool ewol::Widget::stopAnnimation() {
|
||||
m_annimationMode = ewol::Widget::annimationModeDisable;
|
||||
onStopAnnimation();
|
||||
return true; // ???
|
||||
}
|
||||
|
||||
|
||||
void ewol::Widget::drawWidgetTree(int32_t _level) {
|
||||
std::string space;
|
||||
for (int32_t iii=0; iii<_level; ++iii) {
|
||||
space += " ";
|
||||
}
|
||||
EWOL_PRINT(space << "[" << getId() << "] name='" << propertyName << "' type=" << getObjectType() << " o=" << m_origin << " s=" << m_size << " hide=" << propertyHide);
|
||||
}
|
@ -39,9 +39,13 @@ namespace ewol {
|
||||
#define DECLARE_WIDGET_FACTORY(className, name) \
|
||||
DECLARE_FACTORY(className); \
|
||||
static void createManagerWidget(ewol::widget::Manager& _widgetManager) { \
|
||||
_widgetManager.addWidgetCreator(name, []() -> ewol::WidgetShared { \
|
||||
return className::create(); \
|
||||
}); \
|
||||
_widgetManager.addWidgetCreator(name, \
|
||||
[]() -> ewol::WidgetShared { \
|
||||
return className::create(); \
|
||||
}, \
|
||||
[](const exml::Element& _node) -> ewol::WidgetShared { \
|
||||
return className::createXml(_node); \
|
||||
}); \
|
||||
}
|
||||
|
||||
namespace ewol {
|
||||
@ -578,6 +582,8 @@ namespace ewol {
|
||||
virtual void onChangePropertyExpand();
|
||||
virtual void onChangePropertyMaxSize();
|
||||
virtual void onChangePropertyMinSize();
|
||||
public:
|
||||
virtual void drawWidgetTree(int32_t _level=0);
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -263,4 +263,16 @@ ewol::ObjectShared ewol::widget::Windows::getSubObjectNamed(const std::string& _
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void ewol::widget::Windows::drawWidgetTree(int32_t _level) {
|
||||
ewol::Widget::drawWidgetTree(_level);
|
||||
_level++;
|
||||
if (m_subWidget != nullptr) {
|
||||
m_subWidget->drawWidgetTree(_level);
|
||||
}
|
||||
for (auto &it: m_popUpWidgetList) {
|
||||
if (it != nullptr) {
|
||||
it->drawWidgetTree(_level);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,6 +70,7 @@ namespace ewol {
|
||||
ewol::WidgetShared getWidgetAtPos(const vec2& _pos) override;
|
||||
void requestDestroyFromChild(const ewol::ObjectShared& _child) override;
|
||||
ewol::ObjectShared getSubObjectNamed(const std::string& _objectName) override;
|
||||
void drawWidgetTree(int32_t _level=0) override;
|
||||
protected:
|
||||
/**
|
||||
* @brief Called when property change: Title
|
||||
|
Loading…
x
Reference in New Issue
Block a user