diff --git a/Sources/Main.cpp b/Sources/Main.cpp index 407495b4..d7c3fde0 100644 --- a/Sources/Main.cpp +++ b/Sources/Main.cpp @@ -25,6 +25,9 @@ #include #include +#include +#include +#include #include #include @@ -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(); diff --git a/Sources/ewolFont.h b/Sources/ewolFont.h index 4d194f49..e49c485b 100644 --- a/Sources/ewolFont.h +++ b/Sources/ewolFont.h @@ -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); diff --git a/Sources/ewolFontFreeType.cpp b/Sources/ewolFontFreeType.cpp index 5bf784e3..d5432766 100644 --- a/Sources/ewolFontFreeType.cpp +++ b/Sources/ewolFontFreeType.cpp @@ -202,15 +202,16 @@ class FTFontInternal } public: etk::String GetFontName(void) {return m_fontName;}; - bool GenerateBitmapFont(int32_t size, int32_t textureId, etk::VectorType & listElement) + bool GenerateBitmapFont(int32_t size, int32_t &height, int32_t textureId, etk::VectorType & 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 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 & 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(); +} \ No newline at end of file diff --git a/Sources/ewolOObject.cpp b/Sources/ewolOObject.cpp index d1821a36..56f0f074 100644 --- a/Sources/ewolOObject.cpp +++ b/Sources/ewolOObject.cpp @@ -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_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 m_coord; //!< internal coord of the object etk::VectorType 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 m_coord; //!< internal coord of the object etk::VectorType m_coordTex; //!< internal texture coordinate for every point + public: + virtual void UpdateOrigin(float x, float y); }; /* diff --git a/Sources/ewolWidget.cpp b/Sources/ewolWidget.cpp index 4bf78490..e25a6470 100644 --- a/Sources/ewolWidget.cpp +++ b/Sources/ewolWidget.cpp @@ -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); } diff --git a/Sources/ewolWidget.h b/Sources/ewolWidget.h index 6d56499d..1256f02d 100644 --- a/Sources/ewolWidget.h +++ b/Sources/ewolWidget.h @@ -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 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 diff --git a/Sources/ewolWindows.cpp b/Sources/ewolWindows.cpp index ff7b68b7..4039f08e 100644 --- a/Sources/ewolWindows.cpp +++ b/Sources/ewolWindows.cpp @@ -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 #endif - -#include -#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); +} + diff --git a/Sources/ewolWindows.h b/Sources/ewolWindows.h index fca3f684..4a3529d2 100644 --- a/Sources/ewolWindows.h +++ b/Sources/ewolWindows.h @@ -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); }; }; diff --git a/Sources/widget/ewolButton.cpp b/Sources/widget/ewolButton.cpp index e57430a0..860d079c 100644 --- a/Sources/widget/ewolButton.cpp +++ b/Sources/widget/ewolButton.cpp @@ -24,3 +24,75 @@ #include +#include + +#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"); +} diff --git a/Sources/widget/ewolButton.h b/Sources/widget/ewolButton.h index 7c9bc00f..5c82ee1a 100644 --- a/Sources/widget/ewolButton.h +++ b/Sources/widget/ewolButton.h @@ -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); }; }; diff --git a/Sources/widget/ewolCheckBox.cpp b/Sources/widget/ewolCheckBox.cpp index b25588dd..aeecd5a1 100644 --- a/Sources/widget/ewolCheckBox.cpp +++ b/Sources/widget/ewolCheckBox.cpp @@ -24,3 +24,6 @@ #include + +#undef __class__ +#define __class__ "ewol::CheckBox" diff --git a/Sources/widget/ewolEntry.cpp b/Sources/widget/ewolEntry.cpp index df78a963..e0312342 100644 --- a/Sources/widget/ewolEntry.cpp +++ b/Sources/widget/ewolEntry.cpp @@ -24,3 +24,6 @@ #include + +#undef __class__ +#define __class__ "ewol::Entry" diff --git a/Sources/widget/ewolList.cpp b/Sources/widget/ewolList.cpp index 63818f24..f95f4f7b 100644 --- a/Sources/widget/ewolList.cpp +++ b/Sources/widget/ewolList.cpp @@ -24,3 +24,7 @@ #include + +#undef __class__ +#define __class__ "ewol::List" + diff --git a/Sources/widget/ewolSizerHori.cpp b/Sources/widget/ewolSizerHori.cpp index b4dc9c17..6840eb08 100644 --- a/Sources/widget/ewolSizerHori.cpp +++ b/Sources/widget/ewolSizerHori.cpp @@ -26,10 +26,13 @@ #include +#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; iiiGetMinSize(); + 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; iiiGetMinSize(); + // 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; iiiCalculateMinSize(); + 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 m_SubWidget; void ewol::SizerHori::SubWidgetRemoveAll(void) { - for (int32_t iii=0; iiiSetParrent(this); } @@ -73,11 +165,13 @@ void ewol::SizerHori::SubWidgetRemove(ewol::Widget* newWidget) if (NULL == newWidget) { return; } - for (int32_t iii=0; iiiGenDraw(); + } + } + return true; +} + + +void ewol::SizerHori::OnRegenerateDisplay(void) +{ + for (int32_t iii=0; iiiOnRegenerateDisplay(); + } + } +} + + diff --git a/Sources/widget/ewolSizerHori.h b/Sources/widget/ewolSizerHori.h index 3af84afd..5aad7362 100644 --- a/Sources/widget/ewolSizerHori.h +++ b/Sources/widget/ewolSizerHori.h @@ -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 m_SubWidget; + etk::VectorType 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); }; }; diff --git a/Sources/widget/ewolSizerVert.cpp b/Sources/widget/ewolSizerVert.cpp index 7f8cdce2..9ae87538 100644 --- a/Sources/widget/ewolSizerVert.cpp +++ b/Sources/widget/ewolSizerVert.cpp @@ -24,3 +24,191 @@ #include + + +#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; iiiGetMinSize(); + 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; iiiGetMinSize(); + // 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; iiiCalculateMinSize(); + 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 m_SubWidget; + +void ewol::SizerVert::SubWidgetRemoveAll(void) +{ + for (int32_t iii=0; iiiSetParrent(this); +} + + +void ewol::SizerVert::SubWidgetRemove(ewol::Widget* newWidget) +{ + if (NULL == newWidget) { + return; + } + for (int32_t iii=0; iiiGenDraw(); + } + } + return true; +} + + + +void ewol::SizerVert::OnRegenerateDisplay(void) +{ + for (int32_t iii=0; iiiOnRegenerateDisplay(); + } + } +} + + diff --git a/Sources/widget/ewolSizerVert.h b/Sources/widget/ewolSizerVert.h index b9b3c64c..a37ce283 100644 --- a/Sources/widget/ewolSizerVert.h +++ b/Sources/widget/ewolSizerVert.h @@ -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 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); }; };