[DEV] end composer and add a container obstraction

This commit is contained in:
Edouard DUPIN 2013-04-11 21:24:22 +02:00
parent 3bb4c6a700
commit 3ff3c38710
17 changed files with 387 additions and 112 deletions

2
external/etk vendored

@ -1 +1 @@
Subproject commit 2b19ef4bc89e82906865244e056a138c937f88de
Subproject commit 32da0ffb78f9ff9e3ede49c87a9fd5c19e23136b

View File

@ -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)

View File

@ -12,34 +12,33 @@
#include <etk/os/FSNode.h>
#include <ewol/widget/WidgetManager.h>
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 "<<pNode->Row()<<") Unknown basic node=\"" << widgetName << "\" not in : [" << ewol::widgetManager::List() << "]" );
continue;
}
if (NULL != m_subWidget) {
if (NULL != GetSubWidget()) {
EWOL_ERROR("(l "<<pNode->Row()<<") " << __class__ << " Can only have one subWidget ??? node=\"" << widgetName << "\"" );
continue;
}
@ -122,6 +121,8 @@ bool widget::Composer::CommonLoadXML(const char* data)
EWOL_ERROR ("(l "<<pNode->Row()<<") Can not create the widget : \"" << widgetName << "\"");
continue;
}
// add widget :
SetSubWidget(tmpWidget);
if (false == tmpWidget->LoadXML(pNode)) {
EWOL_ERROR ("(l "<<pNode->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; iii<m_list.Size(); iii++) {
if (m_list[iii].widgetName == widgetName) {
return m_list[iii].widget;
}
}
return NULL;
}
void widget::Composer::OnObjectRemove(ewol::EObject* removeObject)
{
for (int32_t iii=0; iii<m_list.Size(); iii++) {
if (m_list[iii].widget == removeObject) {
m_list.Erase(iii);
}
}
if (m_subWidget==removeObject) {
m_subWidget=NULL;
}
}
void widget::Composer::OnDraw(ewol::DrawProperty& displayProp)
{
if (NULL!=m_subWidget) {
m_subWidget->GenDraw(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();
}
}

View File

@ -11,36 +11,36 @@
#include <etk/types.h>
#include <ewol/debug.h>
#include <ewol/widget/Widget.h>
#include <ewol/widget/Container.h>
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<ComposerWidgetListNamed> 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 ...
};
};

View File

@ -0,0 +1,125 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#include <ewol/ewol.h>
#include <ewol/widget/Composer.h>
#include <etk/os/FSNode.h>
#include <ewol/widget/WidgetManager.h>
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()<min.x()) {
m_minSize.setX(min.x());
}
if (m_minSize.y()<min.y()) {
m_minSize.setY(min.y());
}
}
}
void widget::Container::OnRegenerateDisplay(void)
{
if (NULL!=m_subWidget) {
m_subWidget->OnRegenerateDisplay();
}
}
ewol::Widget* widget::Container::GetWidgetAtPos(const vec2& pos)
{
if (false==IsHide()) {
if (NULL!=m_subWidget) {
return m_subWidget->GetWidgetAtPos(pos);
}
}
return NULL;
};

View File

@ -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 <etk/types.h>
#include <ewol/debug.h>
#include <ewol/widget/Widget.h>
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

View File

View File

@ -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 <etk/types.h>
#include <ewol/debug.h>
#include <ewol/widget/Widget.h>
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<ewol::Widget*> 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

View File

@ -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;

View File

@ -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;
}

View File

@ -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.

View File

@ -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 "<<pNode->Row()<<") Unknown basic node=\"" << widgetName << "\" not in : [" << ewol::widgetManager::List() << "]" );
continue;
}
ewol::Widget *subWidget = ewol::widgetManager::Create(widgetName);
if (subWidget == NULL) {
EWOL_ERROR ("(l "<<pNode->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 "<<pNode->Row()<<") can not load widget properties : \"" << widgetName << "\"");
return false;
}
}
return true;
}

View File

@ -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);
};
};

View File

@ -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;
}

View File

@ -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 ...)

View File

@ -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<l_creatorList.Size() ; iii++) {
if (name == l_creatorList[iii].name) {
if (name.CompareNoCase(l_creatorList[iii].name)) {
if (NULL==pointer) {
EWOL_INFO("Remove Creator of a specify widget : " << name);
} else {
@ -282,7 +282,7 @@ void ewol::widgetManager::AddWidgetCreator(const etk::UString& name, ewol::widge
ewol::Widget* ewol::widgetManager::Create(const etk::UString& name)
{
for (int32_t iii=0; iii<l_creatorList.Size() ; iii++) {
if (name == l_creatorList[iii].name) {
if (name.CompareNoCase(l_creatorList[iii].name)) {
if (NULL != l_creatorList[iii].pointer) {
return (*l_creatorList[iii].pointer)();
}
@ -295,7 +295,7 @@ ewol::Widget* ewol::widgetManager::Create(const etk::UString& name)
bool ewol::widgetManager::Exist(const etk::UString& name)
{
for (int32_t iii=0; iii<l_creatorList.Size() ; iii++) {
if (name == l_creatorList[iii].name) {
if (name.CompareNoCase(l_creatorList[iii].name)) {
return true;
}
}

View File

@ -65,6 +65,7 @@ FILE_LIST+= ewol/widget/Widget.cpp \
ewol/widget/ColorBar.cpp \
ewol/widget/ContextMenu.cpp \
ewol/widget/Composer.cpp \
ewol/widget/Container.cpp \
ewol/widget/Drawable.cpp \
ewol/widget/Entry.cpp \
ewol/widget/Joystick.cpp \