basic widget button and sizer

This commit is contained in:
Edouard Dupin 2011-11-08 15:59:25 +01:00
parent 6d28038192
commit e3668827e6
18 changed files with 689 additions and 83 deletions

View File

@ -25,6 +25,9 @@
#include <ewol.h>
#include <ewolFont.h>
#include <widget/ewolButton.h>
#include <widget/ewolSizerHori.h>
#include <widget/ewolSizerVert.h>
#include <unistd.h>
#include <stdlib.h>
@ -38,7 +41,27 @@ class Plop :public ewol::Windows
public:
Plop(void)
{
// generate the display :
ewol::SizerHori * mySizer = new ewol::SizerHori();
SetSubWidget(mySizer);
ewol::Button * myButton = new ewol::Button("Mon Labell 1");
mySizer->SubWidgetAdd(myButton);
ewol::SizerVert * mySizerVert = new ewol::SizerVert();
mySizer->SubWidgetAdd(mySizerVert);
myButton = new ewol::Button("BT 3");
myButton->SetExpendX(true);
myButton->SetExpendY(true);
mySizerVert->SubWidgetAdd(myButton);
myButton = new ewol::Button(" 4 4 BT");
myButton->SetExpendY(true);
mySizerVert->SubWidgetAdd(myButton);
myButton = new ewol::Button("Exemple 2");
myButton->SetExpendX(true);
mySizer->SubWidgetAdd(myButton);
};
~Plop(void)
@ -60,7 +83,7 @@ int main(int argc, char *argv[])
}
*/
ewol::SetFontFolder("Font");
ewol::SetDefaultFont("freefont/FreeMono", 16);
ewol::SetDefaultFont("freefont/FreeMono", 14);
Plop * myWindowsExample = new Plop();

View File

@ -58,8 +58,6 @@ namespace ewol
// get the size of a long string in UTF8 (note that \n and \r represent unknown char...)
int32_t GetWidth(int32_t fontID, const uniChar_t * unicodeString);
int32_t GetWidth(int32_t fontID, const char * utf8String);
int32_t GetWidth(int32_t fontID, const uniChar_t unicodeChar);
int32_t GetWidth(int32_t fontID, const char utf8Char);
int32_t GetHeight(int32_t fontID);

View File

@ -202,15 +202,16 @@ class FTFontInternal
}
public:
etk::String GetFontName(void) {return m_fontName;};
bool GenerateBitmapFont(int32_t size, int32_t textureId, etk::VectorType<freeTypeFontElement_ts> & listElement)
bool GenerateBitmapFont(int32_t size, int32_t &height, int32_t textureId, etk::VectorType<freeTypeFontElement_ts> & listElement)
{
// 300dpi (hight quality) 96 dpi (normal quality)
int32_t fontQuality = 96;
//int32_t fontQuality = 300;
// Select Size ...
// note tha <<6==*64 corespond with the 1/64th of points calculation of freetype
int32_t error = FT_Set_Char_Size(m_fftFace, size<<6, size<<6, fontQuality, fontQuality);
// the line height to have a correct display
//float lineHeight = size*1.43f;
height = size*1.43f;
// a small shortcut
FT_GlyphSlot slot = m_fftFace->glyph;
@ -355,7 +356,7 @@ class FTFont{
m_size = size;
//generate font
glGenTextures(1, &m_textureId);
m_listLoadedTTFont[m_trueTypeFontId]->GenerateBitmapFont(m_size, m_textureId, m_elements);
m_listLoadedTTFont[m_trueTypeFontId]->GenerateBitmapFont(m_size, m_lineHeight, m_textureId, m_elements);
}
~FTFont(void)
{
@ -389,10 +390,16 @@ class FTFont{
return m_size;
};
int32_t GetHeight(void)
{
return m_lineHeight;
};
private:
int32_t m_trueTypeFontId;
uint32_t m_textureId; // internal texture ID
int32_t m_size; // nb pixel height
int32_t m_lineHeight; // nb pixel height
int32_t m_interline; // nb pixel between 2 lines
etk::VectorType<freeTypeFontElement_ts> m_elements; //
@ -606,3 +613,46 @@ void ewol::DrawText(int32_t fontID,
drawPosition.x = posDrawX;
}
int32_t ewol::GetWidth(int32_t fontID, const char * utf8String)
{
if(fontID>=m_listLoadedFont.Size() || fontID < 0) {
EWOL_WARNING("try to display text with an fontID that does not existed " << fontID);
return 0;
}
etk::VectorType<freeTypeFontElement_ts> & listOfElement = m_listLoadedFont[fontID]->GetRefOnElement();
char * tmpVal = (char*)utf8String;
float posDrawX = 0.0;
while(*tmpVal != 0) {
int32_t tmpChar = *tmpVal++;
int32_t charIndex;
if (tmpChar >= 0x80) {
charIndex = 0;
} else if (tmpChar < 0x20) {
charIndex = 0;
} else if (tmpChar < 0x80) {
charIndex = tmpChar - 0x1F;
} else {
for (int32_t iii=0x80-0x20; iii < listOfElement.Size(); iii++) {
if (listOfElement[iii].unicodeCharVal == tmpChar) {
charIndex = iii;
break;
}
}
// TODO : Update if possible the mapping
charIndex = 0;
}
posDrawX += listOfElement[charIndex].width;
}
return posDrawX;
}
int32_t ewol::GetHeight(int32_t fontID)
{
if(fontID>=m_listLoadedFont.Size() || fontID < 0) {
EWOL_WARNING("try to display text with an fontID that does not existed " << fontID);
return 10;
}
return m_listLoadedFont[fontID]->GetHeight();
}

View File

@ -101,6 +101,15 @@ void ewol::OObject2DColored::Rectangle(float x, float y, float w, float h, float
}
void ewol::OObject2DColored::UpdateOrigin(float x, float y)
{
for (int32_t iii=0; iii<m_coord.Size(); iii++) {
m_coord[iii].x += x;
m_coord[iii].y += y;
}
}
#undef __class__
@ -187,6 +196,15 @@ void ewol::OObject2DTextured::Rectangle(float x, float y, float w, float h, floa
m_coordTex.PushBack(tex);
}
void ewol::OObject2DTextured::UpdateOrigin(float x, float y)
{
for (int32_t iii=0; iii<m_coord.Size(); iii++) {
m_coord[iii].x += x;
m_coord[iii].y += y;
}
}
#undef __class__
#define __class__ "ewol::OObject2DText"
@ -228,8 +246,13 @@ void ewol::OObject2DText::Text(float x, float y, etk::String FontName, int32_t s
m_coord.Clear();
m_coordTex.Clear();
// get font Name :
//m_FontId = GetFontIdWithName(FontName);
m_FontId = GetDefaultFontId();
if (FontName == "") {
m_FontId = GetDefaultFontId();
} else {
EWOL_TODO("pas encore fait...");
//m_FontId = GetFontIdWithName(FontName);
return;
}
if (m_FontId == -1) {
EWOL_ERROR("Can not find the font with the name : " << FontName);
}
@ -241,6 +264,13 @@ void ewol::OObject2DText::Text(float x, float y, etk::String FontName, int32_t s
ewol::DrawText(m_FontId, drawPosition, utf8String, m_FontTextureId, m_coord, m_coordTex);
}
void ewol::OObject2DText::UpdateOrigin(float x, float y)
{
for (int32_t iii=0; iii<m_coord.Size(); iii++) {
m_coord[iii].x += x;
m_coord[iii].y += y;
}
}
/*
uint32_t m_FontId; //!< font internal ID

View File

@ -61,6 +61,8 @@ namespace ewol {
{
return m_name;
}
public:
virtual void UpdateOrigin(float x, float y) {};
private:
etk::String m_name;
};
@ -78,6 +80,8 @@ namespace ewol {
//etk::VectorType<linkCoord_ts> m_linkCoord; //!< internal link between point to generate triangle
public:
void Rectangle(float x, float y, float w, float h, float red, float green, float blue, float alpha);
public:
virtual void UpdateOrigin(float x, float y);
};
/*
class OObjectFile :public ewol::OObject
@ -106,6 +110,8 @@ namespace ewol {
uint32_t m_textureId; //!< texture internal ID
etk::VectorType<coord2D_ts> m_coord; //!< internal coord of the object
etk::VectorType<texCoord_ts> m_coordTex; //!< internal texture coordinate for every point
public:
virtual void UpdateOrigin(float x, float y);
};
@ -124,6 +130,8 @@ namespace ewol {
uint32_t m_FontTextureId; //!< font internal Texture ID
etk::VectorType<coord2D_ts> m_coord; //!< internal coord of the object
etk::VectorType<texCoord_ts> m_coordTex; //!< internal texture coordinate for every point
public:
virtual void UpdateOrigin(float x, float y);
};
/*

View File

@ -31,15 +31,17 @@ ewol::Widget::Widget(void)
{
m_origin.x = 0.0;
m_origin.y = 0.0;
m_minSize.x = -1.0;
m_minSize.y = -1.0;
m_size.x = 10.0;
m_size.y = 10.0;
m_maxSize.x = -1.0;
m_maxSize.y = -1.0;
m_expendX = false;
m_expendY = false;
m_minSize.x = -1.0;
m_minSize.y = -1.0;
// user settings :
m_userMinSize.x = -1.0;
m_userMinSize.y = -1.0;
m_userExpendX = false;
m_userExpendY = false;
m_genericDraw = true;
m_specificDraw = false;
}
ewol::Widget::~Widget(void)
@ -51,6 +53,8 @@ ewol::Widget::~Widget(void)
bool ewol::Widget::CalculateSize(double availlableX, double availlableY)
{
m_size.x = availlableX;
m_size.y = availlableY;
return true;
}
@ -175,6 +179,8 @@ void ewol::Widget::AddOObject(ewol::OObject* newObject, etk::String name)
return;
}
newObject->SetName(name);
EWOL_INFO("UPDATE AT origin : (" << m_origin.x << "," << m_origin.y << ")");
newObject->UpdateOrigin(m_origin.x, m_origin.y);
m_listOObject.PushBack(newObject);
}

View File

@ -146,23 +146,27 @@ namespace ewol {
// -- Widget Size:
// ----------------------------------------------------------------------------------------------------------------
protected:
coord m_origin;
coord m_minSize;
coord m_size;
coord m_maxSize;
bool m_expendX;
bool m_expendY;
void SetExpendX(bool newExpend=false) { m_expendX = newExpend; };
void SetExpendY(bool newExpend=false) { m_expendY = newExpend; };
void SetMinSise(double x=-1, double y=-1) { m_minSize.x = x; m_minSize.y = y; };
void SetMaxSise(double x=-1, double y=-1) { m_maxSize.x = x; m_maxSize.y = y; };
void SetCurrentSise(double x=-1, double y=-1) { m_size.x = x; m_size.y = y; };
// internal element calculated by the system
coord m_origin; //!< internal ... I do not really known how i can use it ...
coord m_size; //!< internal : current size of the widget
coord m_minSize; //!< user define the minimum size of the widget
// user configuaration
coord m_userMinSize; //!< user define the minimum size of the widget
bool m_userExpendX;
bool m_userExpendY;
public:
void SetOrigin(double x, double y) { m_origin.x=x; m_origin.y=y; };
virtual bool CalculateSize(double availlableX, double availlableY); // this generate the current size ...
coord GetMinSize(void) { return m_minSize; };
coord GetMaxSize(void) { return m_maxSize; };
coord GetCurrentSize(void) { return m_size; };
void SetOrigin(double x, double y) { m_origin.x=x; m_origin.y=y; };
virtual bool CalculateSize(double availlableX, double availlableY); // this generate the current size ...
virtual bool CalculateMinSize(void) {m_minSize.x = m_userMinSize.x; m_minSize.y = m_userMinSize.y; return true; }; //update the min Size ... and the expend parameters for the sizer
virtual void SetMinSise(double x=-1, double y=-1) { m_userMinSize.x = x; m_userMinSize.y = y; };
coord GetMinSize(void) { return m_minSize; };
coord GetSize(void) { return m_size; };
void SetCurrentSise(double x=-1, double y=-1) { m_size.x = x; m_size.y = y; };
coord GetCurrentSize(void) { return m_size; };
virtual void SetExpendX(bool newExpend=false) { m_userExpendX = newExpend; };
bool CanExpentX(void) { return m_userExpendX; };
virtual void SetExpendY(bool newExpend=false) { m_userExpendY = newExpend; };
bool CanExpentY(void) { return m_userExpendY; };
// ----------------------------------------------------------------------------------------------------------------
// -- Focus Area
@ -239,6 +243,7 @@ namespace ewol {
// ----------------------------------------------------------------------------------------------------------------
private:
bool m_genericDraw;
bool m_specificDraw;
etk::VectorType<ewol::OObject*> m_listOObject; //!< generic element to display...
bool GenericDraw(void);
protected:
@ -246,19 +251,24 @@ namespace ewol {
ewol::OObject* GetOObject(etk::String name);
void RmOObjectElem(etk::String name);
void ClearOObjectList(void);
void SetNotGenericDraw(void) { m_genericDraw = false; };
void SetGenericDraw(void) { m_genericDraw = true; };
virtual bool OnDraw(void) { return true; };
void GenericDrawDisable(void) { m_genericDraw = false; };
void GenericDrawEnable(void) { m_genericDraw = true; };
void SpecificDrawDisable(void) { m_specificDraw = false; };
void SpecificDrawEnable(void) { m_specificDraw = true; };
virtual bool OnDraw(void) { /*EWOL_ERROR("plop");*/ return true; };
public:
virtual void OnRegenerateDisplay(void) { };
bool GenDraw(void)
{
if (true == m_genericDraw) {
//EWOL_DEBUG("Draw generic...");
return GenericDraw();
} else {
//EWOL_DEBUG("Draw Custum...");
return OnDraw();
GenericDraw();
}
if (true == m_specificDraw) {
//EWOL_DEBUG("Draw Custum...");
OnDraw();
}
return true;
};
}; // end of the class Widget declaration

View File

@ -46,16 +46,27 @@ const char * ewolEventWindowsExpend = "ewol Windows expend/unExpend";
ewol::Windows::Windows(void)
{
m_subWidget = NULL;
// enable specific drawing system ...
SpecificDrawEnable();
SetDecorationDisable();
if (true == m_hasDecoration) {
ewol::OObject2DColored * myOObject = new ewol::OObject2DColored();
myOObject->Rectangle( 0, 0, 20, 20, 1.0, 0.0, 0.0, 1.0); // Close
myOObject->Rectangle(20, 0, 20, 20, 0.0, 1.0, 0.0, 1.0); // Reduce
myOObject->Rectangle(40, 0, 20, 20, 0.0, 0.0, 1.0, 1.0); // Expend - Un-expend
AddEventArea({ 0.0,0.0}, {20, 20}, FLAG_EVENT_INPUT_1 | FLAG_EVENT_INPUT_CLICKED_ALL, ewolEventWindowsClose);
AddEventArea({20.0,0.0}, {20, 20}, FLAG_EVENT_INPUT_1 | FLAG_EVENT_INPUT_CLICKED_ALL, ewolEventWindowsMinimize);
AddEventArea({40.0,0.0}, {20, 20}, FLAG_EVENT_INPUT_1 | FLAG_EVENT_INPUT_CLICKED_ALL, ewolEventWindowsExpend);
coord origin;
coord size;
origin.x = 0.0;
origin.y = 0.0;
size.x = 20;
size.y = 20;
AddEventArea(origin, size, FLAG_EVENT_INPUT_1 | FLAG_EVENT_INPUT_CLICKED_ALL, ewolEventWindowsClose);
origin.x = 20.0;
AddEventArea(origin, size, FLAG_EVENT_INPUT_1 | FLAG_EVENT_INPUT_CLICKED_ALL, ewolEventWindowsMinimize);
origin.x = 40.0;
AddEventArea(origin, size, FLAG_EVENT_INPUT_1 | FLAG_EVENT_INPUT_CLICKED_ALL, ewolEventWindowsExpend);
AddOObject(myOObject, "leftBoutton");
@ -69,12 +80,26 @@ ewol::Windows::Windows(void)
}
}
ewol::Windows::~Windows(void)
{
if (NULL != m_subWidget) {
delete(m_subWidget);
m_subWidget=NULL;
}
}
bool ewol::Windows::CalculateSize(double availlableX, double availlableY)
{
m_size.x = availlableX;
m_size.y = availlableY;
if (NULL != m_subWidget) {
m_subWidget->CalculateMinSize();
// TODO : Check if min Size is possible ...
// TODO : Herited from MinSize .. and expand ???
m_subWidget->CalculateSize(m_size.x, m_size.y);
}
// regenerate all the display ...
OnRegenerateDisplay();
return true;
}
@ -112,17 +137,10 @@ bool ewol::Windows::OnEventInput(int32_t IdInput, eventInputType_te typeEvent, d
# include <X11/extensions/Xrender.h>
#endif
#include <ft2build.h>
#include FT_FREETYPE_H
FT_Library library; // handle to library
FT_Face face; // handle to face object
void ewol::Windows::SysDraw(void)
{
//EWOL_DEBUG("Drow on (" << m_size.x << "," << m_size.y << ")");
EWOL_DEBUG("Drow on (" << m_size.x << "," << m_size.y << ")");
// set the size of the open GL system
glViewport(0,0,m_size.x,m_size.y);
@ -146,10 +164,29 @@ void ewol::Windows::SysDraw(void)
GenDraw();
glDisable(GL_BLEND);
return;
}
void ewol::Windows::OnRegenerateDisplay(void)
{
if (NULL != m_subWidget) {
m_subWidget->OnRegenerateDisplay();
}
}
bool ewol::Windows::OnDraw(void)
{
if (NULL != m_subWidget) {
m_subWidget->GenDraw();
}
/*
// Test AREA :
ewol::OObject2DColored tmpOObjects;
tmpOObjects.Rectangle( 50, 50, 200, 300, 1.0, 0.0, 0.0, 1.0);
tmpOObjects.Draw();
glColor4f(0.0, 0.0, 0.0, 1.0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, 1);
@ -164,13 +201,10 @@ void ewol::Windows::SysDraw(void)
glVertex3f(50.0, 350.0, 0.0);
glEnd();
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
return;
*/
return true;
}
bool ewol::Windows::OnEventArea(const char * generateEventId, double x, double y)
{
bool eventIsOK = false;
@ -189,3 +223,17 @@ bool ewol::Windows::OnEventArea(const char * generateEventId, double x, double y
return eventIsOK;
}
void ewol::Windows::SetSubWidget(ewol::Widget * widget)
{
if (NULL != m_subWidget) {
EWOL_INFO("Remove current main windows Widget...");
delete(m_subWidget);
m_subWidget = NULL;
}
m_subWidget = widget;
// Regenerate the size calculation :
CalculateSize(m_size.x, m_size.y);
}

View File

@ -36,7 +36,7 @@ namespace ewol {
{
public:
Windows(void);
virtual ~Windows(void) {};
virtual ~Windows(void);
// internal event at ewol system :
public:
void SysDraw(void);
@ -68,6 +68,14 @@ namespace ewol {
{
m_hasDecoration = true;
}
private:
ewol::Widget * m_subWidget;
public:
void SetSubWidget(ewol::Widget * widget);
protected:
virtual bool OnDraw(void);
public:
virtual void OnRegenerateDisplay(void);
};
};

View File

@ -24,3 +24,75 @@
#include <widget/ewolButton.h>
#include <ewolOObject.h>
#undef __class__
#define __class__ "ewol::Button"
ewol::Button::Button(void)
{
m_label = "No Label";
}
ewol::Button::Button(etk::String newLabel)
{
m_label = newLabel;
}
ewol::Button::~Button(void)
{
}
bool ewol::Button::CalculateMinSize(void)
{
//SetMinSise(55, 24);
int32_t fontId = GetDefaultFontId();
int32_t minWidth = ewol::GetWidth(fontId, m_label.c_str());
int32_t minHeight = ewol::GetHeight(fontId);
m_minSize.x = 10+minWidth;
m_minSize.y = 10+minHeight;
return true;
}
void ewol::Button::SetLabel(etk::String newLabel)
{
m_label = newLabel;
}
void ewol::Button::SetValue(bool val)
{
}
bool ewol::Button::GetValue(void)
{
return false;
}
void ewol::Button::OnRegenerateDisplay(void)
{
// clean the object list ...
ClearOObjectList();
ewol::OObject2DColored * tmpOObjects = new ewol::OObject2DColored;
tmpOObjects->Rectangle( 2, 2, m_size.x-4, m_size.y-4, 0.0, 0.0, 0.0, 1.0);
tmpOObjects->Rectangle( 3, 3, m_size.x-6, m_size.y-6, 1.0, 1.0, 1.0, 1.0);
AddOObject(tmpOObjects, "BouttonDecoration");
color_ts textColorFg;
textColorFg.red = 0.0;
textColorFg.green = 0.0;
textColorFg.blue = 0.0;
textColorFg.alpha = 1.0;
int32_t fontId = GetDefaultFontId();
int32_t fontHeight = ewol::GetHeight(fontId);
int32_t pos = (m_size.y - fontHeight)/2;
ewol::OObject2DText * tmpText = new ewol::OObject2DText(5, pos, "", -1, FONT_MODE_BOLD, textColorFg, m_label.c_str());
AddOObject(tmpText, "BouttonText");
}

View File

@ -33,8 +33,21 @@ namespace ewol {
class Button :public ewol::Widget
{
public:
Button(void) { };
virtual ~Button(void) { };
Button(void);
Button(etk::String newLabel);
virtual ~Button(void);
virtual bool CalculateMinSize(void);
void SetLabel(etk::String newLabel);
// TODO :
//void SetSize(int32_t size);
//void SetFont(etk::String fontName);
//void ResetDefaultParameters(void);
void SetValue(bool val);
bool GetValue(void);
private:
etk::String m_label;
public:
virtual void OnRegenerateDisplay(void);
};
};

View File

@ -24,3 +24,6 @@
#include <widget/ewolCheckBox.h>
#undef __class__
#define __class__ "ewol::CheckBox"

View File

@ -24,3 +24,6 @@
#include <widget/ewolEntry.h>
#undef __class__
#define __class__ "ewol::Entry"

View File

@ -24,3 +24,7 @@
#include <widget/ewolList.h>
#undef __class__
#define __class__ "ewol::List"

View File

@ -26,10 +26,13 @@
#include <widget/ewolSizerHori.h>
#undef __class__
#define __class__ "ewol::SizerHori"
ewol::SizerHori::SizerHori(void)
{
GenericDrawDisable();
SpecificDrawEnable();
}
ewol::SizerHori::~SizerHori(void)
@ -41,20 +44,109 @@ ewol::SizerHori::~SizerHori(void)
bool ewol::SizerHori::CalculateSize(double availlableX, double availlableY)
{
EWOL_DEBUG("Update Size");
m_size.x = availlableX;
m_size.y = availlableY;
// calculate unExpendable Size :
double unexpendableSize=0.0;
int32_t nbWidgetFixedSize=0;
int32_t nbWidgetNotFixedSize=0;
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
if (NULL != m_subWidget[iii]) {
coord tmpSize = m_subWidget[iii]->GetMinSize();
unexpendableSize += tmpSize.x;
if (false == m_subWidget[iii]->CanExpentX()) {
nbWidgetFixedSize++;
} else {
nbWidgetNotFixedSize++;
}
}
}
double sizeToAddAtEveryOne = 0;
// 2 cases : 1 or more can Expend, or all is done ...
if (0 != nbWidgetNotFixedSize) {
sizeToAddAtEveryOne = (m_size.x - unexpendableSize) / nbWidgetNotFixedSize;
if (sizeToAddAtEveryOne<0.0) {
sizeToAddAtEveryOne=0;
}
}
coord tmpOrigin;
tmpOrigin.x = m_origin.x;
tmpOrigin.y = m_origin.y;
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
if (NULL != m_subWidget[iii]) {
coord tmpSize = m_subWidget[iii]->GetMinSize();
// Set the origin :
EWOL_DEBUG("Set ORIGIN : " << tmpOrigin.x << "," << tmpOrigin.y << ")");
m_subWidget[iii]->SetOrigin(tmpOrigin.x, tmpOrigin.y);
// Now Update his Size his size in X and the curent sizer size in Y:
if (true == m_subWidget[iii]->CanExpentX()) {
m_subWidget[iii]->CalculateSize(tmpSize.x+sizeToAddAtEveryOne, m_size.y);
tmpOrigin.x += tmpSize.x+sizeToAddAtEveryOne;
} else {
m_subWidget[iii]->CalculateSize(tmpSize.x, m_size.y);
tmpOrigin.x += tmpSize.x;
}
}
}
return true;
}
bool ewol::SizerHori::CalculateMinSize(void)
{
EWOL_DEBUG("Update minimum Size");
m_userExpendX=false;
m_userExpendY=false;
m_minSize.x = 0.0;
m_minSize.y = 0.0;
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
if (NULL != m_subWidget[iii]) {
m_subWidget[iii]->CalculateMinSize();
if (true == m_subWidget[iii]->CanExpentX()) {
m_userExpendX = true;
}
if (true == m_subWidget[iii]->CanExpentY()) {
m_userExpendY = true;
}
coord tmpSize = m_subWidget[iii]->GetMinSize();
m_minSize.x += tmpSize.x;
if (tmpSize.y>m_minSize.y) {
m_minSize.y = tmpSize.y;
}
}
}
EWOL_DEBUG("Result : expend X="<< m_userExpendX << " Y=" << m_userExpendY);
EWOL_DEBUG(" minSize ("<< m_minSize.x << "," << m_minSize.y << ")");
return true;
}
void ewol::SizerHori::SetMinSise(double x, double y)
{
EWOL_ERROR("Sizer can not have a user Minimum size (herited from under elements)");
}
void ewol::SizerHori::SetExpendX(bool newExpend)
{
EWOL_ERROR("Sizer can not have a user expend settings X (herited from under elements)");
}
void ewol::SizerHori::SetExpendY(bool newExpend)
{
EWOL_ERROR("Sizer can not have a user expend settings Y (herited from under elements)");
}
//etk::VectorType<ewol::Widget*> m_SubWidget;
void ewol::SizerHori::SubWidgetRemoveAll(void)
{
for (int32_t iii=0; iii<m_SubWidget.Size(); iii++) {
delete(m_SubWidget[iii]);
m_SubWidget[iii] = NULL;
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
if (NULL != m_subWidget[iii]) {
delete(m_subWidget[iii]);
m_subWidget[iii] = NULL;
}
}
m_SubWidget.Clear();
m_subWidget.Clear();
}
@ -63,7 +155,7 @@ void ewol::SizerHori::SubWidgetAdd(ewol::Widget* newWidget)
if (NULL == newWidget) {
return;
}
m_SubWidget.PushBack(newWidget);
m_subWidget.PushBack(newWidget);
newWidget->SetParrent(this);
}
@ -73,11 +165,13 @@ void ewol::SizerHori::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);
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
if (newWidget == m_subWidget[iii]) {
if (NULL != m_subWidget[iii]) {
delete(m_subWidget[iii]);
m_subWidget[iii] = NULL;
}
m_subWidget.Erase(iii);
return;
}
}
@ -88,11 +182,34 @@ void ewol::SizerHori::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);
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
if (newWidget == m_subWidget[iii]) {
m_subWidget[iii] = NULL;
m_subWidget.Erase(iii);
return;
}
}
}
}
bool ewol::SizerHori::OnDraw(void)
{
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
if (NULL != m_subWidget[iii]) {
m_subWidget[iii]->GenDraw();
}
}
return true;
}
void ewol::SizerHori::OnRegenerateDisplay(void)
{
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
if (NULL != m_subWidget[iii]) {
m_subWidget[iii]->OnRegenerateDisplay();
}
}
}

View File

@ -36,14 +36,22 @@ namespace ewol {
SizerHori(void);
virtual ~SizerHori(void);
public:
virtual bool CalculateSize(double availlableX, double availlableY); // this generate the current size ...
virtual bool CalculateSize(double availlableX, double availlableY); // this generate the current size ...
virtual bool CalculateMinSize(void); //update the min Size ... and the expend parameters for the sizer
virtual void SetMinSise(double x=-1, double y=-1);
virtual void SetExpendX(bool newExpend=false);
virtual void SetExpendY(bool newExpend=false);
private:
etk::VectorType<ewol::Widget*> m_SubWidget;
etk::VectorType<ewol::Widget*> m_subWidget;
public:
void SubWidgetRemoveAll(void);
void SubWidgetAdd(ewol::Widget* newWidget);
void SubWidgetRemove(ewol::Widget* newWidget);
void SubWidgetUnLink(ewol::Widget* newWidget);
void SubWidgetRemoveAll(void);
void SubWidgetAdd(ewol::Widget* newWidget);
void SubWidgetRemove(ewol::Widget* newWidget);
void SubWidgetUnLink(ewol::Widget* newWidget);
protected:
virtual bool OnDraw(void);
public:
virtual void OnRegenerateDisplay(void);
};
};

View File

@ -24,3 +24,191 @@
#include <widget/ewolSizerVert.h>
#undef __class__
#define __class__ "ewol::SizerVert"
ewol::SizerVert::SizerVert(void)
{
GenericDrawDisable();
SpecificDrawEnable();
}
ewol::SizerVert::~SizerVert(void)
{
SubWidgetRemoveAll();
}
bool ewol::SizerVert::CalculateSize(double availlableX, double availlableY)
{
EWOL_DEBUG("Update Size");
m_size.x = availlableX;
m_size.y = availlableY;
// calculate unExpendable Size :
double unexpendableSize=0.0;
int32_t nbWidgetFixedSize=0;
int32_t nbWidgetNotFixedSize=0;
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
if (NULL != m_subWidget[iii]) {
coord tmpSize = m_subWidget[iii]->GetMinSize();
unexpendableSize += tmpSize.y;
if (false == m_subWidget[iii]->CanExpentY()) {
nbWidgetFixedSize++;
} else {
nbWidgetNotFixedSize++;
}
}
}
// 2 cases : 1 or more can Expend, or all is done ...
double sizeToAddAtEveryOne = 0;
// 2 cases : 1 or more can Expend, or all is done ...
if (0 != nbWidgetNotFixedSize) {
sizeToAddAtEveryOne = (m_size.y - unexpendableSize) / nbWidgetNotFixedSize;
if (sizeToAddAtEveryOne<0.0) {
sizeToAddAtEveryOne=0;
}
}
coord tmpOrigin;
tmpOrigin.x = m_origin.x;
tmpOrigin.y = m_origin.y;
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
if (NULL != m_subWidget[iii]) {
coord tmpSize = m_subWidget[iii]->GetMinSize();
// Set the origin :
EWOL_DEBUG("Set ORIGIN : " << tmpOrigin.x << "," << tmpOrigin.y << ")");
m_subWidget[iii]->SetOrigin(tmpOrigin.x, tmpOrigin.y);
// Now Update his Size his size in X and the curent sizer size in Y:
if (true == m_subWidget[iii]->CanExpentY()) {
m_subWidget[iii]->CalculateSize(m_size.x, tmpSize.y+sizeToAddAtEveryOne);
tmpOrigin.y += tmpSize.y+sizeToAddAtEveryOne;
} else {
m_subWidget[iii]->CalculateSize(m_size.x, tmpSize.y);
tmpOrigin.y += tmpSize.y;
}
}
}
return true;
}
bool ewol::SizerVert::CalculateMinSize(void)
{
EWOL_DEBUG("Update minimum Size");
m_userExpendX=false;
m_userExpendY=false;
m_minSize.x = 0.0;
m_minSize.y = 0.0;
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
if (NULL != m_subWidget[iii]) {
m_subWidget[iii]->CalculateMinSize();
if (true == m_subWidget[iii]->CanExpentX()) {
m_userExpendX = true;
}
if (true == m_subWidget[iii]->CanExpentY()) {
m_userExpendY = true;
}
coord tmpSize = m_subWidget[iii]->GetMinSize();
m_minSize.y += tmpSize.y;
if (tmpSize.x>m_minSize.x) {
m_minSize.x = tmpSize.x;
}
}
}
EWOL_DEBUG("Result : expend X="<< m_userExpendX << " Y=" << m_userExpendY);
EWOL_DEBUG(" minSize ("<< m_minSize.x << "," << m_minSize.y << ")");
return true;
}
void ewol::SizerVert::SetMinSise(double x, double y)
{
EWOL_ERROR("Sizer can not have a user Minimum size (herited from under elements)");
}
void ewol::SizerVert::SetExpendX(bool newExpend)
{
EWOL_ERROR("Sizer can not have a user expend settings X (herited from under elements)");
}
void ewol::SizerVert::SetExpendY(bool newExpend)
{
EWOL_ERROR("Sizer can not have a user expend settings Y (herited from under elements)");
}
//etk::VectorType<ewol::Widget*> m_SubWidget;
void ewol::SizerVert::SubWidgetRemoveAll(void)
{
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
delete(m_subWidget[iii]);
m_subWidget[iii] = NULL;
}
m_subWidget.Clear();
}
void ewol::SizerVert::SubWidgetAdd(ewol::Widget* newWidget)
{
if (NULL == newWidget) {
return;
}
m_subWidget.PushBack(newWidget);
newWidget->SetParrent(this);
}
void ewol::SizerVert::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 ewol::SizerVert::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;
}
}
}
bool ewol::SizerVert::OnDraw(void)
{
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
if (NULL != m_subWidget[iii]) {
m_subWidget[iii]->GenDraw();
}
}
return true;
}
void ewol::SizerVert::OnRegenerateDisplay(void)
{
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
if (NULL != m_subWidget[iii]) {
m_subWidget[iii]->OnRegenerateDisplay();
}
}
}

View File

@ -33,8 +33,25 @@ namespace ewol {
class SizerVert :public ewol::Widget
{
public:
SizerVert(void) { };
virtual ~SizerVert(void) { };
SizerVert(void);
virtual ~SizerVert(void);
public:
virtual bool CalculateSize(double availlableX, double availlableY); // this generate the current size ...
virtual bool CalculateMinSize(void); //update the min Size ... and the expend parameters for the sizer
virtual void SetMinSise(double x=-1, double y=-1);
virtual void SetExpendX(bool newExpend=false);
virtual void SetExpendY(bool newExpend=false);
private:
etk::VectorType<ewol::Widget*> m_subWidget;
public:
void SubWidgetRemoveAll(void);
void SubWidgetAdd(ewol::Widget* newWidget);
void SubWidgetRemove(ewol::Widget* newWidget);
void SubWidgetUnLink(ewol::Widget* newWidget);
protected:
virtual bool OnDraw(void);
public:
virtual void OnRegenerateDisplay(void);
};
};