[DEV] rework of the ContainerN ended start rework of image widget

This commit is contained in:
Edouard DUPIN 2013-04-12 22:24:04 +02:00
parent 3ff3c38710
commit b46542ca8d
28 changed files with 672 additions and 679 deletions

View File

@ -69,6 +69,13 @@ float ewol::dimension::GetWindowsDiag(ewol::Dimension::distance_te type)
ewol::Dimension::Dimension(void) :
m_data(0,0),
m_type(ewol::Dimension::Pixel)
{
// notinh to do ...
}
ewol::Dimension::Dimension(const vec2& size, ewol::Dimension::distance_te type)
{
Set(size, type);

View File

@ -36,7 +36,19 @@ namespace ewol
vec2 m_data;
distance_te m_type;
public:
/**
* @brief Constructor (default :0,0 mode pixel)
*/
Dimension(void);
/**
* @brief Constructor
* @param[in] size Requested dimention
* @param[in] type Unit of the Dimention
*/
Dimension(const vec2& size, ewol::Dimension::distance_te type=ewol::Dimension::Pixel);
/**
* @brief Destructor
*/
~Dimension(void);
/**
* @brief Get the current dimention in requested type
@ -94,8 +106,14 @@ namespace ewol
* = assigment
*****************************************************/
const Dimension& operator= (const Dimension& obj ) {
m_data = obj.m_data;
m_type = obj.m_type;
if (this!=&obj) {
m_data = obj.m_data;
m_type = obj.m_type;
}
return *this;
}
const Dimension& operator= (const etk::UString& obj ) {
SetString(obj);
return *this;
}
/**

View File

@ -15,7 +15,7 @@
#undef __class__
#define __class__ "ewol::Image"
ewol::Image::Image(etk::UString imageName) :
ewol::Image::Image(const etk::UString& imageName) :
m_position(0.0, 0.0, 0.0),
m_clippingPosStart(0.0, 0.0, 0.0),
m_clippingPosStop(0.0, 0.0, 0.0),
@ -114,30 +114,30 @@ vec3 ewol::Image::GetPos(void)
}
void ewol::Image::SetPos(vec3 pos)
void ewol::Image::SetPos(const vec3& pos)
{
m_position = pos;
}
void ewol::Image::SetRelPos(vec3 pos)
void ewol::Image::SetRelPos(const vec3& pos)
{
m_position += pos;
}
void ewol::Image::SetColor(draw::Color color)
void ewol::Image::SetColor(const draw::Color& color)
{
m_color = color;
}
void ewol::Image::SetClippingWidth(vec3 pos, vec3 width)
void ewol::Image::SetClippingWidth(const vec3& pos, vec3 width)
{
SetClipping(pos, pos+width);
}
void ewol::Image::SetClipping(vec3 pos, vec3 posEnd)
void ewol::Image::SetClipping(const vec3& pos, vec3 posEnd)
{
// note the internal system all time request to have a bounding all time in the same order
if (pos.x() <= posEnd.x()) {
@ -171,7 +171,7 @@ void ewol::Image::SetClippingMode(bool newMode)
}
void ewol::Image::SetAngle(vec3 axes, float angle)
void ewol::Image::SetAngle(const vec3& axes, float angle)
{
m_axes = axes;
m_angle = angle;
@ -182,7 +182,12 @@ void ewol::Image::SetAngle(vec3 axes, float angle)
}
}
void ewol::Image::Print(ivec2 size)
void ewol::Image::Print(const ivec2& size)
{
Print(vec2(size.x(),size.y()));
}
void ewol::Image::Print(const vec2& size)
{
vec3 point(0,0,0);
vec2 tex(0,1);
@ -228,14 +233,19 @@ void ewol::Image::Print(ivec2 size)
m_coordColor.PushBack(m_color);
}
void ewol::Image::PrintPart(ivec2 size,
vec2 sourcePosStart,
vec2 sourcePosStop)
void ewol::Image::PrintPart(const ivec2& size,
const vec2& sourcePosStart,
const vec2& sourcePosStop)
{
}
void ewol::Image::SetSource(etk::UString newFile, int32_t size)
void ewol::Image::SetSource(const etk::UString& newFile, int32_t size)
{
SetSource(newFile, vec2(size,size));
}
void ewol::Image::SetSource(const etk::UString& newFile, const vec2& size)
{
Clear();
// remove old one
@ -243,7 +253,7 @@ void ewol::Image::SetSource(etk::UString newFile, int32_t size)
ewol::resource::Release(m_resource);
m_resource = NULL;
}
ivec2 tmpSize(size,size);
ivec2 tmpSize(size.x(),size.y());
// note that no image can be loaded...
if (newFile != "") {
// link to new One

View File

@ -48,7 +48,7 @@ namespace ewol
* @brief generic constructor
* @param[in] imageName Name of the file that might be loaded
*/
Image(etk::UString imageName="");
Image(const etk::UString& imageName="");
/**
* @brief generic destructor
*/
@ -71,29 +71,29 @@ namespace ewol
* @brief Set position for the next text writen
* @param[in] pos Position of the text (in 3D)
*/
void SetPos(vec3 pos);
void SetPos(const vec3& pos);
/**
* @brief Set relative position for the next text writen
* @param[in] pos ofset apply of the text (in 3D)
*/
void SetRelPos(vec3 pos);
void SetRelPos(const vec3& pos);
/**
* @brief Set the Color of the current foreground font
* @param[in] color Color to set on foreground (for next print)
*/
void SetColor(draw::Color color);
void SetColor(const draw::Color& color);
/**
* @brief Request a clipping area for the text (next draw only)
* @param[in] pos Start position of the clipping
* @param[in] width Width size of the clipping
*/
void SetClippingWidth(vec3 pos, vec3 width);
void SetClippingWidth(const vec3& pos, vec3 width);
/**
* @brief Request a clipping area for the text (next draw only)
* @param[in] pos Start position of the clipping
* @param[in] posEnd End position of the clipping
*/
void SetClipping(vec3 pos, vec3 posEnd);
void SetClipping(const vec3& pos, vec3 posEnd);
/**
* @brief Enable/Disable the clipping (without lose the current clipping position)
* @brief newMode The new status of the clipping
@ -104,27 +104,29 @@ namespace ewol
* @param[in] axes Rotation axes selection
* @param[in] angle Angle to set on this axes
*/
void SetAngle(vec3 axes, float angle);
void SetAngle(const vec3& axes, float angle);
/**
* @brief Add a compleate of the image to display with the requested size
* @param[in] size Size of the output image
*/
void Print(ivec2 size);
void Print(const ivec2& size);
void Print(const vec2& size);
/**
* @brief Add a part of the image to display with the requested size
* @param[in] size Size of the output image
* @param[in] sourcePosStart Start position in the image [0..1] (can be bigger but this repeate the image).
* @param[in] sourcePosStop Stop position in the image [0..1] (can be bigger but this repeate the image).
*/
void PrintPart(ivec2 size,
vec2 sourcePosStart,
vec2 sourcePosStop);
void PrintPart(const ivec2& size,
const vec2& sourcePosStart,
const vec2& sourcePosStop);
/**
* @brief Change the image Source ==> can not be done to display 2 images at the same time ...
* @param[in] newFile New file of the Image
* @param[in] size for the image when Verctorial image loading is requested
*/
void SetSource(etk::UString newFile, int32_t size=32);
void SetSource(const etk::UString& newFile, int32_t size=32);
void SetSource(const etk::UString& newFile, const vec2& size);
/**
* @brief Sometimes the user declare an image but not allocate the ressources all the time, this is to know it ..
* @return the validity od the resources.

View File

@ -137,13 +137,6 @@ void ewol::EObject::RemoveObject(void)
ewol::EObjectManager::AutoRemove(this);
}
int32_t ewol::EObject::GetId(void)
{
return m_uniqueId;
};
void ewol::EObject::AddEventId(const char * generateEventId)
{
if (NULL != generateEventId) {
@ -151,7 +144,6 @@ void ewol::EObject::AddEventId(const char * generateEventId)
}
}
void ewol::EObject::GenerateEventId(const char * generateEventId, const etk::UString& data)
{
// for every element registered ...
@ -167,19 +159,16 @@ void ewol::EObject::GenerateEventId(const char * generateEventId, const etk::USt
}
}
void ewol::EObject::SendMultiCast(const char* const messageId, const etk::UString& data)
{
MultiCastSend(this, messageId, data);
}
void ewol::EObject::RegisterMultiCast(const char* const messageId)
{
MultiCastAdd(this, messageId);
}
void ewol::EObject::RegisterOnEvent(ewol::EObject * destinationObject, const char * eventId, const char * eventIdgenerated)
{
if (NULL == destinationObject) {

View File

@ -56,7 +56,7 @@ namespace ewol {
* @brief Get the UniqueId of the EObject
* @return the requested ID
*/
int32_t GetId(void);
int32_t GetId(void){ return m_uniqueId; };
/**
* @brief Auto-destroy the object

View File

@ -96,38 +96,9 @@ bool widget::Composer::CommonLoadXML(const char* data)
EWOL_ERROR("(l ?) main node not find: \"composer\" ...");
return false;
}
// remove previous elements ...
RemoveSubWidget();
ewol::Widget::LoadXML(root);
// call upper class to parse his elements ...
widget::Container::LoadXML(root);
for(TiXmlNode * pNode = root->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;
}
if (NULL != GetSubWidget()) {
EWOL_ERROR("(l "<<pNode->Row()<<") " << __class__ << " Can only have one subWidget ??? node=\"" << widgetName << "\"" );
continue;
}
ewol::Widget* tmpWidget = ewol::widgetManager::Create(widgetName);
if (tmpWidget == NULL) {
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;
}
}
return true;
}

View File

@ -8,8 +8,7 @@
#include <ewol/ewol.h>
#include <ewol/widget/Composer.h>
#include <etk/os/FSNode.h>
#include <ewol/widget/Container.h>
#include <ewol/widget/WidgetManager.h>
@ -21,7 +20,7 @@ widget::Container::Container(ewol::Widget* subElement) :
widget::Container::~Container(void)
{
RemoveSubWidget();
SubWidgetRemove();
}
ewol::Widget* widget::Container::GetSubWidget(void)
@ -34,14 +33,14 @@ void widget::Container::SetSubWidget(ewol::Widget* newWidget)
if (NULL==newWidget) {
return;
}
RemoveSubWidget();
SubWidgetRemove();
m_subWidget = newWidget;
MarkToRedraw();
ewol::RequestUpdateSize();
}
void widget::Container::RemoveSubWidget(void)
void widget::Container::SubWidgetRemove(void)
{
if (NULL != m_subWidget) {
delete(m_subWidget);
@ -123,3 +122,46 @@ ewol::Widget* widget::Container::GetWidgetAtPos(const vec2& pos)
}
return NULL;
};
bool widget::Container::LoadXML(TiXmlNode* node)
{
if (NULL==node) {
return false;
}
// parse generic properties :
ewol::Widget::LoadXML(node);
// remove previous element :
SubWidgetRemove();
// 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;
}
if (NULL != GetSubWidget()) {
EWOL_ERROR("(l "<<pNode->Row()<<") " << __class__ << " Can only have one subWidget ??? node=\"" << widgetName << "\"" );
continue;
}
ewol::Widget* tmpWidget = ewol::widgetManager::Create(widgetName);
if (tmpWidget == NULL) {
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;
}
}
return true;
}

View File

@ -45,7 +45,7 @@ namespace widget
/**
* @brief Remove the subWidget node.
*/
void RemoveSubWidget(void);
void SubWidgetRemove(void);
protected: // Derived function
virtual void OnDraw(ewol::DrawProperty& displayProp);
@ -56,6 +56,8 @@ namespace widget
virtual void CalculateMinMaxSize(void);
virtual ewol::Widget* GetWidgetAtPos(const vec2& pos);
virtual ewol::Widget* GetWidgetNamed(const etk::UString& widgetName);
virtual const char * const GetObjectType(void) { return "Ewol::Container"; };
virtual bool LoadXML(TiXmlNode* node);
};
};

View File

@ -0,0 +1,296 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#include <ewol/ewol.h>
#include <ewol/widget/ContainerN.h>
#include <ewol/widget/WidgetManager.h>
widget::ContainerN::ContainerN(void) :
m_lockExpand(false,false),
m_subExpend(false,false)
{
// nothing to do ...
}
widget::ContainerN::~ContainerN(void)
{
SubWidgetRemoveAll();
}
bvec2 widget::ContainerN::CanExpand(void)
{
bvec2 res = m_userExpand;
if (false==m_lockExpand.x()) {
if (true==m_subExpend.x()) {
res.setX(true);
}
}
if (false==m_lockExpand.x()) {
if (true==m_subExpend.x()) {
res.setX(false);
}
}
return res;
}
void widget::ContainerN::LockExpand(const bvec2& lockExpand)
{
if (lockExpand != m_lockExpand) {
m_lockExpand = lockExpand;
MarkToRedraw();
ewol::RequestUpdateSize();
}
}
void widget::ContainerN::SubWidgetAdd(ewol::Widget* newWidget)
{
if (NULL == newWidget) {
EWOL_ERROR("[" << GetId() << "] Try to add An empty Widget ... ");
return;
}
m_subWidget.PushBack(newWidget);
MarkToRedraw();
ewol::RequestUpdateSize();
}
void widget::ContainerN::SubWidgetAddStart(ewol::Widget* newWidget)
{
if (NULL == newWidget) {
EWOL_ERROR("[" << GetId() << "] Try to add start An empty Widget ... ");
return;
}
m_subWidget.PushFront(newWidget);
MarkToRedraw();
ewol::RequestUpdateSize();
}
void widget::ContainerN::SubWidgetRemove(ewol::Widget* newWidget)
{
if (NULL == newWidget) {
return;
}
int32_t errorControl = m_subWidget.Size();
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
if (newWidget == m_subWidget[iii]) {
delete(m_subWidget[iii]);
// no remove, this element is removed with the function OnObjectRemove ==> it does not exist anymore ...
if (errorControl == m_subWidget.Size()) {
EWOL_CRITICAL("[" << GetId() << "] The number of element might have been reduced ... ==> it is not the case ==> the herited class must call the \"OnObjectRemove\" function...");
m_subWidget[iii] = NULL;
m_subWidget.Erase(iii);
}
MarkToRedraw();
ewol::RequestUpdateSize();
return;
}
}
}
void widget::ContainerN::SubWidgetUnLink(ewol::Widget* newWidget)
{
if (NULL == newWidget) {
return;
}
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
if (newWidget == m_subWidget[iii]) {
m_subWidget[iii] = NULL;
m_subWidget.Erase(iii);
MarkToRedraw();
ewol::RequestUpdateSize();
return;
}
}
}
void widget::ContainerN::SubWidgetRemoveAll(void)
{
int32_t errorControl = m_subWidget.Size();
// the size automaticly decrement with the auto call of the OnObjectRemove function
while (m_subWidget.Size() > 0 ) {
if (NULL != m_subWidget[0]) {
delete(m_subWidget[0]);
// no remove, this element is removed with the function OnObjectRemove ==> it does not exist anymore ...
if (errorControl == m_subWidget.Size()) {
EWOL_CRITICAL("[" << GetId() << "] The number of element might have been reduced ... ==> it is not the case ==> the herited class must call the \"OnObjectRemove\" function...");
m_subWidget[0] = NULL;
}
} else {
EWOL_WARNING("[" << GetId() << "] Must not have null pointer on the subWidget list ...");
m_subWidget.Erase(0);
}
errorControl = m_subWidget.Size();
}
m_subWidget.Clear();
}
ewol::Widget* widget::ContainerN::GetWidgetNamed(const etk::UString& widgetName)
{
if (GetName()==widgetName) {
return this;
}
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
if (NULL != m_subWidget[iii]) {
ewol::Widget* tmpWidget = m_subWidget[iii]->GetWidgetNamed(widgetName);
if (NULL != tmpWidget) {
return tmpWidget;
}
}
}
return NULL;
}
void widget::ContainerN::OnObjectRemove(ewol::EObject* removeObject)
{
// First step call parrent :
ewol::Widget::OnObjectRemove(removeObject);
// second step find if in all the elements ...
for(int32_t iii=m_subWidget.Size()-1; iii>=0; iii--) {
if(m_subWidget[iii] == removeObject) {
EWOL_VERBOSE("[" << GetId() << "]={" << GetObjectType() << "} Remove sizer sub Element [" << iii << "/" << m_subWidget.Size()-1 << "] ==> destroyed object");
m_subWidget[iii] = NULL;
m_subWidget.Erase(iii);
}
}
}
void widget::ContainerN::OnDraw(ewol::DrawProperty& displayProp)
{
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
if (NULL != m_subWidget[iii]) {
m_subWidget[iii]->GenDraw(displayProp);
}
}
}
void widget::ContainerN::CalculateSize(const vec2& availlable)
{
EWOL_DEBUG("Update Size ???");
m_size = availlable;
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
if (NULL != m_subWidget[iii]) {
m_subWidget[iii]->SetOrigin(m_origin);
m_subWidget[iii]->CalculateSize(m_size);
}
}
MarkToRedraw();
}
void widget::ContainerN::CalculateMinMaxSize(void)
{
m_subExpend.setValue(false, false);
m_minSize.setValue(0,0);
m_maxSize.setValue(ULTIMATE_MAX_SIZE,ULTIMATE_MAX_SIZE);
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
if (NULL != m_subWidget[iii]) {
m_subWidget[iii]->CalculateMinMaxSize();
bvec2 subExpendProp = m_subWidget[iii]->CanExpand();
if (true == subExpendProp.x()) {
m_subExpend.setX(true);
}
if (true == subExpendProp.y()) {
m_subExpend.setY(true);
}
vec2 tmpSize = m_subWidget[iii]->GetCalculateMinSize();
m_minSize.setValue( etk_max(tmpSize.x(), m_minSize.x()),
etk_max(tmpSize.y(), m_minSize.y()) );
}
}
}
void widget::ContainerN::OnRegenerateDisplay(void)
{
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
if (NULL != m_subWidget[iii]) {
m_subWidget[iii]->OnRegenerateDisplay();
}
}
}
ewol::Widget* widget::ContainerN::GetWidgetAtPos(const vec2& pos)
{
if (true == IsHide()) {
return NULL;
}
// for all element in the sizer ...
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
if (NULL != m_subWidget[iii]) {
vec2 tmpSize = m_subWidget[iii]->GetSize();
vec2 tmpOrigin = m_subWidget[iii]->GetOrigin();
if( (tmpOrigin.x() <= pos.x() && tmpOrigin.x() + tmpSize.x() >= pos.x())
&& (tmpOrigin.y() <= pos.y() && tmpOrigin.y() + tmpSize.y() >= pos.y()) )
{
ewol::Widget * tmpWidget = m_subWidget[iii]->GetWidgetAtPos(pos);
if (NULL != tmpWidget) {
return tmpWidget;
}
// stop searching
break;
}
}
}
return NULL;
};
bool widget::ContainerN::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) {
m_lockExpand = tmpAttributeValue;
}
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

@ -6,8 +6,8 @@
* @license BSD v3 (see license file)
*/
#ifndef __EWOL_WIDGET_CONTAINER_H__
#define __EWOL_WIDGET_CONTAINER_H__
#ifndef __EWOL_WIDGET_CONTAINER_N_H__
#define __EWOL_WIDGET_CONTAINER_N_H__
#include <etk/types.h>
#include <ewol/debug.h>
@ -20,35 +20,56 @@ namespace widget
*/
class ContainerN : public ewol::Widget
{
private:
int32_t m_limitElement;
etk::Vector<ewol::Widget*> m_subList;
protected:
etk::Vector<ewol::Widget*> m_subWidget;
public:
/**
* @brief Constructor
*/
ContainerN(int32_t limitElement=-1);
ContainerN(void);
/**
* @brief Destructor
*/
~ContainerN(void);
protected:
bvec2 m_lockExpand; //!< Lock the expend of the sub widget to this one ==> this permit to limit bigger subWidget
bvec2 m_subExpend; //!< reference of the sub element expention requested.
public:
/**
* @brief Get the main node widget
* @return the requested pointer on the node
* @brief Limit the expend properties to the current widget (no contamination)
* @param[in] lockExpend Lock mode of the expend properties
*/
ewol::Widget* GetSubWidget(int32_t id);
void LockExpand(const bvec2& lockExpand);
// herited function
bvec2 CanExpand(void);
public:
/**
* @brief Set the subWidget node widget.
* @param[in] newWidget The widget to Add.
* @brief Remove all sub element from the widget.
*/
void SubWidgetAdd(ewol::Widget* newWidget);
void SubWidgetAddStart(ewol::Widget* newWidget);
virtual void SubWidgetRemoveAll(void);
/**
* @brief Remove the subWidget node.
* @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
*/
void RemoveSubWidget(void);
virtual void SubWidgetAdd(ewol::Widget* newWidget);
inline void SubWidgetAddBack(ewol::Widget* newWidget) { SubWidgetAdd(newWidget); };
inline void SubWidgetAddEnd(ewol::Widget* newWidget) { SubWidgetAdd(newWidget); };
/**
* @brief Add at start position a Widget (note : This system use an inverted phylisophie (button to top, and left to right)
* @param[in] newWidget the element pointer
*/
virtual void SubWidgetAddStart(ewol::Widget* newWidget);
inline void SubWidgetAddFront(ewol::Widget* newWidget) { SubWidgetAddStart(newWidget); };
/**
* @brief Remove definitly a widget from the system and this layer.
* @param[in] newWidget the element pointer.
*/
virtual void SubWidgetRemove(ewol::Widget* newWidget);
/**
* @brief Just unlick the specify widget, this function does not remove it from the system (if you can, do nt use it ...)
* @param[in] newWidget the element pointer.
*/
virtual void SubWidgetUnLink(ewol::Widget* newWidget);
protected: // Derived function
virtual void OnDraw(ewol::DrawProperty& displayProp);
public:// Derived function
@ -58,6 +79,8 @@ namespace widget
virtual void CalculateMinMaxSize(void);
virtual ewol::Widget* GetWidgetAtPos(const vec2& pos);
virtual ewol::Widget* GetWidgetNamed(const etk::UString& widgetName);
virtual const char * const GetObjectType(void) { return "Ewol::ContainerN"; };
virtual bool LoadXML(TiXmlNode* node);
};
};

View File

@ -27,7 +27,7 @@ namespace widget {
*
* @code
* ----------------------------------------------
* | Mon Texte Modi|fiable |
* | Editable Text |
* ----------------------------------------------
* @endcode
*/

View File

@ -10,6 +10,7 @@
#include <ewol/compositing/Image.h>
#include <ewol/compositing/Drawing.h>
#include <ewol/widget/WidgetManager.h>
#include <ewol/ewol.h>
extern const char * const ewolEventImagePressed = "ewol-image-Pressed";
@ -33,99 +34,82 @@ void widget::Image::UnInit(void)
}
widget::Image::Image(const etk::UString& dataFile, int32_t size)
widget::Image::Image(const etk::UString& file, const ewol::Dimension& size, const ewol::Dimension& border)
{
m_imageSelected = dataFile;
AddEventId(ewolEventImagePressed);
#ifdef __TARGET_OS__Android
m_padding.setValue(12,12);
#else
m_padding.setValue(4,4);
#endif
m_textColorBg = draw::color::black;
m_textColorBg.a = 0x00;
m_imageSize = 32;
// Limit event at 1:
SetMouseLimit(1);
if (size>0) {
m_imageSize = size;
Set(file, border, size);
}
void widget::Image::SetFile(const etk::UString& file)
{
// copy data :
m_fileName = file;
// Force redraw all :
MarkToRedraw();
ewol::RequestUpdateSize();
m_compositing.SetSource(m_fileName, m_size);
}
void widget::Image::SetBorder(const ewol::Dimension& border)
{
// copy data :
m_border = border;
// Force redraw all :
MarkToRedraw();
ewol::RequestUpdateSize();
}
void widget::Image::SetSize(const ewol::Dimension& size)
{
// copy data :
m_imageSize = size;
// Force redraw all :
MarkToRedraw();
if (m_compositing.HasSources()) {
m_compositing.SetSource(m_fileName, m_size);
}
}
widget::Image::~Image(void)
void widget::Image::Set(const etk::UString& file, const ewol::Dimension& size, const ewol::Dimension& border)
{
}
void widget::Image::SetPadding(vec2 newPadding)
{
m_padding = newPadding;
}
void widget::Image::CalculateMinMaxSize(void)
{
m_minSize.setValue(m_padding.x()*2 + m_imageSize,
m_padding.y()*2 + m_imageSize );
// copy data :
m_border = border;
m_imageSize = size;
m_fileName = file;
// Force redraw all :
MarkToRedraw();
ewol::RequestUpdateSize();
m_compositing.SetSource(m_fileName, m_size);
}
void widget::Image::SetFile(etk::UString newFile)
void widget::Image::OnDraw(ewol::DrawProperty& displayProp)
{
m_imageSelected = newFile;
MarkToRedraw();
m_compositing.Draw();
}
void widget::Image::OnRegenerateDisplay(void)
{
if (true == NeedRedraw()) {
// clean the object list ...
ClearOObjectList();
int32_t tmpSizeX = m_minSize.x();
int32_t tmpSizeY = m_minSize.y();
int32_t tmpOriginX = (m_size.x() - m_minSize.x()) / 2;
int32_t tmpOriginY = (m_size.y() - m_minSize.y()) / 2;
if (true==m_userFill.x()) {
tmpSizeX = m_size.x();
tmpOriginX = 0;
}
if (true==m_userFill.y()) {
tmpSizeY = m_size.y();
tmpOriginY = 0;
}
tmpOriginX += m_padding.x();
tmpOriginY += m_padding.y();
tmpSizeX -= 2*m_padding.x();
tmpSizeY -= 2*m_padding.y();
ewol::Image * tmpImage = NULL;
tmpImage = new ewol::Image(m_imageSelected); // TODO : Check if it was possible later : , m_imageSize, m_imageSize);
tmpImage->SetPos(vec3(tmpOriginX, tmpOriginY, 0) );
tmpImage->Print(vec2(m_imageSize, m_imageSize));
ewol::Drawing * tmpDraw = new ewol::Drawing();
tmpDraw->SetColor(m_textColorBg);
tmpDraw->SetPos(vec3(tmpOriginX, tmpOriginY, 0) );
tmpDraw->RectangleWidth(vec3(tmpSizeX, tmpSizeY, 0) );
// add all needed objects ...
if (NULL != tmpDraw) {
AddOObject(tmpDraw);
}
if (NULL != tmpImage) {
AddOObject(tmpImage);
}
// remove data of the previous composition :
m_compositing.Clear();
// calculate the new position and size :
vec2 origin = m_origin + m_border.GetPixel();
// set the somposition properties :
m_compositing.SetPos(vec3(origin.x(), origin.y(), 0) );
m_compositing.Print(m_imageSize.GetPixel());
EWOL_DEBUG("Paint Image at : " << origin << " size=" << m_imageSize.GetPixel() << " border=" << m_border.GetPixel());
}
}
void widget::Image::CalculateMinMaxSize(void)
{
m_minSize = m_border.GetPixel()*2+m_imageSize.GetPixel();
m_maxSize = m_userMaxSize.GetPixel();
MarkToRedraw();
}
bool widget::Image::OnEventInput(ewol::keyEvent::type_te type, int32_t IdInput, ewol::keyEvent::status_te typeEvent, const vec2& pos)
{
//EWOL_DEBUG("Event on BT ...");
@ -138,3 +122,16 @@ bool widget::Image::OnEventInput(ewol::keyEvent::type_te type, int32_t IdInput,
return false;
}
bool widget::Image::LoadXML(TiXmlNode* node)
{
if (NULL==node) {
return false;
}
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

@ -12,32 +12,84 @@
#include <etk/types.h>
#include <ewol/debug.h>
#include <draw/Color.h>
#include <ewol/widget/Drawable.h>
#include <ewol/widget/Widget.h>
#include <ewol/compositing/Image.h>
extern const char * const ewolEventImagePressed;
namespace widget {
class Image :public widget::Drawable
class Image :public ewol::Widget
{
public:
/**
* @brief Main call of recording the widget on the List of "widget named creator"
*/
static void Init(void);
/**
* @brief Main call to unrecord the widget from the list of "widget named creator"
*/
static void UnInit(void);
protected:
ewol::Dimension m_border; //!< border to add at the image.
etk::UString m_fileName; //!< File name of the image.
ewol::Dimension m_imageSize; //!< requested image Size
ewol::Image m_compositing; //!< compositing element of the image.
public:
Image(const etk::UString& dataFile="", int32_t size=-1);
virtual ~Image(void);
void SetFile(etk::UString newFile);
void SetPadding(vec2 newPadding);
private:
etk::UString m_imageSelected;
vec2 m_padding;
draw::Color m_textColorBg; //!< Background color
int32_t m_imageSize;
/**
* @brief
*/
Image(const etk::UString& file="",
const ewol::Dimension& size=ewol::Dimension(vec2(10,10),ewol::Dimension::Centimeter),
const ewol::Dimension& border=ewol::Dimension(vec2(2,2),ewol::Dimension::Millimeter));
/**
* @brief
*/
virtual ~Image(void) { };
/**
* @brief Set the new filename
* @param[in] file Filaneme of the new image
*/
void SetFile(const etk::UString& file);
/**
* @brief Set tge Border size around the image
* @param[in] border New border size to set
*/
void SetBorder(const ewol::Dimension& border);
/**
* @brief Set the display size of the image (can be greater than the widget size (it will be clipped)
* @param[in] size new size of the display
*/
void SetSize(const ewol::Dimension& size);
/**
* @brief Set All the configuration of the current image
* @param[in] file Filaneme of the new image
* @param[in] border New border size to set
* @param[in] size new size of the display
*/
void Set(const etk::UString& file, const ewol::Dimension& border, const ewol::Dimension& size);
/**
* @brief Get the file displayed
* @return the filename of the image
*/
const etk::UString& GetFile() { return m_fileName; };
/**
* @brief Get the current border request at the image
* @return the border size
*/
const ewol::Dimension& GetBorder() { return m_border; };
/**
* @brief Get the current Image display size
* @return the size of the image
*/
const ewol::Dimension& GetImageSize() { return m_imageSize; };
public:
// Derived function
virtual const char * const GetObjectType(void) { return "Ewol::Image"; };
virtual void CalculateMinMaxSize(void);
virtual void OnRegenerateDisplay(void);
virtual void OnDraw(ewol::DrawProperty& displayProp);
virtual bool OnEventInput(ewol::keyEvent::type_te type, int32_t IdInput, ewol::keyEvent::status_te typeEvent, const vec2& pos);
virtual bool LoadXML(TiXmlNode* node);
};
};

View File

@ -12,11 +12,8 @@
#include <ewol/widget/WidgetManager.h>
#include <ewol/ewol.h>
extern const char * const ewolEventLabelPressed = "ewol Label Pressed";
#undef __class__
#define __class__ "Label"
@ -35,7 +32,6 @@ void widget::Label::UnInit(void)
ewol::widgetManager::AddWidgetCreator(__class__,NULL);
}
widget::Label::Label(etk::UString newLabel)
{
m_label = newLabel;
@ -43,11 +39,6 @@ widget::Label::Label(etk::UString newLabel)
SetCanHaveFocus(false);
}
widget::Label::~Label(void)
{
}
void widget::Label::CalculateMinMaxSize(void)
{
vec2 tmpMax = m_userMaxSize.GetPixel();
@ -60,7 +51,6 @@ void widget::Label::CalculateMinMaxSize(void)
m_minSize.setY(etk_min(4 + minSize.y(), tmpMax.y()));
}
void widget::Label::SetLabel(const etk::UString& newLabel)
{
m_label = newLabel;
@ -68,19 +58,16 @@ void widget::Label::SetLabel(const etk::UString& newLabel)
ewol::RequestUpdateSize();
}
etk::UString widget::Label::GetLabel(void)
{
return m_label;
}
void widget::Label::OnDraw(ewol::DrawProperty& displayProp)
{
m_text.Draw();
}
void widget::Label::OnRegenerateDisplay(void)
{
if (true == NeedRedraw()) {

View File

@ -20,10 +20,16 @@ namespace widget {
class Label : public ewol::Widget
{
public:
/**
* @brief Main call of recording the widget on the List of "widget named creator"
*/
static void Init(void);
/**
* @brief Main call to unrecord the widget from the list of "widget named creator"
*/
static void UnInit(void);
private:
ewol::Text m_text; //!< Compositing text element.
ewol::Text m_text; //!< Compositing text element.
etk::UString m_label; //!< decorated text to display.
public:
/**
@ -34,7 +40,7 @@ namespace widget {
/**
* @brief destructor
*/
virtual ~Label(void);
virtual ~Label(void) { };
/**
* @brief Change the label displayed
* @param[in] newLabel The displayed decorated text.

View File

@ -31,184 +31,11 @@ void widget::Layer::UnInit(void)
widget::Layer::Layer(void)
{
// set contamination enable
LockExpandContamination();
// nothing to do ...
}
widget::Layer::~Layer(void)
{
EWOL_DEBUG("[" << GetId() << "] Layer : destroy");
SubWidgetRemoveAll();
}
void widget::Layer::CalculateSize(const vec2& availlable)
{
//EWOL_DEBUG("Update Size");
m_size = availlable;
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
if (NULL != m_subWidget[iii]) {
m_subWidget[iii]->SetOrigin(m_origin);
m_subWidget[iii]->CalculateSize(m_size);
}
}
MarkToRedraw();
}
void widget::Layer::CalculateMinMaxSize(void)
{
m_userExpand.setValue(false, false);
m_minSize.setValue(0,0);
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
if (NULL != m_subWidget[iii]) {
m_subWidget[iii]->CalculateMinMaxSize();
if (true == m_subWidget[iii]->CanExpand().x()) {
m_userExpand.setX(true);
}
if (true == m_subWidget[iii]->CanExpand().y()) {
m_userExpand.setY(true);
}
vec2 tmpSize = m_subWidget[iii]->GetCalculateMinSize();
m_minSize.setValue( etk_max(tmpSize.x(), m_minSize.x()),
etk_max(tmpSize.y(), m_minSize.y()) );
}
}
}
void widget::Layer::SetMinSize(const vec2& size)
{
EWOL_ERROR("Layer can not have a user Minimum size (herited from under elements)");
}
bvec2 widget::Layer::CanExpand(void)
{
if (true == m_lockExpandContamination) {
return bvec2(false,false);
}
return m_userExpand;
}
void widget::Layer::LockExpandContamination(bool lockExpand)
{
m_lockExpandContamination = lockExpand;
}
//etk::Vector<ewol::Widget*> m_SubWidget;
void widget::Layer::SubWidgetRemoveAll(void)
{
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
delete(m_subWidget[iii]);
m_subWidget[iii] = NULL;
}
m_subWidget.Clear();
}
void widget::Layer::SubWidgetAdd(ewol::Widget* newWidget)
{
if (NULL == newWidget) {
return;
}
m_subWidget.PushBack(newWidget);
}
void widget::Layer::SubWidgetAddFront(ewol::Widget* newWidget)
{
if (NULL == newWidget) {
return;
}
m_subWidget.PushFront(newWidget);
}
void widget::Layer::SubWidgetRemove(ewol::Widget* newWidget)
{
if (NULL == newWidget) {
return;
}
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
if (newWidget == m_subWidget[iii]) {
delete(m_subWidget[iii]);
m_subWidget[iii] = NULL;
m_subWidget.Erase(iii);
return;
}
}
}
void widget::Layer::SubWidgetUnLink(ewol::Widget* newWidget)
{
if (NULL == newWidget) {
return;
}
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
if (newWidget == m_subWidget[iii]) {
m_subWidget[iii] = NULL;
m_subWidget.Erase(iii);
return;
}
}
}
void widget::Layer::OnDraw(ewol::DrawProperty& displayProp)
{
// draw is done in the invert sense of inserting ... the first element inserted is on the top and the last is on the buttom
for (int32_t iii=m_subWidget.Size()-1; iii>=0; iii--) {
if (NULL != m_subWidget[iii]) {
m_subWidget[iii]->GenDraw(displayProp);
}
}
}
void widget::Layer::OnRegenerateDisplay(void)
{
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
if (NULL != m_subWidget[iii]) {
m_subWidget[iii]->OnRegenerateDisplay();
}
}
}
ewol::Widget * widget::Layer::GetWidgetAtPos(const vec2& pos)
{
// for all element in the sizer ...
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
if (NULL != m_subWidget[iii]) {
vec2 tmpSize = m_subWidget[iii]->GetSize();
vec2 tmpOrigin = m_subWidget[iii]->GetOrigin();
if( (tmpOrigin.x() <= pos.x() && tmpOrigin.x() + tmpSize.x() >= pos.x())
&& (tmpOrigin.y() <= pos.y() && tmpOrigin.y() + tmpSize.y() >= pos.y()) )
{
ewol::Widget * tmpWidget = m_subWidget[iii]->GetWidgetAtPos(pos);
if (NULL != tmpWidget) {
return tmpWidget;
}
}
}
}
// otherwise the event go to this widget ...
return this;
}
void widget::Layer::OnObjectRemove(ewol::EObject * removeObject)
{
// First step call parrent :
ewol::Widget::OnObjectRemove(removeObject);
// second step find if in all the elements ...
for(int32_t iii=m_subWidget.Size()-1; iii>=0; iii--) {
if(m_subWidget[iii] == removeObject) {
EWOL_DEBUG("Remove layer sub Element [" << iii << "] ==> destroyed object");
m_subWidget[iii] = NULL;
m_subWidget.Erase(iii);
}
}
}

View File

@ -11,40 +11,31 @@
#include <etk/types.h>
#include <ewol/debug.h>
#include <ewol/widget/Widget.h>
#include <ewol/widget/ContainerN.h>
namespace widget {
class Layer :public ewol::Widget
class Layer : public widget::ContainerN
{
public:
/**
* @brief Main call of recording the widget on the List of "widget named creator"
*/
static void Init(void);
/**
* @brief Main call to unrecord the widget from the list of "widget named creator"
*/
static void UnInit(void);
public:
/**
* @brief Constructor
*/
Layer(void);
/**
* @brief Desstructor
*/
virtual ~Layer(void);
void LockExpandContamination(bool lockExpend=false);
private:
bool m_lockExpandContamination;
etk::Vector<ewol::Widget*> m_subWidget;
public:
virtual void SubWidgetRemoveAll(void);
virtual void SubWidgetAdd(ewol::Widget* newWidget);
virtual void SubWidgetAddFront(ewol::Widget* newWidget);
virtual void SubWidgetRemove(ewol::Widget* newWidget);
virtual void SubWidgetUnLink(ewol::Widget* newWidget);
protected:
// Derived function
virtual void OnDraw(ewol::DrawProperty& displayProp);
public:
// Derived function
virtual void OnRegenerateDisplay(void);
virtual ewol::Widget * GetWidgetAtPos(const vec2& pos);
virtual void OnObjectRemove(ewol::EObject * removeObject);
virtual void CalculateSize(const vec2& availlable);
virtual void CalculateMinMaxSize(void);
virtual void SetMinSize(const vec2& size);
virtual bvec2 CanExpand(void);
virtual const char * const GetObjectType(void) { return "EwolLayer"; };
virtual const char * const GetObjectType(void) { return "Ewol::Layer"; };
};
};

View File

@ -163,8 +163,9 @@ void widget::Menu::OnReceiveMessage(ewol::EObject * CallerObject, const char * e
widget::Sizer * mySizer = NULL;
widget::Button * myButton = NULL;
// TODO : Set a gird ...
mySizer = new widget::Sizer(widget::Sizer::modeVert);
mySizer->LockExpandContamination(vec2(true,true));
mySizer->LockExpand(vec2(true,true));
// set it in the pop-up-system :
m_widgetContextMenu->SubWidgetSet(mySizer);

View File

@ -32,30 +32,20 @@ void widget::Sizer::UnInit(void)
widget::Sizer::Sizer(widget::Sizer::displayMode_te mode):
m_mode(mode),
m_lockExpandContamination(false,false),
m_borderSize(0,0)
m_borderSize()
{
}
widget::Sizer::~Sizer(void)
{
EWOL_DEBUG("[" << GetId() << "]={" << GetObjectType() << "} Sizer : destroy (mode=" << (m_mode==widget::Sizer::modeVert?"Vert":"Hori") << ")");
SubWidgetRemoveAll();
//EWOL_DEBUG("[" << GetId() << "]={" << GetObjectType() << "} Sizer : destroy (mode=" << (m_mode==widget::Sizer::modeVert?"Vert":"Hori") << ")");
}
void widget::Sizer::SetBorderSize(const ivec2& newBorderSize)
void widget::Sizer::SetBorderSize(const ewol::Dimension& newBorderSize)
{
m_borderSize = newBorderSize;
if (m_borderSize.x() < 0) {
EWOL_ERROR("Try to set a border size <0 on x : " << m_borderSize.x() << " ==> restore to 0");
m_borderSize.setX(0);
}
if (m_borderSize.y() < 0) {
EWOL_ERROR("Try to set a border size <0 on y : " << m_borderSize.y() << " ==> restore to 0");
m_borderSize.setY(0);
}
MarkToRedraw();
ewol::RequestUpdateSize();
}
@ -74,9 +64,10 @@ widget::Sizer::displayMode_te widget::Sizer::GetMode(void)
void widget::Sizer::CalculateSize(const vec2& availlable)
{
//EWOL_DEBUG("Update Size");
vec2 tmpBorderSize = m_borderSize.GetPixel();
//EWOL_DEBUG("[" << GetId() << "] Update Size : " << availlable << " nbElement : " << m_subWidget.Size());
m_size = availlable;
m_size -= m_borderSize*2;
m_size -= tmpBorderSize*2;
// calculate unExpandable Size :
float unexpandableSize=0.0;
int32_t nbWidgetFixedSize=0;
@ -114,12 +105,12 @@ void widget::Sizer::CalculateSize(const vec2& availlable)
sizeToAddAtEveryOne=0;
}
}
vec2 tmpOrigin = m_origin + m_borderSize;
vec2 tmpOrigin = m_origin + tmpBorderSize;
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
if (NULL != m_subWidget[iii]) {
vec2 tmpSize = m_subWidget[iii]->GetCalculateMinSize();
// Set the origin :
//EWOL_DEBUG("Set ORIGIN : " << tmpOrigin.x << "," << tmpOrigin.y << ")");
//EWOL_DEBUG("[" << GetId() << "] Set ORIGIN : " << tmpOrigin);
m_subWidget[iii]->SetOrigin(tmpOrigin);
// Now Update his Size his size in X and the curent sizer size in Y:
if (m_mode==widget::Sizer::modeVert) {
@ -141,18 +132,19 @@ void widget::Sizer::CalculateSize(const vec2& availlable)
}
}
}
m_size += m_borderSize*2;
m_size += tmpBorderSize*2;
MarkToRedraw();
}
void widget::Sizer::CalculateMinMaxSize(void)
{
//EWOL_DEBUG("Update minimum Size");
//EWOL_DEBUG("[" << GetId() << "] Update minimum Size");
m_userExpand.setValue(false, false);
m_minSize = m_userMinSize.GetPixel();
vec2 tmpBorderSize = m_borderSize.GetPixel();
m_minSize += m_borderSize*2;
m_minSize += tmpBorderSize*2;
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
if (NULL != m_subWidget[iii]) {
m_subWidget[iii]->CalculateMinMaxSize();
@ -163,8 +155,8 @@ void widget::Sizer::CalculateMinMaxSize(void)
m_userExpand.setY(true);
}
vec2 tmpSize = m_subWidget[iii]->GetCalculateMinSize();
//EWOL_DEBUG("VERT : NewMinSize=" << tmpSize);
//EWOL_DEBUG(" Get minSize[" << iii << "] "<< tmpSize);
//EWOL_DEBUG("[" << GetId() << "] NewMinSize=" << tmpSize);
//EWOL_DEBUG("[" << GetId() << "] Get minSize[" << iii << "] "<< tmpSize);
if (m_mode==widget::Sizer::modeVert) {
m_minSize.setY(m_minSize.y() + tmpSize.y());
if (tmpSize.x()>m_minSize.x()) {
@ -180,190 +172,17 @@ void widget::Sizer::CalculateMinMaxSize(void)
}
}
void widget::Sizer::SetMinSize(const vec2& size)
{
EWOL_ERROR("[" << GetId() << "] Sizer can not have a user Minimum size (herited from under elements)");
}
void widget::Sizer::SetExpand(const bvec2& newExpand)
{
EWOL_ERROR("[" << GetId() << "] Sizer can not have a user expand settings (herited from under elements)");
}
bvec2 widget::Sizer::CanExpand(void)
{
bvec2 res = m_userExpand;
if (true == m_lockExpandContamination.x()) {
res.setX(false);
}
if (true == m_lockExpandContamination.y()) {
res.setY(false);
}
return res;
}
void widget::Sizer::LockExpandContamination(const bvec2& lockExpand)
{
m_lockExpandContamination = lockExpand;
}
void widget::Sizer::SubWidgetRemoveAll(void)
{
int32_t errorControl = m_subWidget.Size();
// the size automaticly decrement with the auto call of the OnObjectRemove function
while (m_subWidget.Size() > 0 ) {
if (NULL != m_subWidget[0]) {
delete(m_subWidget[0]);
// no remove, this element is removed with the function OnObjectRemove ==> it does not exist anymore ...
if (errorControl == m_subWidget.Size()) {
EWOL_CRITICAL("[" << GetId() << "] The number of element might have been reduced ... ==> it is not the case ==> the herited class must call the \"OnObjectRemove\" function...");
m_subWidget[0] = NULL;
}
} else {
EWOL_WARNING("[" << GetId() << "] Must not have null pointer on the subWidget list ...");
m_subWidget.Erase(0);
}
errorControl = m_subWidget.Size();
}
m_subWidget.Clear();
}
void widget::Sizer::SubWidgetAdd(ewol::Widget* newWidget)
{
if (NULL == newWidget) {
return;
}
m_subWidget.PushBack(newWidget);
}
void widget::Sizer::SubWidgetAddStart(ewol::Widget* newWidget)
{
if (NULL == newWidget) {
return;
}
m_subWidget.PushFront(newWidget);
}
void widget::Sizer::SubWidgetRemove(ewol::Widget* newWidget)
{
if (NULL == newWidget) {
return;
}
int32_t errorControl = m_subWidget.Size();
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
if (newWidget == m_subWidget[iii]) {
delete(m_subWidget[iii]);
// no remove, this element is removed with the function OnObjectRemove ==> it does not exist anymore ...
if (errorControl == m_subWidget.Size()) {
EWOL_CRITICAL("[" << GetId() << "] The number of element might have been reduced ... ==> it is not the case ==> the herited class must call the \"OnObjectRemove\" function...");
m_subWidget[iii] = NULL;
m_subWidget.Erase(iii);
}
return;
}
}
}
void widget::Sizer::SubWidgetUnLink(ewol::Widget* newWidget)
{
if (NULL == newWidget) {
return;
}
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
if (newWidget == m_subWidget[iii]) {
m_subWidget[iii] = NULL;
m_subWidget.Erase(iii);
return;
}
}
}
void widget::Sizer::OnDraw(ewol::DrawProperty& displayProp)
{
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
if (NULL != m_subWidget[iii]) {
m_subWidget[iii]->GenDraw(displayProp);
}
}
}
void widget::Sizer::OnRegenerateDisplay(void)
{
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
if (NULL != m_subWidget[iii]) {
m_subWidget[iii]->OnRegenerateDisplay();
}
}
}
ewol::Widget * widget::Sizer::GetWidgetAtPos(const vec2& pos)
{
if (true == IsHide()) {
return NULL;
}
// for all element in the sizer ...
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
if (NULL != m_subWidget[iii]) {
vec2 tmpSize = m_subWidget[iii]->GetSize();
vec2 tmpOrigin = m_subWidget[iii]->GetOrigin();
if( (tmpOrigin.x() <= pos.x() && tmpOrigin.x() + tmpSize.x() >= pos.x())
&& (tmpOrigin.y() <= pos.y() && tmpOrigin.y() + tmpSize.y() >= pos.y()) )
{
ewol::Widget * tmpWidget = m_subWidget[iii]->GetWidgetAtPos(pos);
if (NULL != tmpWidget) {
return tmpWidget;
}
// stop searching
break;
}
}
}
// TODO : Check if we have a mover, otherwire return NULL;
return NULL;
//return this;
}
void widget::Sizer::OnObjectRemove(ewol::EObject * removeObject)
{
// First step call parrent :
ewol::Widget::OnObjectRemove(removeObject);
// second step find if in all the elements ...
for(int32_t iii=m_subWidget.Size()-1; iii>=0; iii--) {
if(m_subWidget[iii] == removeObject) {
EWOL_VERBOSE("[" << GetId() << "]={" << GetObjectType() << "} Remove sizer sub Element [" << iii << "/" << m_subWidget.Size()-1 << "] ==> destroyed object");
m_subWidget[iii] = NULL;
m_subWidget.Erase(iii);
}
}
}
bool widget::Sizer::LoadXML(TiXmlNode* node)
{
if (NULL==node) {
return false;
}
// parse generic properties :
ewol::Widget::LoadXML(node);
// remove previous element :
SubWidgetRemoveAll();
widget::ContainerN::LoadXML(node);
const char *tmpAttributeValue = node->ToElement()->Attribute("lock");
const char* tmpAttributeValue = node->ToElement()->Attribute("borderSize");
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;
m_borderSize = tmpAttributeValue;
}
tmpAttributeValue = node->ToElement()->Attribute("mode");
if (NULL != tmpAttributeValue) {
@ -375,42 +194,5 @@ bool widget::Sizer::LoadXML(TiXmlNode* node)
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

@ -11,13 +11,19 @@
#include <etk/types.h>
#include <ewol/debug.h>
#include <ewol/widget/Widget.h>
#include <ewol/widget/ContainerN.h>
namespace widget {
class Sizer :public ewol::Widget
class Sizer : public widget::ContainerN
{
public:
/**
* @brief Main call of recording the widget on the List of "widget named creator"
*/
static void Init(void);
/**
* @brief Main call to unrecord the widget from the list of "widget named creator"
*/
static void UnInit(void);
public:
typedef enum {
@ -25,7 +31,6 @@ namespace widget {
modeHori, //!< Horizontal mode
} displayMode_te;
private:
etk::Vector<ewol::Widget*> m_subWidget; //!< all sub widget are contained in this element
displayMode_te m_mode; //!< Methode to display the widget list (vert/hory ...)
public:
/**
@ -48,63 +53,22 @@ namespace widget {
*/
displayMode_te GetMode(void);
private:
bvec2 m_lockExpandContamination; //!< If some sub-widget request the expand==> this permit to unpropagate the problem
public:
/**
* @brief Change state of the expand contatmination (if some sub-widget request the expent this permit to not propagate if at this widget)
* @param[in] lockExpand New expand state in vertical and horisantal
*/
void LockExpandContamination(const bvec2& lockExpand);
public:
/**
* @brief Remove all sub element from the widget.
*/
virtual void SubWidgetRemoveAll(void);
/**
* @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
*/
virtual void SubWidgetAdd(ewol::Widget* newWidget);
/**
* @brief Add at start position a Widget (note : This system use an inverted phylisophie (button to top, and left to right)
* @param[in] newWidget the element pointer
*/
virtual void SubWidgetAddStart(ewol::Widget* newWidget);
/**
* @brief Remove definitly a widget from the system and this layer.
* @param[in] newWidget the element pointer.
*/
virtual void SubWidgetRemove(ewol::Widget* newWidget);
/**
* @brief Just unlick the specify widget, this function does not remove it from the system (if you can, do nt use it ...)
* @param[in] newWidget the element pointer.
*/
virtual void SubWidgetUnLink(ewol::Widget* newWidget);
private:
ivec2 m_borderSize; //!< Border size needed for all the display
ewol::Dimension m_borderSize; //!< Border size needed for all the display
public:
/**
* @brief Set the current border size of the current element:
* @param[in] newBorderSize The border size to set (0 if not used)
*/
void SetBorderSize(const ivec2& newBorderSize);
void SetBorderSize(const ewol::Dimension& newBorderSize);
/**
* @brief Get the current border size of the current element:
* @return the border size (0 if not used)
*/
const ivec2& GetBorderSize(void) { return m_borderSize; };
protected: // Derived function
virtual void OnDraw(ewol::DrawProperty& displayProp);
const ewol::Dimension& GetBorderSize(void) { return m_borderSize; };
public: // Derived function
virtual void OnRegenerateDisplay(void);
virtual ewol::Widget* GetWidgetAtPos(const vec2& pos);
virtual void OnObjectRemove(ewol::EObject* removeObject);
virtual const char * const GetObjectType(void) { return "Ewol::Sizer"; };
virtual void CalculateSize(const vec2& availlable);
virtual void CalculateMinMaxSize(void);
virtual void SetMinSize(const vec2& size);
virtual void SetExpand(const bvec2& newExpand);
virtual bvec2 CanExpand(void);
virtual bool LoadXML(TiXmlNode* node);
};

View File

@ -14,7 +14,6 @@
#include <ewol/renderer/os/eSystem.h>
#include <ewol/renderer/os/gui.h>
#define ULTIMATE_MAX_SIZE (99999999)
#undef __class__
#define __class__ "Widget"

View File

@ -24,6 +24,8 @@ namespace ewol {
#include <ewol/key.h>
#include <ewol/cursor.h>
#define ULTIMATE_MAX_SIZE (99999999)
namespace ewol {
class DrawProperty{

View File

@ -44,7 +44,7 @@ widget::ColorChooser::ColorChooser(void) :
m_widgetBlue = NULL;
m_widgetAlpha = NULL;
LockExpandContamination(bvec2(true,true));
LockExpand(bvec2(true,true));
m_widgetColorBar = new widget::ColorBar();
m_widgetColorBar->RegisterOnEvent(this, ewolEventColorBarChange, eventColorBarHasChange);
m_widgetColorBar->SetFill(bvec2(true,true));

View File

@ -81,7 +81,7 @@ widget::FileChooser::FileChooser(void)
if (NULL == mySizerVert) {
EWOL_ERROR("Can not allocate widget ==> display might be in error");
} else {
mySizerVert->LockExpandContamination(bvec2(true,true));
mySizerVert->LockExpand(bvec2(true,true));
// set it in the pop-up-system :
SubWidgetSet(mySizerVert);

View File

@ -48,7 +48,7 @@ widget::Parameter::Parameter(void) :
EWOL_ERROR("Can not allocate widget ==> display might be in error");
} else {
EWOL_INFO("add widget");
mySizerVert->LockExpandContamination(bvec2(true,true));
mySizerVert->LockExpand(bvec2(true,true));
// set it in the pop-up-system :
SubWidgetSet(mySizerVert);

View File

@ -1,6 +1,30 @@
I need to organize widget by style (Like GTK):
ewol::EObject [OK]
.
/|\
|
ewol::Widget [OK]
.
/|\
|== widget::Windows [ TOEND ]
|
|== widget::Container [OK]
| .
| /|\
| |== widget::Button [OK]
| |
| \== widget::Composer [OK]
|
|== widget::ContainerN [OK]
| .
| /|\
| |== widget::Layer [OK]
| |
| \== widget::Sizer [OK]
ewol::EObject
ewol::Widget
## Windows :

View File

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