[DEV] generate warning when delete in an error state and rework pop-up and contextmenu

This commit is contained in:
Edouard DUPIN 2013-04-15 21:18:54 +02:00
parent 3e29816651
commit 87676f657a
20 changed files with 202 additions and 335 deletions

View File

@ -111,11 +111,16 @@ vec2 ewol::Dimension::Get(ewol::Dimension::distance_te type) const
void ewol::Dimension::Set(const vec2& _size, ewol::Dimension::distance_te type) void ewol::Dimension::Set(const vec2& _size, ewol::Dimension::distance_te type)
{ {
// Set min max on input to limit error : // Set min max on input to limit error :
vec2 size(etk_avg(0,_size.x(),999999999999999.0), vec2 size(etk_avg(0.0f,_size.x(),9999999.0f),
etk_avg(0,_size.y(),999999999999999.0)); etk_avg(0.0f,_size.y(),9999999.0f));
switch(type) { switch(type) {
case ewol::Dimension::Pourcent: case ewol::Dimension::Pourcent:
m_data = vec2(size.x()*0.01f, size.y()*0.01f); {
vec2 size2(etk_avg(0.0f,_size.x(),100.0f),
etk_avg(0.0f,_size.y(),100.0f));
m_data = vec2(size2.x()*0.01f, size2.y()*0.01f);
//EWOL_VERBOSE("Set % : " << size2 << " ==> " << m_data);
}
break; break;
case ewol::Dimension::Pixel: case ewol::Dimension::Pixel:
m_data = size; m_data = size;
@ -148,7 +153,9 @@ vec2 ewol::Dimension::GetPixel(void) const
return m_data; return m_data;
} else { } else {
vec2 windDim = windowsSize.GetPixel(); vec2 windDim = windowsSize.GetPixel();
return vec2(windDim.x()*m_data.x(), windDim.y()*m_data.y()); vec2 res = vec2(windDim.x()*m_data.x(), windDim.y()*m_data.y());
//EWOL_DEBUG("Get % : " << m_data << " / " << windDim << "==> " << res);
return res;
} }
} }

View File

@ -447,7 +447,7 @@ void ewol::Drawing::LineTo(vec3 dest)
{ {
ResetCount(); ResetCount();
InternalSetColor(m_color); InternalSetColor(m_color);
EWOL_DEBUG("DrawLine : " << m_position << " to " << dest); //EWOL_DEBUG("DrawLine : " << m_position << " to " << dest);
if (m_position.x() == dest.x() && m_position.y() == dest.y() && m_position.z() == dest.z()) { if (m_position.x() == dest.x() && m_position.y() == dest.y() && m_position.z() == dest.z()) {
EWOL_WARNING("Try to draw an line width 0"); EWOL_WARNING("Try to draw an line width 0");
return; return;

View File

@ -146,6 +146,7 @@ void ewol::EObject::AddEventId(const char * generateEventId)
void ewol::EObject::GenerateEventId(const char * generateEventId, const etk::UString& data) void ewol::EObject::GenerateEventId(const char * generateEventId, const etk::UString& data)
{ {
int32_t nbObject = ewol::EObjectManager::GetNumberObject();
// for every element registered ... // for every element registered ...
for (int32_t iii=0; iii<m_externEvent.Size(); iii++) { for (int32_t iii=0; iii<m_externEvent.Size(); iii++) {
if (NULL!=m_externEvent[iii]) { if (NULL!=m_externEvent[iii]) {
@ -157,11 +158,18 @@ void ewol::EObject::GenerateEventId(const char * generateEventId, const etk::USt
} }
} }
} }
if (nbObject > ewol::EObjectManager::GetNumberObject()) {
EWOL_CRITICAL("It if really dangerous ro remove (delete) element inside a callback ... use ->RemoveObject() which is asynchronous");
}
} }
void ewol::EObject::SendMultiCast(const char* const messageId, const etk::UString& data) void ewol::EObject::SendMultiCast(const char* const messageId, const etk::UString& data)
{ {
int32_t nbObject = ewol::EObjectManager::GetNumberObject();
MultiCastSend(this, messageId, data); MultiCastSend(this, messageId, data);
if (nbObject > ewol::EObjectManager::GetNumberObject()) {
EWOL_CRITICAL("It if really dangerous ro remove (delete) element inside a callback ... use ->RemoveObject() which is asynchronous");
}
} }
void ewol::EObject::RegisterMultiCast(const char* const messageId) void ewol::EObject::RegisterMultiCast(const char* const messageId)

View File

@ -20,6 +20,7 @@ static etk::Vector<ewol::EObject*> m_eObjectList; // all widget al
static etk::Vector<ewol::EObject*> m_eObjectAutoRemoveList; // all widget allocated static etk::Vector<ewol::EObject*> m_eObjectAutoRemoveList; // all widget allocated
void ewol::EObjectManager::Init(void) void ewol::EObjectManager::Init(void)
{ {
EWOL_DEBUG("==> Init EObject-Manager"); EWOL_DEBUG("==> Init EObject-Manager");
@ -56,6 +57,11 @@ void ewol::EObjectManager::Add(ewol::EObject* object)
} }
} }
int32_t ewol::EObjectManager::GetNumberObject(void)
{
return m_eObjectList.Size() + m_eObjectAutoRemoveList.Size();
}
void informOneObjectIsRemoved(ewol::EObject* object) void informOneObjectIsRemoved(ewol::EObject* object)
{ {
for (int32_t iii=0; iii<m_eObjectList.Size(); iii++) { for (int32_t iii=0; iii<m_eObjectList.Size(); iii++) {

View File

@ -14,12 +14,13 @@
namespace ewol { namespace ewol {
namespace EObjectManager { namespace EObjectManager {
void Init( void); void Init(void);
void UnInit( void); void UnInit(void);
void Add( ewol::EObject* object); void Add(ewol::EObject* object);
void Rm( ewol::EObject* object); void Rm(ewol::EObject* object);
int32_t GetNumberObject(void);
void AutoRemove( ewol::EObject* object); void AutoRemove(ewol::EObject* object);
void RemoveAllAutoRemove(void); void RemoveAllAutoRemove(void);
}; };
}; };

View File

@ -201,7 +201,7 @@ bool widget::ButtonColor::OnEventInput(ewol::keyEvent::type_te type, int32_t IdI
widget::ColorChooser * myColorChooser = new widget::ColorChooser(); widget::ColorChooser * myColorChooser = new widget::ColorChooser();
myColorChooser->SetColor(m_textColorFg); myColorChooser->SetColor(m_textColorFg);
// set it in the pop-up-system : // set it in the pop-up-system :
m_widgetContextMenu->SubWidgetSet(myColorChooser); m_widgetContextMenu->SetSubWidget(myColorChooser);
myColorChooser->RegisterOnEvent(this, ewolEventColorChooserChange, ewolEventColorChooserChange); myColorChooser->RegisterOnEvent(this, ewolEventColorChooserChange, ewolEventColorChooserChange);
ewol::WindowsPopUpAdd(m_widgetContextMenu); ewol::WindowsPopUpAdd(m_widgetContextMenu);
MarkToRedraw(); MarkToRedraw();

View File

@ -20,7 +20,7 @@ namespace widget
*/ */
class Container : public ewol::Widget class Container : public ewol::Widget
{ {
private: protected:
ewol::Widget* m_subWidget; ewol::Widget* m_subWidget;
public: public:
/** /**

View File

@ -164,7 +164,7 @@ void widget::ContainerN::OnObjectRemove(ewol::EObject* removeObject)
void widget::ContainerN::OnDraw(ewol::DrawProperty& displayProp) void widget::ContainerN::OnDraw(ewol::DrawProperty& displayProp)
{ {
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) { for (int32_t iii=m_subWidget.Size()-1; iii>=0; iii--) {
if (NULL != m_subWidget[iii]) { if (NULL != m_subWidget[iii]) {
m_subWidget[iii]->GenDraw(displayProp); m_subWidget[iii]->GenDraw(displayProp);
} }

View File

@ -16,7 +16,7 @@
widget::ContextMenu::ContextMenu(void) widget::ContextMenu::ContextMenu(void)
{ {
m_userExpand.setValue(true,true); m_userExpand.setValue(false,false);
m_padding.setValue(4,4); m_padding.setValue(4,4);
m_offset = 20; m_offset = 20;
@ -33,7 +33,7 @@ widget::ContextMenu::ContextMenu(void)
widget::ContextMenu::~ContextMenu(void) widget::ContextMenu::~ContextMenu(void)
{ {
SubWidgetRemove();
} }
@ -107,49 +107,21 @@ void widget::ContextMenu::CalculateSize(const vec2& availlable)
void widget::ContextMenu::CalculateMinMaxSize(void) void widget::ContextMenu::CalculateMinMaxSize(void)
{ {
EWOL_DEBUG("CalculateMinSize"); //EWOL_DEBUG("CalculateMinSize");
m_userExpand.setValue(false,false); m_userExpand.setValue(false,false);
m_minSize.setValue(50,50); m_minSize.setValue(50,50);
if (NULL != m_subWidget) { if (NULL != m_subWidget) {
m_subWidget->CalculateMinMaxSize(); m_subWidget->CalculateMinMaxSize();
m_minSize = m_subWidget->GetCalculateMinSize(); m_minSize = m_subWidget->GetCalculateMinSize();
} }
EWOL_DEBUG("CalculateMinSize=>>" << m_minSize); //EWOL_DEBUG("CalculateMinSize=>>" << m_minSize);
MarkToRedraw(); MarkToRedraw();
} }
void widget::ContextMenu::SetMinSize(const vec2& size)
{
EWOL_ERROR("Pop-up can not have a user Minimum size (herited from under elements)");
}
void widget::ContextMenu::SetExpand(const bvec2& newExpand)
{
EWOL_ERROR("Pop-up can not have a user expand settings X (herited from under elements)");
}
void widget::ContextMenu::SubWidgetSet(ewol::Widget* newWidget)
{
if (NULL == newWidget) {
return;
}
m_subWidget = newWidget;
}
void widget::ContextMenu::SubWidgetRemove(void)
{
if (NULL != m_subWidget) {
delete(m_subWidget);
m_subWidget = NULL;
}
}
void widget::ContextMenu::OnDraw(ewol::DrawProperty& displayProp) void widget::ContextMenu::OnDraw(ewol::DrawProperty& displayProp)
{ {
//EWOL_DEBUG("On Draw " << m_currentDrawId); //EWOL_DEBUG("On Draw " << m_currentDrawId);
widget::Drawable::OnDraw(displayProp); m_compositing.Draw();
if (NULL != m_subWidget) { if (NULL != m_subWidget) {
m_subWidget->GenDraw(displayProp); m_subWidget->GenDraw(displayProp);
} }
@ -159,91 +131,68 @@ void widget::ContextMenu::OnDraw(ewol::DrawProperty& displayProp)
void widget::ContextMenu::OnRegenerateDisplay(void) void widget::ContextMenu::OnRegenerateDisplay(void)
{ {
if (true == NeedRedraw()) { if (true == NeedRedraw()) {
} m_compositing.Clear();
// generate a white background and take gray on other surfaces if (NULL != m_subWidget) {
ClearOObjectList(); vec2 tmpSize = m_subWidget->GetSize();
ewol::Drawing * BGOObjects = new ewol::Drawing(); vec2 tmpOrigin = m_subWidget->GetOrigin();
AddOObject(BGOObjects);
if (NULL != m_subWidget) { // display border ...
vec2 tmpSize = m_subWidget->GetSize(); m_compositing.SetColor(m_colorBorder);
vec2 tmpOrigin = m_subWidget->GetOrigin(); switch (m_arrawBorder)
{
// display border ... case widget::CONTEXT_MENU_MARK_TOP:
BGOObjects->SetColor(m_colorBorder); m_compositing.SetPos(vec3(m_arrowPos.x(), m_arrowPos.y(), 0.0f) );
switch (m_arrawBorder) m_compositing.AddVertex();
{ if (m_arrowPos.x() <= tmpOrigin.x() ) {
case widget::CONTEXT_MENU_MARK_TOP: float laking = m_offset - m_padding.y();
BGOObjects->SetPos(vec3(m_arrowPos.x(), m_arrowPos.y(), 0.0f) ); m_compositing.SetPos(vec3(m_arrowPos.x()+laking, m_arrowPos.y()-laking, 0.0f) );
BGOObjects->AddVertex(); m_compositing.AddVertex();
if (m_arrowPos.x() <= tmpOrigin.x() ) { m_compositing.SetPos(vec3(m_arrowPos.x(), m_arrowPos.y()-laking, 0.0f) );
float laking = m_offset - m_padding.y(); m_compositing.AddVertex();
BGOObjects->SetPos(vec3(m_arrowPos.x()+laking, m_arrowPos.y()-laking, 0.0f) ); } else {
BGOObjects->AddVertex(); float laking = m_offset - m_padding.y();
BGOObjects->SetPos(vec3(m_arrowPos.x(), m_arrowPos.y()-laking, 0.0f) ); m_compositing.SetPos(vec3(m_arrowPos.x()+laking, m_arrowPos.y()-laking, 0.0f) );
BGOObjects->AddVertex(); m_compositing.AddVertex();
} else { m_compositing.SetPos(vec3(m_arrowPos.x()-laking, m_arrowPos.y()-laking, 0.0f) );
float laking = m_offset - m_padding.y(); m_compositing.AddVertex();
BGOObjects->SetPos(vec3(m_arrowPos.x()+laking, m_arrowPos.y()-laking, 0.0f) ); }
BGOObjects->AddVertex(); break;
BGOObjects->SetPos(vec3(m_arrowPos.x()-laking, m_arrowPos.y()-laking, 0.0f) ); case widget::CONTEXT_MENU_MARK_BOTTOM:
BGOObjects->AddVertex(); m_compositing.SetPos(vec3(m_arrowPos.x(), m_arrowPos.y(), 0) );
} m_compositing.AddVertex();
break; if (m_arrowPos.x() <= tmpOrigin.x() ) {
case widget::CONTEXT_MENU_MARK_BOTTOM: int32_t laking = m_offset - m_padding.y();
BGOObjects->SetPos(vec3(m_arrowPos.x(), m_arrowPos.y(), 0) ); m_compositing.SetPos(vec3(m_arrowPos.x()+laking, m_arrowPos.y()+laking, 0.0f) );
BGOObjects->AddVertex(); m_compositing.AddVertex();
if (m_arrowPos.x() <= tmpOrigin.x() ) { m_compositing.SetPos(vec3(m_arrowPos.x(), m_arrowPos.y()+laking, 0.0f) );
int32_t laking = m_offset - m_padding.y(); m_compositing.AddVertex();
BGOObjects->SetPos(vec3(m_arrowPos.x()+laking, m_arrowPos.y()+laking, 0.0f) ); } else {
BGOObjects->AddVertex(); int32_t laking = m_offset - m_padding.y();
BGOObjects->SetPos(vec3(m_arrowPos.x(), m_arrowPos.y()+laking, 0.0f) ); m_compositing.SetPos(vec3(m_arrowPos.x()+laking, m_arrowPos.y()+laking, 0.0f) );
BGOObjects->AddVertex(); m_compositing.AddVertex();
} else { m_compositing.SetPos(vec3(m_arrowPos.x()-laking, m_arrowPos.y()+laking, 0.0f) );
int32_t laking = m_offset - m_padding.y(); m_compositing.AddVertex();
BGOObjects->SetPos(vec3(m_arrowPos.x()+laking, m_arrowPos.y()+laking, 0.0f) ); }
BGOObjects->AddVertex(); break;
BGOObjects->SetPos(vec3(m_arrowPos.x()-laking, m_arrowPos.y()+laking, 0.0f) ); default:
BGOObjects->AddVertex(); case widget::CONTEXT_MENU_MARK_RIGHT:
} case widget::CONTEXT_MENU_MARK_LEFT:
break; EWOL_TODO("later");
default: break;
case widget::CONTEXT_MENU_MARK_RIGHT: }
case widget::CONTEXT_MENU_MARK_LEFT: m_compositing.SetPos(vec3(tmpOrigin.x()-m_padding.x(), tmpOrigin.y() - m_padding.y(), 0.0f) );
EWOL_TODO("later"); m_compositing.RectangleWidth(vec3(tmpSize.x() + m_padding.x()*2, tmpSize.y() + m_padding.y()*2, 0.0f) );
break; // set the area in white ...
m_compositing.SetColor(m_colorBackGroung);
m_compositing.SetPos(vec3(tmpOrigin.x(), tmpOrigin.y(), 0.0f) );
m_compositing.RectangleWidth(vec3(tmpSize.x(), tmpSize.y(), 0.0f) );
} }
BGOObjects->SetPos(vec3(tmpOrigin.x()-m_padding.x(), tmpOrigin.y() - m_padding.y(), 0.0f) );
BGOObjects->RectangleWidth(vec3(tmpSize.x() + m_padding.x()*2, tmpSize.y() + m_padding.y()*2, 0.0f) );
// set the area in white ...
BGOObjects->SetColor(m_colorBackGroung);
BGOObjects->SetPos(vec3(tmpOrigin.x(), tmpOrigin.y(), 0.0f) );
BGOObjects->RectangleWidth(vec3(tmpSize.x(), tmpSize.y(), 0.0f) );
} }
if (NULL != m_subWidget) { if (NULL != m_subWidget) {
m_subWidget->OnRegenerateDisplay(); m_subWidget->OnRegenerateDisplay();
} }
} }
ewol::Widget * widget::ContextMenu::GetWidgetAtPos(const vec2& pos)
{
// calculate relative position
vec2 relativePos = RelativePosition(pos);
// Check for sub Element
if (NULL != m_subWidget) {
vec2 tmpSize = m_subWidget->GetSize();
vec2 tmpOrigin = m_subWidget->GetOrigin();
if( (tmpOrigin.x() <= relativePos.x() && tmpOrigin.x() + tmpSize.x() >= relativePos.x())
&& (tmpOrigin.y() <= relativePos.y() && tmpOrigin.y() + tmpSize.y() >= relativePos.y()) )
{
return m_subWidget->GetWidgetAtPos(pos);
}
}
return this;
}
bool widget::ContextMenu::OnEventInput(ewol::keyEvent::type_te type, int32_t IdInput, ewol::keyEvent::status_te typeEvent, const vec2& pos) bool widget::ContextMenu::OnEventInput(ewol::keyEvent::type_te type, int32_t IdInput, ewol::keyEvent::status_te typeEvent, const vec2& pos)
{ {
//EWOL_INFO("Event ouside the context menu"); //EWOL_INFO("Event ouside the context menu");
@ -271,3 +220,11 @@ void widget::ContextMenu::SetPositionMark(markPosition_te position, vec2 arrowPo
MarkToRedraw(); MarkToRedraw();
} }
ewol::Widget* widget::ContextMenu::GetWidgetAtPos(const vec2& pos)
{
ewol::Widget* val = widget::Container::GetWidgetAtPos(pos);
if (NULL != val) {
return val;
}
return this;
}

View File

@ -12,8 +12,8 @@
#include <etk/types.h> #include <etk/types.h>
#include <draw/Color.h> #include <draw/Color.h>
#include <ewol/debug.h> #include <ewol/debug.h>
#include <ewol/widget/Widget.h> #include <ewol/widget/Container.h>
#include <ewol/widget/Drawable.h> #include <ewol/compositing/Drawing.h>
namespace widget { namespace widget {
typedef enum { typedef enum {
@ -23,38 +23,30 @@ namespace widget {
CONTEXT_MENU_MARK_LEFT, CONTEXT_MENU_MARK_LEFT,
CONTEXT_MENU_MARK_NONE CONTEXT_MENU_MARK_NONE
}markPosition_te; }markPosition_te;
class ContextMenu : public widget::Drawable class ContextMenu : public widget::Container
{ {
public: public:
ContextMenu(void); ContextMenu(void);
virtual ~ContextMenu(void); virtual ~ContextMenu(void);
// Derived function
virtual const char * const GetObjectType(void) { return "EwolContextMenu"; };
public:
virtual void CalculateSize(const vec2& availlable); // this generate the current size ...
virtual void CalculateMinMaxSize(void); //update the min Size ... and the expend parameters for the sizer
virtual void SetMinSize(const vec2& size);
virtual void SetExpand(const bvec2& newExpend);
private: private:
ewol::Drawing m_compositing;
draw::Color m_colorBackGroung; draw::Color m_colorBackGroung;
draw::Color m_colorBorder; draw::Color m_colorBorder;
vec2 m_padding; vec2 m_padding;
vec2 m_arrowPos; vec2 m_arrowPos;
float m_offset; float m_offset;
markPosition_te m_arrawBorder; markPosition_te m_arrawBorder;
ewol::Widget* m_subWidget;
public: public:
void SubWidgetSet(ewol::Widget* newWidget); void SetPositionMark(markPosition_te position, vec2 arrowPos);
void SubWidgetRemove(void); protected: // Derived function
void SetPositionMark(markPosition_te position, vec2 arrowPos);
protected:
// Derived function
virtual void OnDraw(ewol::DrawProperty& displayProp); virtual void OnDraw(ewol::DrawProperty& displayProp);
public: public: // Derived function
// Derived function
virtual void OnRegenerateDisplay(void); virtual void OnRegenerateDisplay(void);
virtual ewol::Widget* GetWidgetAtPos(const vec2& pos);
virtual bool OnEventInput(ewol::keyEvent::type_te type, int32_t IdInput, ewol::keyEvent::status_te typeEvent, const vec2& pos); virtual bool OnEventInput(ewol::keyEvent::type_te type, int32_t IdInput, ewol::keyEvent::status_te typeEvent, const vec2& pos);
virtual void CalculateSize(const vec2& availlable);
virtual void CalculateMinMaxSize(void);
virtual const char * const GetObjectType(void) { return "ewol::ContextMenu"; };
virtual ewol::Widget* GetWidgetAtPos(const vec2& pos);
}; };
}; };

View File

@ -127,7 +127,7 @@ void widget::Image::OnRegenerateDisplay(void)
// set the somposition properties : // set the somposition properties :
m_compositing.SetPos(origin); m_compositing.SetPos(origin);
m_compositing.Print(imageRealSize); m_compositing.Print(imageRealSize);
EWOL_DEBUG("Paint Image at : " << origin << " size=" << imageRealSize << " origin=" << origin); //EWOL_DEBUG("Paint Image at : " << origin << " size=" << imageRealSize << " origin=" << origin);
} }
} }

View File

@ -134,7 +134,7 @@ void widget::Menu::OnReceiveMessage(ewol::EObject * CallerObject, const char * e
SendMultiCast(m_listElement[iii]->m_generateEvent, m_listElement[iii]->m_message); SendMultiCast(m_listElement[iii]->m_generateEvent, m_listElement[iii]->m_message);
if (NULL != m_widgetContextMenu) { if (NULL != m_widgetContextMenu) {
EWOL_DEBUG("Mark the menu to remove ..."); EWOL_DEBUG("Mark the menu to remove ...");
delete(m_widgetContextMenu); m_widgetContextMenu->RemoveObject();
m_widgetContextMenu = NULL; m_widgetContextMenu = NULL;
} }
return; return;
@ -177,7 +177,7 @@ void widget::Menu::OnReceiveMessage(ewol::EObject * CallerObject, const char * e
mySizer = new widget::Sizer(widget::Sizer::modeVert); mySizer = new widget::Sizer(widget::Sizer::modeVert);
mySizer->LockExpand(vec2(true,true)); mySizer->LockExpand(vec2(true,true));
// set it in the pop-up-system : // set it in the pop-up-system :
m_widgetContextMenu->SubWidgetSet(mySizer); m_widgetContextMenu->SetSubWidget(mySizer);
for(int32_t jjj=m_listElement.Size()-1; jjj>=0; jjj--) { for(int32_t jjj=m_listElement.Size()-1; jjj>=0; jjj--) {
if (m_listElement[iii]!=NULL) { if (m_listElement[iii]!=NULL) {

View File

@ -13,53 +13,45 @@
#undef __class__ #undef __class__
#define __class__ "PopUp" #define __class__ "PopUp"
widget::PopUp::PopUp(void) : widget::PopUp::PopUp(void)
m_subWidgetNext(NULL)
{ {
m_userExpand.setValue(true, true); m_userExpand.setValue(false, false);
SetMinSize(ewol::Dimension(vec2(80,80),ewol::Dimension::Pourcent));
m_colorBackGroung = draw::color::white; m_colorBackGroung = draw::color::white;
m_colorEmptyArea = draw::color::black; m_colorEmptyArea = draw::color::black;
m_colorEmptyArea.a = 0x7F; m_colorEmptyArea.a = 0x7F;
m_colorBorder = draw::color::black; m_colorBorder = draw::color::black;
m_colorBorder.a = 0x7F; m_colorBorder.a = 0x7F;
m_subWidget = 0;
} }
widget::PopUp::~PopUp(void) widget::PopUp::~PopUp(void)
{ {
SubWidgetRemove();
} }
void widget::PopUp::CalculateSize(const vec2& availlable) void widget::PopUp::CalculateSize(const vec2& availlable)
{ {
//EWOL_DEBUG("CalculateSize=" << availlable);
// pop-up fill all the display :
m_size = availlable; m_size = availlable;
if (NULL != m_subWidget) { if (NULL != m_subWidget) {
vec2 subWidgetSize; vec2 subElementSize = m_minSize;
vec2 subWidgetOrigin; vec2 subElementOrigin = m_origin + (m_size-m_minSize)/2.0f;
subWidgetSize = m_subWidget->GetCalculateMinSize();
vec2 subWidgetSize = m_subWidget->GetCalculateMinSize();
if (true == m_subWidget->CanExpand().x()) { if (true == m_subWidget->CanExpand().x()) {
subWidgetSize.setX(m_size.x()); subWidgetSize.setX(m_minSize.x());
} }
if (true == m_subWidget->CanExpand().y()) { if (true == m_subWidget->CanExpand().y()) {
subWidgetSize.setY(m_size.y()); subWidgetSize.setY(m_minSize.y());
} }
if (m_displayRatio>0.1 && m_displayRatio<=1) { // limit the size of the element :
subWidgetSize.setValue(etk_max(m_size.x()*m_displayRatio, subWidgetSize.x()), subWidgetSize.setMin(m_minSize);
etk_max(m_size.y()*m_displayRatio, subWidgetSize.y()) ); // posiition at a int32_t pos :
} subWidgetSize = vec2ClipInt32(subWidgetSize);
// force to be an integer ...
subWidgetSize.setValue((int32_t)subWidgetSize.x(), (int32_t)subWidgetSize.y());
// set config to the Sub-widget // set config to the Sub-widget
subWidgetOrigin.setValue((int32_t)(m_size.x() - m_origin.x() - subWidgetSize.x())/2 + m_origin.x(), vec2 subWidgetOrigin = m_origin + (m_size-subWidgetSize)/2.0f;
(int32_t)(m_size.y() - m_origin.y() - subWidgetSize.y())/2 + m_origin.y());
m_subWidget->SetOrigin(subWidgetOrigin); m_subWidget->SetOrigin(subWidgetOrigin);
m_subWidget->CalculateSize(subWidgetSize); m_subWidget->CalculateSize(subWidgetSize);
@ -70,55 +62,28 @@ void widget::PopUp::CalculateSize(const vec2& availlable)
void widget::PopUp::CalculateMinMaxSize(void) void widget::PopUp::CalculateMinMaxSize(void)
{ {
//EWOL_DEBUG("CalculateMinMaxSize"); // remove expand of sub widget ==> not needed ...
m_userExpand.setValue(false,false); m_userExpand.setValue(false,false);
m_minSize.setValue(50, 50);
if (m_userMinSize.GetType() != ewol::Dimension::Pourcent) {
EWOL_ERROR(" ==> Please set pourcent size of the popo_up view");
m_minSize.setValue(50, 50);
} else {
m_minSize = m_userMinSize.GetPixel();
}
if (NULL != m_subWidget) { if (NULL != m_subWidget) {
m_subWidget->CalculateMinMaxSize(); m_subWidget->CalculateMinMaxSize();
vec2 tmpSize = m_subWidget->GetCalculateMinSize(); vec2 tmpSize = m_subWidget->GetCalculateMinSize();
m_minSize = tmpSize; m_minSize.setMax(tmpSize);
} }
//EWOL_DEBUG("CalculateMinSize(" << m_minSize.x << "," << m_minSize.y << ")"); EWOL_DEBUG("CalculateMinSize=" << m_minSize);
MarkToRedraw(); MarkToRedraw();
} }
void widget::PopUp::SetMinSize(const vec2& size)
{
EWOL_ERROR("Pop-up can not have a user Minimum size (herited from under elements)");
}
void widget::PopUp::SetExpand(const bvec2& newExpand)
{
EWOL_ERROR("Pop-up can not have a user expand settings X (herited from under elements)");
}
void widget::PopUp::SubWidgetSet(ewol::Widget* newWidget)
{
if (NULL == newWidget) {
EWOL_ERROR("Try to set a sub wiget with NULL pointer ...");
return;
}
SubWidgetRemove();
m_subWidget = newWidget;
//EWOL_DEBUG("SetSubWidget on Pop-Up : " << (int64_t)m_subWidget);
MarkToRedraw();
}
void widget::PopUp::SubWidgetRemove(void)
{
if (NULL != m_subWidget) {
delete(m_subWidget);
m_subWidget = NULL;
}
MarkToRedraw();
}
void widget::PopUp::OnDraw(ewol::DrawProperty& displayProp) void widget::PopUp::OnDraw(ewol::DrawProperty& displayProp)
{ {
// draw upper classes // draw upper classes
widget::Drawable::OnDraw(displayProp); m_compositing.Draw();
if (NULL != m_subWidget) { if (NULL != m_subWidget) {
m_subWidget->GenDraw(displayProp); m_subWidget->GenDraw(displayProp);
} }
@ -128,68 +93,33 @@ void widget::PopUp::OnDraw(ewol::DrawProperty& displayProp)
void widget::PopUp::OnRegenerateDisplay(void) void widget::PopUp::OnRegenerateDisplay(void)
{ {
if (true == NeedRedraw()) { if (true == NeedRedraw()) {
m_compositing.Clear();
m_compositing.SetColor(m_colorEmptyArea);
m_compositing.SetPos(vec3(0,0,0));
m_compositing.RectangleWidth(vec3(m_size.x(), m_size.y(), 0));
// set the area in white ...
if (NULL != m_subWidget) {
vec2 tmpSize = m_subWidget->GetSize();
vec2 tmpOrigin = m_subWidget->GetOrigin();
m_compositing.SetColor(m_colorBorder);
m_compositing.SetPos(vec3(tmpOrigin.x()-BORDER_SIZE_TMP, tmpOrigin.y()-BORDER_SIZE_TMP,0) );
m_compositing.RectangleWidth(vec3(tmpSize.x()+2*BORDER_SIZE_TMP, tmpSize.y()+2*BORDER_SIZE_TMP, 0) );
m_compositing.SetColor(m_colorBackGroung);
m_compositing.SetPos(vec3(tmpOrigin.x(), tmpOrigin.y(),0) );
m_compositing.RectangleWidth(vec3(tmpSize.x(), tmpSize.y(), 0) );
}
} }
// generate a white background and take gray on other surfaces // SUBwIDGET GENERATION ...
ClearOObjectList();
ewol::Drawing * BGOObjects = new ewol::Drawing();
AddOObject(BGOObjects);
BGOObjects->SetColor(m_colorEmptyArea);
BGOObjects->SetPos(vec3(0,0,0));
BGOObjects->RectangleWidth(vec3(m_size.x(), m_size.y(), 0));
// set the area in white ...
if (NULL != m_subWidget) {
vec2 tmpSize = m_subWidget->GetSize();
vec2 tmpOrigin = m_subWidget->GetOrigin();
BGOObjects->SetColor(m_colorBorder);
BGOObjects->SetPos(vec3(tmpOrigin.x()-BORDER_SIZE_TMP, tmpOrigin.y()-BORDER_SIZE_TMP,0) );
BGOObjects->RectangleWidth(vec3(tmpSize.x()+2*BORDER_SIZE_TMP, tmpSize.y()+2*BORDER_SIZE_TMP, 0) );
BGOObjects->SetColor(m_colorBackGroung);
BGOObjects->SetPos(vec3(tmpOrigin.x(), tmpOrigin.y(),0) );
BGOObjects->RectangleWidth(vec3(tmpSize.x(), tmpSize.y(), 0) );
}
if (NULL != m_subWidget) { if (NULL != m_subWidget) {
m_subWidget->OnRegenerateDisplay(); m_subWidget->OnRegenerateDisplay();
} }
} }
ewol::Widget* widget::PopUp::GetWidgetAtPos(const vec2& pos)
ewol::Widget * widget::PopUp::GetWidgetAtPos(const vec2& pos)
{ {
// calculate relative position ewol::Widget* val = widget::Container::GetWidgetAtPos(pos);
vec2 relativePos = RelativePosition(pos); if (NULL != val) {
// for the element in the pop-up ... return val;
if (NULL != m_subWidget) {
vec2 tmpSize = m_subWidget->GetSize();
vec2 tmpOrigin = m_subWidget->GetOrigin();
if( (tmpOrigin.x() <= relativePos.x() && tmpOrigin.x() + tmpSize.x() >= relativePos.x())
&& (tmpOrigin.y() <= relativePos.y() && tmpOrigin.y() + tmpSize.y() >= relativePos.y()) )
{
return m_subWidget->GetWidgetAtPos(pos);
} else {
//EWOL_INFO("Event ouside the Pop-up");
}
} }
// otherwise the event go to this widget ...
return this; return this;
} }
void widget::PopUp::SetDisplayRatio(float ratio)
{
m_displayRatio = ratio;
MarkToRedraw();
}
void widget::PopUp::OnObjectRemove(ewol::EObject * removeObject)
{
// First step call parrent :
widget::Drawable::OnObjectRemove(removeObject);
// second step find if in all the elements ...
if(m_subWidget == removeObject) {
EWOL_DEBUG("Remove pop-up sub Element ==> destroyed object");
m_subWidget = NULL;
}
}

View File

@ -13,43 +13,28 @@
#include <draw/Color.h> #include <draw/Color.h>
#include <ewol/debug.h> #include <ewol/debug.h>
#include <ewol/widget/Widget.h> #include <ewol/widget/Widget.h>
#include <ewol/widget/Drawable.h> #include <ewol/widget/Container.h>
#include <ewol/compositing/Drawing.h>
namespace widget { namespace widget {
class PopUp : public widget::Drawable class PopUp : public widget::Container
{ {
public: public:
PopUp(void); PopUp(void);
virtual ~PopUp(void); virtual ~PopUp(void);
// Derived function private:
virtual const char * const GetObjectType(void) { return "EwolPopUp"; }; draw::Color m_colorBackGroung;
public: draw::Color m_colorBorder;
// Derived function draw::Color m_colorEmptyArea;
ewol::Drawing m_compositing;
protected: // Derived function
virtual void OnDraw(ewol::DrawProperty& displayProp);
public: // Derived function
virtual void OnRegenerateDisplay(void);
virtual void CalculateSize(const vec2& availlable); virtual void CalculateSize(const vec2& availlable);
virtual void CalculateMinMaxSize(void); virtual void CalculateMinMaxSize(void);
virtual void SetMinSize(const vec2& size); virtual const char * const GetObjectType(void) { return "ewol::PopUp"; };
virtual void SetExpand(const bvec2& newExpend); virtual ewol::Widget* GetWidgetAtPos(const vec2& pos);
void SetDisplayRatio(float ratio);
private:
draw::Color m_colorBackGroung;
draw::Color m_colorBorder;
draw::Color m_colorEmptyArea;
ewol::Widget* m_subWidgetNext;
ewol::Widget* m_subWidget;
float m_displayRatio;
public:
void SubWidgetSet(ewol::Widget* newWidget);
void SubWidgetRemove(void);
protected:
// Derived function
virtual void OnDraw(ewol::DrawProperty& displayProp);
public:
// Derived function
virtual void OnRegenerateDisplay(void);
// Derived function
virtual ewol::Widget * GetWidgetAtPos(const vec2& pos);
// Derived function
virtual void OnObjectRemove(ewol::EObject * removeObject);
}; };
}; };

View File

@ -33,7 +33,7 @@ void widget::Spacer::UnInit(void)
widget::Spacer::Spacer(void) widget::Spacer::Spacer(void)
{ {
m_localSize = 10; m_userMinSize = vec2(10,10);
SetCanHaveFocus(false); SetCanHaveFocus(false);
m_color = draw::color::black; m_color = draw::color::black;
m_color.a = 0; m_color.a = 0;
@ -44,20 +44,6 @@ widget::Spacer::~Spacer(void)
} }
void widget::Spacer::CalculateMinMaxSize(void)
{
m_minSize.setValue(m_localSize, m_localSize);
}
void widget::Spacer::SetSize(float size)
{
m_localSize = size;
MarkToRedraw();
}
void widget::Spacer::OnDraw(ewol::DrawProperty& displayProp) void widget::Spacer::OnDraw(ewol::DrawProperty& displayProp)
{ {
m_draw.Draw(); m_draw.Draw();

View File

@ -23,8 +23,6 @@ namespace widget {
static void UnInit(void); static void UnInit(void);
private: private:
ewol::Drawing m_draw; //!< Compositing drawing element ewol::Drawing m_draw; //!< Compositing drawing element
float m_localSize; //!< Local request size of the display
draw::Color m_color; //!< Background color
public: public:
/** /**
* @brief Main constructer * @brief Main constructer
@ -34,11 +32,9 @@ namespace widget {
* @brief Main destructer * @brief Main destructer
*/ */
virtual ~Spacer(void); virtual ~Spacer(void);
/** protected:
* @brief Set the minimum size requested draw::Color m_color; //!< Background color
* @param[in] size Requested size of the minimum display (in X and Y) public:
*/
void SetSize(float size);
/** /**
* @brief Spziby the background color (basicly transparent) * @brief Spziby the background color (basicly transparent)
* @param[in] newColor the display background color * @param[in] newColor the display background color
@ -46,8 +42,7 @@ namespace widget {
void SetColor(draw::Color newColor) { m_color = newColor; MarkToRedraw(); }; void SetColor(draw::Color newColor) { m_color = newColor; MarkToRedraw(); };
public: public:
// Derived function // Derived function
virtual const char * const GetObjectType(void) { return "Ewol::Spacer"; }; virtual const char * const GetObjectType(void) { return "ewol::spacer"; };
virtual void CalculateMinMaxSize(void);
virtual ewol::Widget * GetWidgetAtPos(const vec2& pos) { return NULL; }; virtual ewol::Widget * GetWidgetAtPos(const vec2& pos) { return NULL; };
virtual void OnRegenerateDisplay(void); virtual void OnRegenerateDisplay(void);
virtual void OnDraw(ewol::DrawProperty& displayProp); virtual void OnDraw(ewol::DrawProperty& displayProp);

View File

@ -214,7 +214,7 @@ void ewol::widgetManager::PeriodicCallAdd(ewol::Widget * pWidget)
void ewol::widgetManager::PeriodicCallRm(ewol::Widget * pWidget) void ewol::widgetManager::PeriodicCallRm(ewol::Widget * pWidget)
{ {
int32_t nbElement = 0; int32_t nbElement = 0;
for (int32_t iii=0; iii < l_listOfPeriodicWidget.Size(); iii++) { for (int32_t iii=l_listOfPeriodicWidget.Size()-1; iii>=0 ; iii--) {
if (l_listOfPeriodicWidget[iii] == pWidget) { if (l_listOfPeriodicWidget[iii] == pWidget) {
l_listOfPeriodicWidget[iii] = NULL; l_listOfPeriodicWidget[iii] = NULL;
} else { } else {
@ -228,7 +228,7 @@ void ewol::widgetManager::PeriodicCallRm(ewol::Widget * pWidget)
void ewol::widgetManager::PeriodicCall(int64_t localTime) void ewol::widgetManager::PeriodicCall(int64_t localTime)
{ {
for (int32_t iii=0; iii < l_listOfPeriodicWidget.Size(); iii++) { for (int32_t iii=l_listOfPeriodicWidget.Size()-1; iii>=0 ; iii--) {
if (NULL != l_listOfPeriodicWidget[iii]) { if (NULL != l_listOfPeriodicWidget[iii]) {
l_listOfPeriodicWidget[iii]->PeriodicCall(localTime); l_listOfPeriodicWidget[iii]->PeriodicCall(localTime);
} }

View File

@ -28,8 +28,8 @@ namespace ewol {
ewol::Widget* FocusGet(void); ewol::Widget* FocusGet(void);
void FocusRemoveIfRemove(ewol::Widget * newWidget); void FocusRemoveIfRemove(ewol::Widget * newWidget);
void PeriodicCallAdd(ewol::Widget * pWidget); void PeriodicCallAdd(ewol::Widget* pWidget);
void PeriodicCallRm( ewol::Widget * pWidget); void PeriodicCallRm(ewol::Widget* pWidget);
void PeriodicCall(int64_t localTime); void PeriodicCall(int64_t localTime);
bool PeriodicCallHave(void); bool PeriodicCallHave(void);

View File

@ -70,11 +70,11 @@ widget::FileChooser::FileChooser(void)
widget::Image * myImage = NULL; widget::Image * myImage = NULL;
m_folder = etk::GetUserHomeFolder(); m_folder = etk::GetUserHomeFolder();
#if defined(__TARGET_OS__Android) #if defined(__TARGET_OS__Android)
SetDisplayRatio(0.90); SetMinSize(ewol::Dimension(vec2(90,90),ewol::Dimension::Pourcent));;
#elif defined(__TARGET_OS__Windows) #elif defined(__TARGET_OS__Windows)
SetDisplayRatio(0.80); SetMinSize(ewol::Dimension(vec2(80,80),ewol::Dimension::Pourcent));;
#else #else
SetDisplayRatio(0.80); SetMinSize(ewol::Dimension(vec2(80,80),ewol::Dimension::Pourcent));;
#endif #endif
m_file = ""; m_file = "";
@ -120,7 +120,7 @@ widget::FileChooser::FileChooser(void)
} else { } else {
mySizerVert->LockExpand(bvec2(true,true)); mySizerVert->LockExpand(bvec2(true,true));
// set it in the pop-up-system : // set it in the pop-up-system :
SubWidgetSet(mySizerVert); SetSubWidget(mySizerVert);
mySizerHori = new widget::Sizer(widget::Sizer::modeHori); mySizerHori = new widget::Sizer(widget::Sizer::modeHori);
if (NULL == mySizerHori) { if (NULL == mySizerHori) {
@ -182,7 +182,7 @@ widget::FileChooser::FileChooser(void)
if (NULL == mySpacer) { if (NULL == mySpacer) {
EWOL_ERROR("Can not allocate widget ==> display might be in error"); EWOL_ERROR("Can not allocate widget ==> display might be in error");
} else { } else {
mySpacer->SetSize(2); mySpacer->SetMinSize(vec2(2,2));
mySizerHori->SubWidgetAdd(mySpacer); mySizerHori->SubWidgetAdd(mySpacer);
} }
m_widgetListFolder = new widget::ListFileSystem(); m_widgetListFolder = new widget::ListFileSystem();
@ -201,7 +201,7 @@ widget::FileChooser::FileChooser(void)
if (NULL == mySpacer) { if (NULL == mySpacer) {
EWOL_ERROR("Can not allocate widget ==> display might be in error"); EWOL_ERROR("Can not allocate widget ==> display might be in error");
} else { } else {
mySpacer->SetSize(2); mySpacer->SetMinSize(vec2(2,2));
mySizerHori->SubWidgetAdd(mySpacer); mySizerHori->SubWidgetAdd(mySpacer);
} }
m_widgetListFile = new widget::ListFileSystem(); m_widgetListFile = new widget::ListFileSystem();
@ -221,7 +221,7 @@ widget::FileChooser::FileChooser(void)
if (NULL == mySpacer) { if (NULL == mySpacer) {
EWOL_ERROR("Can not allocate widget ==> display might be in error"); EWOL_ERROR("Can not allocate widget ==> display might be in error");
} else { } else {
mySpacer->SetSize(2); mySpacer->SetMinSize(vec2(2,2));
mySizerHori->SubWidgetAdd(mySpacer); mySizerHori->SubWidgetAdd(mySpacer);
} }
} }

View File

@ -38,9 +38,9 @@ widget::Parameter::Parameter(void) :
widget::Sizer * mySizerHori = NULL; widget::Sizer * mySizerHori = NULL;
widget::Spacer * mySpacer = NULL; widget::Spacer * mySpacer = NULL;
#ifdef __TARGET_OS__Android #ifdef __TARGET_OS__Android
SetDisplayRatio(0.90); SetMinSize(ewol::Dimension(vec2(90,90),ewol::Dimension::Pourcent));
#else #else
SetDisplayRatio(0.80); SetMinSize(ewol::Dimension(vec2(80,80),ewol::Dimension::Pourcent));
#endif #endif
mySizerVert = new widget::Sizer(widget::Sizer::modeVert); mySizerVert = new widget::Sizer(widget::Sizer::modeVert);
@ -50,7 +50,7 @@ widget::Parameter::Parameter(void) :
EWOL_INFO("add widget"); EWOL_INFO("add widget");
mySizerVert->LockExpand(bvec2(true,true)); mySizerVert->LockExpand(bvec2(true,true));
// set it in the pop-up-system : // set it in the pop-up-system :
SubWidgetSet(mySizerVert); SetSubWidget(mySizerVert);
mySizerHori = new widget::Sizer(widget::Sizer::modeHori); mySizerHori = new widget::Sizer(widget::Sizer::modeHori);
if (NULL == mySizerHori) { if (NULL == mySizerHori) {
@ -100,7 +100,7 @@ widget::Parameter::Parameter(void) :
EWOL_ERROR("Can not allocate widget ==> display might be in error"); EWOL_ERROR("Can not allocate widget ==> display might be in error");
} else { } else {
mySpacer->SetFill(bvec2(false,true)); mySpacer->SetFill(bvec2(false,true));
mySpacer->SetSize(5); mySpacer->SetMinSize(vec2(5,5));
mySpacer->SetColor(0x000000BF); mySpacer->SetColor(0x000000BF);
mySizerHori->SubWidgetAdd(mySpacer); mySizerHori->SubWidgetAdd(mySpacer);
} }
@ -116,7 +116,7 @@ widget::Parameter::Parameter(void) :
EWOL_ERROR("Can not allocate widget ==> display might be in error"); EWOL_ERROR("Can not allocate widget ==> display might be in error");
} else { } else {
mySpacer->SetExpand(bvec2(true,false)); mySpacer->SetExpand(bvec2(true,false));
mySpacer->SetSize(5); mySpacer->SetMinSize(vec2(5,5));
mySpacer->SetColor(0x000000BF); mySpacer->SetColor(0x000000BF);
mySizerVert2->SubWidgetAdd(mySpacer); mySizerVert2->SubWidgetAdd(mySpacer);
} }
@ -136,7 +136,7 @@ widget::Parameter::Parameter(void) :
EWOL_ERROR("Can not allocate widget ==> display might be in error"); EWOL_ERROR("Can not allocate widget ==> display might be in error");
} else { } else {
mySpacer->SetExpand(bvec2(true,false)); mySpacer->SetExpand(bvec2(true,false));
mySpacer->SetSize(5); mySpacer->SetMinSize(vec2(5,5));
mySpacer->SetColor(0x000000BF); mySpacer->SetColor(0x000000BF);
mySizerVert->SubWidgetAdd(mySpacer); mySizerVert->SubWidgetAdd(mySpacer);
} }