From 3ff3c3871091e4cccdae8eedf8aec41bc11d394a Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Thu, 11 Apr 2013 21:24:22 +0200 Subject: [PATCH] [DEV] end composer and add a container obstraction --- external/etk | 2 +- sources/ewol/widget/Button.cpp | 1 + sources/ewol/widget/Composer.cpp | 92 +++++-------------- sources/ewol/widget/Composer.h | 48 +++------- sources/ewol/widget/Container.cpp | 125 ++++++++++++++++++++++++++ sources/ewol/widget/Container.h | 62 +++++++++++++ sources/ewol/widget/ContainerN.cpp | 0 sources/ewol/widget/ContainerN.h | 64 +++++++++++++ sources/ewol/widget/Image.h | 4 +- sources/ewol/widget/Label.cpp | 3 +- sources/ewol/widget/Label.h | 2 +- sources/ewol/widget/Sizer.cpp | 69 ++++++++++++++ sources/ewol/widget/Sizer.h | 3 +- sources/ewol/widget/Widget.cpp | 11 +++ sources/ewol/widget/Widget.h | 6 ++ sources/ewol/widget/WidgetManager.cpp | 6 +- sources/file.mk | 1 + 17 files changed, 387 insertions(+), 112 deletions(-) create mode 100644 sources/ewol/widget/Container.cpp create mode 100644 sources/ewol/widget/Container.h create mode 100644 sources/ewol/widget/ContainerN.cpp create mode 100644 sources/ewol/widget/ContainerN.h diff --git a/external/etk b/external/etk index 2b19ef4b..32da0ffb 160000 --- a/external/etk +++ b/external/etk @@ -1 +1 @@ -Subproject commit 2b19ef4bc89e82906865244e056a138c937f88de +Subproject commit 32da0ffb78f9ff9e3ede49c87a9fd5c19e23136b diff --git a/sources/ewol/widget/Button.cpp b/sources/ewol/widget/Button.cpp index e719a25c..6fd312f0 100644 --- a/sources/ewol/widget/Button.cpp +++ b/sources/ewol/widget/Button.cpp @@ -100,6 +100,7 @@ void widget::Button::SetSubWidget(ewol::Widget* subWidget) m_subWidget[idWidget] = subWidget; // element change ... We need to recalculate all the subElments : ewol::RequestUpdateSize(); + MarkToRedraw(); } void widget::Button::SetSubWidgetToggle(ewol::Widget* subWidget) diff --git a/sources/ewol/widget/Composer.cpp b/sources/ewol/widget/Composer.cpp index dff17aa0..51afc2f8 100644 --- a/sources/ewol/widget/Composer.cpp +++ b/sources/ewol/widget/Composer.cpp @@ -12,34 +12,33 @@ #include #include -widget::Composer::Composer(void) : - m_subWidget(NULL) + +widget::Composer::Composer(void) { // nothing to do ... - } +widget::Composer::Composer(widget::Composer::composerMode_te mode, const etk::UString& fileName) +{ + switch(mode) { + case widget::Composer::None: + // nothing to do ... + break; + case widget::Composer::String: + LoadFromString(fileName); + break; + case widget::Composer::File: + LoadFromFile(fileName); + break; + } +} + + widget::Composer::~Composer(void) { - Clean(); + } -void widget::Composer::Clean(void) -{ - if (NULL != m_subWidget) { - delete(m_subWidget); - // might have been destroy first here : - if (m_subWidget!=NULL) { - EWOL_ERROR("Composer : An error Occured when removing main node"); - } - } - // nothing else to do .. all node in the list might have been removed now ... - if (0!=m_list.Size()) { - EWOL_ERROR("the subName element in the list are incorect..."); - } -} - - bool widget::Composer::LoadFromFile(const etk::UString& _fileName) { // open the curent File @@ -98,7 +97,7 @@ bool widget::Composer::CommonLoadXML(const char* data) return false; } // remove previous elements ... - Clean(); + RemoveSubWidget(); ewol::Widget::LoadXML(root); for(TiXmlNode * pNode = root->FirstChild() ; @@ -113,7 +112,7 @@ bool widget::Composer::CommonLoadXML(const char* data) EWOL_ERROR("(l "<Row()<<") Unknown basic node=\"" << widgetName << "\" not in : [" << ewol::widgetManager::List() << "]" ); continue; } - if (NULL != m_subWidget) { + if (NULL != GetSubWidget()) { EWOL_ERROR("(l "<Row()<<") " << __class__ << " Can only have one subWidget ??? node=\"" << widgetName << "\"" ); continue; } @@ -122,6 +121,8 @@ bool widget::Composer::CommonLoadXML(const char* data) EWOL_ERROR ("(l "<Row()<<") Can not create the widget : \"" << widgetName << "\""); continue; } + // add widget : + SetSubWidget(tmpWidget); if (false == tmpWidget->LoadXML(pNode)) { EWOL_ERROR ("(l "<Row()<<") can not load widget properties : \"" << widgetName << "\""); return false; @@ -131,50 +132,3 @@ bool widget::Composer::CommonLoadXML(const char* data) } -ewol::Widget* widget::Composer::GetWidgetNamed(const etk::UString& widgetName) -{ - for (int32_t iii=0; iiiGenDraw(displayProp); - } -} - -void widget::Composer::CalculateSize(const vec2& availlable) -{ - if (NULL!=m_subWidget) { - m_subWidget->CalculateSize(availlable); - // copy all sub parameters: - m_hide = m_subWidget->IsHide(); - } -} -void widget::Composer::CalculateMinMaxSize(void) -{ - if (NULL!=m_subWidget) { - m_subWidget->CalculateMinMaxSize(); - // copy all sub parameters : - m_hide = m_subWidget->IsHide(); - m_userFill = m_subWidget->CanFill(); - - } -} diff --git a/sources/ewol/widget/Composer.h b/sources/ewol/widget/Composer.h index 29983fc6..106b83c9 100644 --- a/sources/ewol/widget/Composer.h +++ b/sources/ewol/widget/Composer.h @@ -11,36 +11,36 @@ #include #include -#include +#include namespace widget { /** * @brief the composer widget is a widget that create a link on a string.file to parse the data and generate some widget tree */ - class Composer : public ewol::Widget + class Composer : public widget::Container { - private: - class ComposerWidgetListNamed { - public: - ewol::Widget* widget; - etk::UString widgetName; - }; - ewol::Widget* m_subWidget; - etk::Vector m_list; + public: + typedef enum { + None, + String, + File + } composerMode_te; public: /** * @brief Constructor */ Composer(void); + /** + * @brief Constructor + * @param[in] mode mode of parsing the string + * @param[in] data File/directString data to generate compositing of the widget.. + */ + Composer(composerMode_te mode, const etk::UString& data); /** * @brief Destructor */ ~Composer(void); - /** - * @brief Remove all sub elements - */ - void Clean(void); /** * @brief Load a composition with a file * @param[in] fileName Name of the file @@ -63,26 +63,6 @@ namespace widget * @return false ==> some error occured. */ bool CommonLoadXML(const char* data); - public: - /** - * @brief Get the main node widget - * @return the requested pointer on the node - */ - ewol::Widget* GetMainWidget(void); - /** - * @brief Get the main node widget - * @param[in] widgetName name of the widget - * @return the requested pointer on the node - */ - ewol::Widget* GetWidgetNamed(const etk::UString& widgetName); - - protected: // Derived function - virtual void OnDraw(ewol::DrawProperty& displayProp); - public:// Derived function - virtual void OnObjectRemove(ewol::EObject* removeObject); - virtual void CalculateSize(const vec2& availlable); - virtual void CalculateMinMaxSize(void); - // TODO : Call all sub element getter an setter ==> this object might be transparent ... }; }; diff --git a/sources/ewol/widget/Container.cpp b/sources/ewol/widget/Container.cpp new file mode 100644 index 00000000..32276db9 --- /dev/null +++ b/sources/ewol/widget/Container.cpp @@ -0,0 +1,125 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2011, Edouard DUPIN, all right reserved + * + * @license BSD v3 (see license file) + */ + + +#include +#include +#include +#include + + +widget::Container::Container(ewol::Widget* subElement) : + m_subWidget(subElement) +{ + // nothing to do ... +} + +widget::Container::~Container(void) +{ + RemoveSubWidget(); +} + +ewol::Widget* widget::Container::GetSubWidget(void) +{ + return m_subWidget; +} + +void widget::Container::SetSubWidget(ewol::Widget* newWidget) +{ + if (NULL==newWidget) { + return; + } + RemoveSubWidget(); + m_subWidget = newWidget; + MarkToRedraw(); + ewol::RequestUpdateSize(); +} + + +void widget::Container::RemoveSubWidget(void) +{ + if (NULL != m_subWidget) { + delete(m_subWidget); + // might have been destroy first here : + if (m_subWidget!=NULL) { + EWOL_ERROR("Composer : An error Occured when removing main node"); + } + MarkToRedraw(); + ewol::RequestUpdateSize(); + } +} + +ewol::Widget* widget::Container::GetWidgetNamed(const etk::UString& widgetName) +{ + if (GetName()==widgetName) { + return this; + } + if (NULL != m_subWidget) { + return m_subWidget->GetWidgetNamed(widgetName); + } + return NULL; +} + +void widget::Container::OnObjectRemove(ewol::EObject* removeObject) +{ + if (m_subWidget==removeObject) { + m_subWidget=NULL; + MarkToRedraw(); + ewol::RequestUpdateSize(); + } +} + +void widget::Container::OnDraw(ewol::DrawProperty& displayProp) +{ + if (NULL!=m_subWidget) { + m_subWidget->GenDraw(displayProp); + } +} + +void widget::Container::CalculateSize(const vec2& availlable) +{ + if (NULL!=m_subWidget) { + m_subWidget->SetOrigin(m_origin); + m_subWidget->CalculateSize(availlable); + } + ewol::Widget::CalculateSize(availlable); +} + +void widget::Container::CalculateMinMaxSize(void) +{ + // callmain class + ewol::Widget::CalculateMinMaxSize(); + // call sub classes + if (NULL!=m_subWidget) { + m_subWidget->CalculateMinMaxSize(); + vec2 min = m_subWidget->GetCalculateMinSize(); + if (m_minSize.x()OnRegenerateDisplay(); + } +} + +ewol::Widget* widget::Container::GetWidgetAtPos(const vec2& pos) +{ + if (false==IsHide()) { + if (NULL!=m_subWidget) { + return m_subWidget->GetWidgetAtPos(pos); + } + } + return NULL; +}; diff --git a/sources/ewol/widget/Container.h b/sources/ewol/widget/Container.h new file mode 100644 index 00000000..4d0c626c --- /dev/null +++ b/sources/ewol/widget/Container.h @@ -0,0 +1,62 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2011, Edouard DUPIN, all right reserved + * + * @license BSD v3 (see license file) + */ + +#ifndef __EWOL_WIDGET_CONTAINER_H__ +#define __EWOL_WIDGET_CONTAINER_H__ + +#include +#include +#include + +namespace widget +{ + /** + * @brief the Cotainer widget is a widget that have an only one subWidget + */ + class Container : public ewol::Widget + { + private: + ewol::Widget* m_subWidget; + public: + /** + * @brief Constructor + */ + Container(ewol::Widget* subElement=NULL); + /** + * @brief Destructor + */ + ~Container(void); + public: + /** + * @brief Get the main node widget + * @return the requested pointer on the node + */ + ewol::Widget* GetSubWidget(void); + /** + * @brief Set the subWidget node widget. + * @param[in] newWidget The widget to Add. + */ + void SetSubWidget(ewol::Widget* newWidget); + /** + * @brief Remove the subWidget node. + */ + void RemoveSubWidget(void); + + protected: // Derived function + virtual void OnDraw(ewol::DrawProperty& displayProp); + public:// Derived function + virtual void OnRegenerateDisplay(void); + virtual void OnObjectRemove(ewol::EObject* removeObject); + virtual void CalculateSize(const vec2& availlable); + virtual void CalculateMinMaxSize(void); + virtual ewol::Widget* GetWidgetAtPos(const vec2& pos); + virtual ewol::Widget* GetWidgetNamed(const etk::UString& widgetName); + }; +}; + +#endif diff --git a/sources/ewol/widget/ContainerN.cpp b/sources/ewol/widget/ContainerN.cpp new file mode 100644 index 00000000..e69de29b diff --git a/sources/ewol/widget/ContainerN.h b/sources/ewol/widget/ContainerN.h new file mode 100644 index 00000000..031a2ddd --- /dev/null +++ b/sources/ewol/widget/ContainerN.h @@ -0,0 +1,64 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2011, Edouard DUPIN, all right reserved + * + * @license BSD v3 (see license file) + */ + +#ifndef __EWOL_WIDGET_CONTAINER_H__ +#define __EWOL_WIDGET_CONTAINER_H__ + +#include +#include +#include + +namespace widget +{ + /** + * @brief the Cotainer widget is a widget that have an only one subWidget + */ + class ContainerN : public ewol::Widget + { + private: + int32_t m_limitElement; + etk::Vector m_subList; + public: + /** + * @brief Constructor + */ + ContainerN(int32_t limitElement=-1); + /** + * @brief Destructor + */ + ~ContainerN(void); + public: + /** + * @brief Get the main node widget + * @return the requested pointer on the node + */ + ewol::Widget* GetSubWidget(int32_t id); + /** + * @brief Set the subWidget node widget. + * @param[in] newWidget The widget to Add. + */ + void SubWidgetAdd(ewol::Widget* newWidget); + void SubWidgetAddStart(ewol::Widget* newWidget); + /** + * @brief Remove the subWidget node. + */ + void RemoveSubWidget(void); + + protected: // Derived function + virtual void OnDraw(ewol::DrawProperty& displayProp); + public:// Derived function + virtual void OnRegenerateDisplay(void); + virtual void OnObjectRemove(ewol::EObject* removeObject); + virtual void CalculateSize(const vec2& availlable); + virtual void CalculateMinMaxSize(void); + virtual ewol::Widget* GetWidgetAtPos(const vec2& pos); + virtual ewol::Widget* GetWidgetNamed(const etk::UString& widgetName); + }; +}; + +#endif diff --git a/sources/ewol/widget/Image.h b/sources/ewol/widget/Image.h index b0704e22..bc8eec75 100644 --- a/sources/ewol/widget/Image.h +++ b/sources/ewol/widget/Image.h @@ -23,10 +23,10 @@ namespace widget { static void Init(void); static void UnInit(void); public: - Image(const etk::UString& dataFile="", int32_t size=-1); // automatic considering in the appl Data older + Image(const etk::UString& dataFile="", int32_t size=-1); virtual ~Image(void); void SetFile(etk::UString newFile); - void SetPadding(vec2 newPadding); + void SetPadding(vec2 newPadding); private: etk::UString m_imageSelected; vec2 m_padding; diff --git a/sources/ewol/widget/Label.cpp b/sources/ewol/widget/Label.cpp index 88ff9c42..6d5a93e8 100644 --- a/sources/ewol/widget/Label.cpp +++ b/sources/ewol/widget/Label.cpp @@ -61,7 +61,7 @@ void widget::Label::CalculateMinMaxSize(void) } -void widget::Label::SetLabel(etk::UString newLabel) +void widget::Label::SetLabel(const etk::UString& newLabel) { m_label = newLabel; MarkToRedraw(); @@ -152,6 +152,7 @@ bool widget::Label::LoadXML(TiXmlNode* node) ewol::Widget::LoadXML(node); // get internal data : // TODO : Unparse data type XML ... + EWOL_DEBUG("Load label:" << node->ToElement()->GetText()); SetLabel(node->ToElement()->GetText()); return true; } diff --git a/sources/ewol/widget/Label.h b/sources/ewol/widget/Label.h index 84fa36fe..7e7af399 100644 --- a/sources/ewol/widget/Label.h +++ b/sources/ewol/widget/Label.h @@ -39,7 +39,7 @@ namespace widget { * @brief Change the label displayed * @param[in] newLabel The displayed decorated text. */ - void SetLabel(etk::UString newLabel); + void SetLabel(const etk::UString& newLabel); /** * @brief Get the current displayed label * @return The displayed decorated text. diff --git a/sources/ewol/widget/Sizer.cpp b/sources/ewol/widget/Sizer.cpp index 2aca1e22..37011f0c 100644 --- a/sources/ewol/widget/Sizer.cpp +++ b/sources/ewol/widget/Sizer.cpp @@ -345,3 +345,72 @@ void widget::Sizer::OnObjectRemove(ewol::EObject * removeObject) } +bool widget::Sizer::LoadXML(TiXmlNode* node) +{ + if (NULL==node) { + return false; + } + // parse generic properties : + ewol::Widget::LoadXML(node); + // remove previous element : + SubWidgetRemoveAll(); + + const char *tmpAttributeValue = node->ToElement()->Attribute("lock"); + if (NULL != tmpAttributeValue) { + etk::UString val(tmpAttributeValue); + m_lockExpandContamination = val; + } + tmpAttributeValue = node->ToElement()->Attribute("borderSize"); + if (NULL != tmpAttributeValue) { + etk::UString val(tmpAttributeValue); + m_borderSize = val; + } + tmpAttributeValue = node->ToElement()->Attribute("mode"); + if (NULL != tmpAttributeValue) { + etk::UString val(tmpAttributeValue); + if( val.CompareNoCase("vert") + || val.CompareNoCase("vertical")) { + m_mode = widget::Sizer::modeVert; + } else { + m_mode = widget::Sizer::modeHori; + } + } + bool invertAdding=false; + tmpAttributeValue = node->ToElement()->Attribute("addmode"); + if (NULL != tmpAttributeValue) { + etk::UString val(tmpAttributeValue); + if(val.CompareNoCase("invert")) { + invertAdding=true; + } + } + // parse all the elements : + for(TiXmlNode * pNode = node->FirstChild() ; + NULL != pNode ; + pNode = pNode->NextSibling() ) { + if (pNode->Type()==TiXmlNode::TINYXML_COMMENT) { + // nothing to do, just proceed to next step + continue; + } + etk::UString widgetName = pNode->Value(); + if (ewol::widgetManager::Exist(widgetName) == false) { + EWOL_ERROR("(l "<Row()<<") Unknown basic node=\"" << widgetName << "\" not in : [" << ewol::widgetManager::List() << "]" ); + continue; + } + ewol::Widget *subWidget = ewol::widgetManager::Create(widgetName); + if (subWidget == NULL) { + EWOL_ERROR ("(l "<Row()<<") Can not create the widget : \"" << widgetName << "\""); + continue; + } + // add sub element : + if (false==invertAdding) { + SubWidgetAdd(subWidget); + } else { + SubWidgetAddStart(subWidget); + } + if (false == subWidget->LoadXML(pNode)) { + EWOL_ERROR ("(l "<Row()<<") can not load widget properties : \"" << widgetName << "\""); + return false; + } + } + return true; +} diff --git a/sources/ewol/widget/Sizer.h b/sources/ewol/widget/Sizer.h index 2b42c3c7..6186516a 100644 --- a/sources/ewol/widget/Sizer.h +++ b/sources/ewol/widget/Sizer.h @@ -104,7 +104,8 @@ namespace widget { virtual void CalculateMinMaxSize(void); virtual void SetMinSize(const vec2& size); virtual void SetExpand(const bvec2& newExpand); - virtual bvec2 CanExpand(void);; + virtual bvec2 CanExpand(void); + virtual bool LoadXML(TiXmlNode* node); }; }; diff --git a/sources/ewol/widget/Widget.cpp b/sources/ewol/widget/Widget.cpp index 298db33b..48c5cab9 100644 --- a/sources/ewol/widget/Widget.cpp +++ b/sources/ewol/widget/Widget.cpp @@ -593,6 +593,8 @@ bool ewol::Widget::LoadXML(TiXmlNode* node) if (NULL != tmpAttributeValue) { m_userMaxSize.SetString(tmpAttributeValue); } + EWOL_DEBUG("Widget parse: m_hide=" << m_hide << " m_userMinSize=" << m_userMinSize << " m_userMaxSize=" << m_userMaxSize << " m_userFill=" << m_userFill << " m_userExpand=" << m_userExpand); + MarkToRedraw(); return ret; } @@ -634,3 +636,12 @@ bool ewol::Widget::StoreXML(TiXmlNode* node) } +ewol::Widget* ewol::Widget::GetWidgetNamed(const etk::UString& widgetName) +{ + if (GetName()==widgetName) { + return this; + } + return NULL; +} + + diff --git a/sources/ewol/widget/Widget.h b/sources/ewol/widget/Widget.h index 2ea15735..dd17a39d 100644 --- a/sources/ewol/widget/Widget.h +++ b/sources/ewol/widget/Widget.h @@ -347,6 +347,12 @@ namespace ewol { * @note : INTERNAL EWOL SYSTEM */ virtual ewol::Widget* GetWidgetAtPos(const vec2& pos) { if (false==IsHide()) { return this; } return NULL; }; + /** + * @brief Get the widget if it have this name or one of the subwidget with the same name + * @param[in] widgetName name of the widget + * @return the requested pointer on the node (or NULL pointer) + */ + virtual ewol::Widget* GetWidgetNamed(const etk::UString& widgetName); /** * @brief Event on an input of this Widget * @param[in] type Type of the input (ewol::INPUT_TYPE_MOUSE/ewol::INPUT_TYPE_FINGER ...) diff --git a/sources/ewol/widget/WidgetManager.cpp b/sources/ewol/widget/WidgetManager.cpp index dc51fc39..dab5d570 100644 --- a/sources/ewol/widget/WidgetManager.cpp +++ b/sources/ewol/widget/WidgetManager.cpp @@ -259,7 +259,7 @@ bool ewol::widgetManager::IsDrawingNeeded(void) void ewol::widgetManager::AddWidgetCreator(const etk::UString& name, ewol::widgetManager::creator_tf pointer) { for (int32_t iii=0; iii