[DEV] add an API to create widget with XML

This commit is contained in:
Edouard DUPIN 2016-01-29 21:24:02 +01:00
parent 7273b617ff
commit b595794a0d
6 changed files with 89 additions and 5 deletions

View File

@ -48,6 +48,22 @@ void ewol::widget::Container::setSubWidget(std::shared_ptr<ewol::Widget> _newWid
requestUpdateSize();
}
void ewol::widget::Container::subWidgetReplace(const std::shared_ptr<ewol::Widget>& _oldWidget,
const std::shared_ptr<ewol::Widget>& _newWidget) {
if (m_subWidget != _oldWidget) {
EWOL_WARNING("Request replace with a wrong old widget");
return;
}
m_subWidget->removeParent();
m_subWidget.reset();
m_subWidget = _newWidget;
if (m_subWidget != nullptr) {
m_subWidget->setParent(shared_from_this());
}
markToRedraw();
requestUpdateSize();
}
void ewol::widget::Container::subWidgetRemove() {
if (m_subWidget != nullptr) {
m_subWidget->removeParent();
@ -163,7 +179,7 @@ bool ewol::widget::Container::loadXML(const std::shared_ptr<const exml::Element>
EWOL_ERROR("(l "<<pNode->getPos()<<") Unknown basic node=\"" << widgetName << "\" not in : [" << getWidgetManager().list() << "]" );
continue;
}
if (nullptr != getSubWidget()) {
if (getSubWidget() != nullptr) {
EWOL_ERROR("(l "<<pNode->getPos()<<") " << __class__ << " Can only have one subWidget ??? node=\"" << widgetName << "\"" );
continue;
}

View File

@ -44,6 +44,13 @@ namespace ewol {
* @param[in] _newWidget The widget to add.
*/
void setSubWidget(std::shared_ptr<ewol::Widget> _newWidget);
/**
* @brief Replace a old subwidget with a new one.
* @param[in] _oldWidget The widget to replace.
* @param[in] _newWidget The widget to set.
*/
virtual void subWidgetReplace(const std::shared_ptr<ewol::Widget>& _oldWidget,
const std::shared_ptr<ewol::Widget>& _newWidget);
/**
* @brief remove the subWidget node (async).
*/

View File

@ -44,6 +44,29 @@ void ewol::widget::Container2::setSubWidget(std::shared_ptr<ewol::Widget> _newWi
requestUpdateSize();
}
void ewol::widget::Container2::subWidgetReplace(const std::shared_ptr<ewol::Widget>& _oldWidget,
const std::shared_ptr<ewol::Widget>& _newWidget) {
bool haveChange = false;
for (size_t iii=0; iii<2; ++iii) {
if (m_subWidget[iii] != _oldWidget) {
continue;
}
m_subWidget[iii]->removeParent();
m_subWidget[iii].reset();
m_subWidget[iii] = _newWidget;
if (m_subWidget[iii] != nullptr) {
m_subWidget[iii]->setParent(shared_from_this());
}
haveChange = true;
}
if (haveChange == false) {
EWOL_WARNING("Request replace with a wrong old widget");
return;
}
markToRedraw();
requestUpdateSize();
}
void ewol::widget::Container2::subWidgetRemove(int32_t _idWidget) {
if (m_subWidget[_idWidget] != nullptr) {

View File

@ -151,6 +151,13 @@ namespace ewol {
}
return _id;
}
/**
* @brief Replace a old subwidget with a new one.
* @param[in] _oldWidget The widget to replace.
* @param[in] _newWidget The widget to set.
*/
virtual void subWidgetReplace(const std::shared_ptr<ewol::Widget>& _oldWidget,
const std::shared_ptr<ewol::Widget>& _newWidget);
public: // Derived function
virtual void systemDraw(const ewol::DrawProperty& _displayProp);
virtual void onRegenerateDisplay();

View File

@ -56,14 +56,38 @@ void ewol::widget::ContainerN::lockExpand(const bvec2& _lockExpand) {
}
void ewol::widget::ContainerN::subWidgetReplace(const std::shared_ptr<ewol::Widget>& _oldWidget,
const std::shared_ptr<ewol::Widget>& _newWidget) {
bool haveChange = false;
for (auto &it : m_subWidget) {
if (it != _oldWidget) {
continue;
}
EWOL_WARNING("Remove old");
it->removeParent();
it.reset();
EWOL_WARNING("Set New");
if (_newWidget != nullptr) {
EWOL_WARNING("set parrent");
_newWidget->setParent(shared_from_this());
}
it = _newWidget;
haveChange = true;
}
if (haveChange == false) {
EWOL_WARNING("Request replace with a wrong old widget");
return;
}
markToRedraw();
requestUpdateSize();
}
int32_t ewol::widget::ContainerN::subWidgetAdd(std::shared_ptr<ewol::Widget> _newWidget) {
if (nullptr == _newWidget) {
if (_newWidget == nullptr) {
EWOL_ERROR("[" << getId() << "] {" << getObjectType() << "} Try to add An empty Widget ... ");
return -1;
}
if (_newWidget != nullptr) {
_newWidget->setParent(shared_from_this());
}
_newWidget->setParent(shared_from_this());
m_subWidget.push_back(_newWidget);
markToRedraw();
requestUpdateSize();

View File

@ -54,6 +54,13 @@ namespace ewol {
* @brief remove all sub element from the widget (delayed to prevent remove in the callbback).
*/
virtual void subWidgetRemoveAllDelayed();
/**
* @brief Replace a old subwidget with a new one.
* @param[in] _oldWidget The widget to replace.
* @param[in] _newWidget The widget to set.
*/
virtual void subWidgetReplace(const std::shared_ptr<ewol::Widget>& _oldWidget,
const std::shared_ptr<ewol::Widget>& _newWidget);
/**
* @brief add at end position a Widget (note : This system use an inverted phylisophie (button to top, and left to right)
* @param[in] _newWidget the element pointer