From 5ee58f35402ecbb27c1b4b62559de9c0ec3346fa Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Mon, 1 Feb 2016 23:50:01 +0100 Subject: [PATCH] [DEV] rework all the API of the sizing --- ewol/context/Context.cpp | 3 +- ewol/widget/Button.cpp | 12 +- ewol/widget/Button.h | 2 +- ewol/widget/CheckBox.cpp | 4 +- ewol/widget/CheckBox.h | 2 +- ewol/widget/Container.cpp | 52 +++--- ewol/widget/Container.h | 2 +- ewol/widget/Container2.cpp | 18 +-- ewol/widget/Container2.h | 7 +- ewol/widget/ContainerN.cpp | 14 +- ewol/widget/ContainerN.h | 2 +- ewol/widget/ContextMenu.cpp | 7 +- ewol/widget/ContextMenu.h | 2 +- ewol/widget/Gird.cpp | 6 +- ewol/widget/Gird.h | 2 +- ewol/widget/Joystick.cpp | 7 - ewol/widget/Joystick.h | 1 - ewol/widget/PopUp.cpp | 70 ++++----- ewol/widget/PopUp.h | 2 +- ewol/widget/Sizer.cpp | 304 ++++++++++++++---------------------- ewol/widget/Sizer.h | 2 +- ewol/widget/WSlider.cpp | 18 +-- ewol/widget/WSlider.h | 2 +- ewol/widget/Widget.cpp | 17 +- ewol/widget/Widget.h | 16 +- ewol/widget/Windows.cpp | 20 +-- ewol/widget/Windows.h | 2 +- 27 files changed, 243 insertions(+), 353 deletions(-) diff --git a/ewol/context/Context.cpp b/ewol/context/Context.cpp index 9586d73f..fc2755e3 100644 --- a/ewol/context/Context.cpp +++ b/ewol/context/Context.cpp @@ -460,7 +460,8 @@ void ewol::Context::forceRedrawAll() { return; } ivec2 size = getSize(); - m_windowsCurrent->calculateSize(vec2(size.x(), size.y())); + m_windowsCurrent->setSize(vec2(size.x(), size.y())); + m_windowsCurrent->onSizeChange(); } /* void ewol::Context::OS_Stop() { diff --git a/ewol/widget/Button.cpp b/ewol/widget/Button.cpp index 73af67b5..e6c5d831 100644 --- a/ewol/widget/Button.cpp +++ b/ewol/widget/Button.cpp @@ -62,20 +62,12 @@ ewol::widget::Button::~Button() { } - -void ewol::widget::Button::calculateSize(const vec2& _availlable) { +void ewol::widget::Button::onSizeChange() { ewol::Padding padding = m_shaper->getPadding(); - ewol::Padding ret = calculateSizePadded(_availlable, padding); + ewol::Padding ret = onSizeChangePadded(padding); //EWOL_DEBUG(" configuring : origin=" << origin << " size=" << subElementSize << ""); m_selectableAreaPos = vec2(ret.xLeft(), ret.yButtom()); m_selectableAreaSize = m_size - (m_selectableAreaPos + vec2(ret.xRight(), ret.yTop())); - - if (m_userExpand->x() == true) { - m_size.setX(std::max(m_size.x(), _availlable.x())); - } - if (m_userExpand->y() == true) { - m_size.setY(std::max(m_size.y(), _availlable.y())); - } } diff --git a/ewol/widget/Button.h b/ewol/widget/Button.h index 5017649a..fea5dd6b 100644 --- a/ewol/widget/Button.h +++ b/ewol/widget/Button.h @@ -155,7 +155,7 @@ namespace ewol { virtual void onParameterChangeValue(const ewol::parameter::Ref& _paramPointer); public: // Derived function virtual void calculateMinMaxSize(); - virtual void calculateSize(const vec2& _availlable); + virtual void onSizeChange(); virtual void onRegenerateDisplay(); virtual bool onEventInput(const ewol::event::Input& _event); virtual bool onEventEntry(const ewol::event::Entry& _event); diff --git a/ewol/widget/CheckBox.cpp b/ewol/widget/CheckBox.cpp index 71b482de..8d23c339 100644 --- a/ewol/widget/CheckBox.cpp +++ b/ewol/widget/CheckBox.cpp @@ -55,11 +55,11 @@ ewol::widget::CheckBox::~CheckBox() { } -void ewol::widget::CheckBox::calculateSize(const vec2& _availlable) { +void ewol::widget::CheckBox::onSizeChange() { ewol::Padding padding = m_shaper->getPadding(); float boxSize = m_shaper->getConfigNumber(m_shaperIdSize); padding.setXLeft(padding.xLeft()*2.0f + boxSize); - ewol::Padding ret = calculateSizePadded(_availlable, padding); + ewol::Padding ret = onSizeChangePadded(padding); EWOL_DEBUG(" configuring : padding=" << padding << " boxSize=" << boxSize << ""); m_selectableAreaPos = vec2(ret.xLeft()/*-boxSize*/, ret.yButtom()); m_selectableAreaSize = m_size - (m_selectableAreaPos + vec2(ret.xRight(), ret.yTop())); diff --git a/ewol/widget/CheckBox.h b/ewol/widget/CheckBox.h index 6c49d7fc..a76dd160 100644 --- a/ewol/widget/CheckBox.h +++ b/ewol/widget/CheckBox.h @@ -90,7 +90,7 @@ namespace ewol { virtual void onParameterChangeValue(const ewol::parameter::Ref& _paramPointer); public: // Derived function virtual void calculateMinMaxSize(); - virtual void calculateSize(const vec2& _availlable); + virtual void onSizeChange(); virtual void onRegenerateDisplay(); virtual bool onEventInput(const ewol::event::Input& _event); virtual bool onEventEntry(const ewol::event::Entry& _event); diff --git a/ewol/widget/Container.cpp b/ewol/widget/Container.cpp index 64184ac9..56d867e5 100644 --- a/ewol/widget/Container.cpp +++ b/ewol/widget/Container.cpp @@ -104,31 +104,33 @@ void ewol::widget::Container::systemDraw(const ewol::DrawProperty& _displayProp) } } -void ewol::widget::Container::calculateSize(const vec2& _availlable) { - if (nullptr!=m_subWidget) { - vec2 origin = m_origin+m_offset; - vec2 minSize = m_subWidget->getCalculateMinSize(); - bvec2 expand = m_subWidget->getExpand(); - if ( expand.x() == false - || minSize.x()>_availlable.x()) { - if (m_gravity == ewol::gravityCenter) { - origin -= vec2((minSize.x() - _availlable.x())/2.0f, 0); - } else if (((int32_t)m_gravity & (int32_t)ewol::gravityRight) != 0) { - origin -= vec2((minSize.x() - _availlable.x()), 0); - } - } - if( expand.y() == false - || minSize.y()>_availlable.y()) { - if (m_gravity == ewol::gravityCenter) { - origin -= vec2(0, (minSize.y() - _availlable.y())/2.0f); - } else if (((int32_t)m_gravity & (int32_t)ewol::gravityTop) != 0) { - origin -= vec2(0, (minSize.y() - _availlable.y())); - } - } - m_subWidget->setOrigin(origin); - m_subWidget->calculateSize(_availlable); +void ewol::widget::Container::onSizeChange() { + ewol::Widget::onSizeChange(); + if (m_subWidget == nullptr) { + return; } - ewol::Widget::calculateSize(_availlable); + vec2 origin = m_origin+m_offset; + vec2 minSize = m_subWidget->getCalculateMinSize(); + bvec2 expand = m_subWidget->getExpand(); + if ( expand.x() == false + || minSize.x()>m_size.x()) { + if (m_gravity == ewol::gravityCenter) { + origin -= vec2((minSize.x() - m_size.x())*0.5f, 0.0f); + } else if (((int32_t)m_gravity & (int32_t)ewol::gravityRight) != 0) { + origin -= vec2((minSize.x() - m_size.x()), 0.0f); + } + } + if( expand.y() == false + || minSize.y()>m_size.y()) { + if (m_gravity == ewol::gravityCenter) { + origin -= vec2(0.0f, (minSize.y() - m_size.y())*0.5f); + } else if (((int32_t)m_gravity & (int32_t)ewol::gravityTop) != 0) { + origin -= vec2(0.0f, (minSize.y() - m_size.y())); + } + } + m_subWidget->setOrigin(origin); + m_subWidget->setSize(m_size); + m_subWidget->onSizeChange(); } void ewol::widget::Container::calculateMinMaxSize() { @@ -203,7 +205,7 @@ void ewol::widget::Container::setOffset(const vec2& _newVal) { if (m_offset != _newVal) { ewol::Widget::setOffset(_newVal); // recalculate the new sise and position of sub widget ... - calculateSize(m_size); + onSizeChange(); } } diff --git a/ewol/widget/Container.h b/ewol/widget/Container.h index 310781fb..d9f63082 100644 --- a/ewol/widget/Container.h +++ b/ewol/widget/Container.h @@ -62,7 +62,7 @@ namespace ewol { public: // Derived function virtual void systemDraw(const ewol::DrawProperty& _displayProp); virtual void onRegenerateDisplay(); - virtual void calculateSize(const vec2& _availlable); + virtual void onSizeChange(); virtual void calculateMinMaxSize(); virtual std::shared_ptr getWidgetAtPos(const vec2& _pos); virtual std::shared_ptr getSubObjectNamed(const std::string& _objectName); diff --git a/ewol/widget/Container2.cpp b/ewol/widget/Container2.cpp index 5db91e0c..8c7fcddc 100644 --- a/ewol/widget/Container2.cpp +++ b/ewol/widget/Container2.cpp @@ -114,16 +114,9 @@ void ewol::widget::Container2::systemDraw(const ewol::DrawProperty& _displayProp } } -ewol::Padding ewol::widget::Container2::calculateSizePadded(const vec2& _availlable, const ewol::Padding& _padding) { - vec2 localAvaillable = _availlable - vec2(_padding.x(), _padding.y()); - ewol::Widget::calculateSize(_availlable); - // set minimal size - if (m_userExpand->x() == true) { - m_size.setX(_availlable.x()); - } - if (m_userExpand->y() == true) { - m_size.setY(_availlable.y()); - } +ewol::Padding ewol::widget::Container2::onSizeChangePadded(const ewol::Padding& _padding) { + ewol::Widget::onSizeChange(); + vec2 localAvaillable = m_size - vec2(_padding.x(), _padding.y()); // Checkin the filling properties == > for the subElements: vec2 subElementSize = m_minSize; if (m_userFill->x() == true) { @@ -156,7 +149,8 @@ ewol::Padding ewol::widget::Container2::calculateSizePadded(const vec2& _availla } } m_subWidget[iii]->setOrigin(m_origin + origin); - m_subWidget[iii]->calculateSize(subElementSize); + m_subWidget[iii]->setSize(subElementSize); + m_subWidget[iii]->onSizeChange(); } } vec2 selectableAreaPos = origin-vec2(_padding.xLeft(), _padding.yButtom()); @@ -252,7 +246,7 @@ void ewol::widget::Container2::setOffset(const vec2& _newVal) { if (m_offset != _newVal) { ewol::Widget::setOffset(_newVal); // recalculate the new sise and position of sub widget ... - calculateSize(m_size); + calculateSize(); } } diff --git a/ewol/widget/Container2.h b/ewol/widget/Container2.h index c9773366..f65dd697 100644 --- a/ewol/widget/Container2.h +++ b/ewol/widget/Container2.h @@ -125,11 +125,10 @@ namespace ewol { /** * @brief Parent set the possible diplay size of the current widget whith his own possibilities * By default this save the widget available size in the widget size - * @param[in] _available Available x&y pixel size * @param[in] _padding Padding of the widget. * @note : INTERNAL EWOL SYSTEM */ - virtual ewol::Padding calculateSizePadded(const vec2& _availlable, const ewol::Padding& _padding = ewol::Padding(0,0,0,0)); + virtual ewol::Padding onSizeChangePadded(const ewol::Padding& _padding = ewol::Padding(0,0,0,0)); /** * @brief calculate the minimum and maximum size (need to estimate expend properties of the widget) * @param[in] _padding Padding of the widget. @@ -161,8 +160,8 @@ namespace ewol { public: // Derived function virtual void systemDraw(const ewol::DrawProperty& _displayProp); virtual void onRegenerateDisplay(); - virtual void calculateSize(const vec2& _availlable) { - calculateSizePadded(_availlable); + virtual void onSizeChange() { + onSizeChangePadded(); } virtual void calculateMinMaxSize() { calculateMinMaxSizePadded(); diff --git a/ewol/widget/ContainerN.cpp b/ewol/widget/ContainerN.cpp index 8bf4939b..97cd8e71 100644 --- a/ewol/widget/ContainerN.cpp +++ b/ewol/widget/ContainerN.cpp @@ -195,15 +195,15 @@ void ewol::widget::ContainerN::systemDraw(const ewol::DrawProperty& _displayProp } } -void ewol::widget::ContainerN::calculateSize(const vec2& _availlable) { - m_size = _availlable; +void ewol::widget::ContainerN::onSizeChange() { for (auto &it : m_subWidget) { - if (it != nullptr) { - it->setOrigin(m_origin+m_offset); - it->calculateSize(m_size); + if (it == nullptr) { + continue; } + it->setOrigin(m_origin+m_offset); + it->setSize(m_size); + it->onSizeChange(); } - markToRedraw(); } void ewol::widget::ContainerN::calculateMinMaxSize() { @@ -317,7 +317,7 @@ void ewol::widget::ContainerN::setOffset(const vec2& _newVal) { if (m_offset != _newVal) { ewol::Widget::setOffset(_newVal); // recalculate the new sise and position of sub widget ... - calculateSize(m_size); + onSizeChange(); } } diff --git a/ewol/widget/ContainerN.h b/ewol/widget/ContainerN.h index 816aa9cb..d640d994 100644 --- a/ewol/widget/ContainerN.h +++ b/ewol/widget/ContainerN.h @@ -98,7 +98,7 @@ namespace ewol { public:// Derived function virtual void systemDraw(const ewol::DrawProperty& _displayProp); virtual void onRegenerateDisplay(); - virtual void calculateSize(const vec2& _availlable); + virtual void onSizeChange(); virtual void calculateMinMaxSize(); virtual std::shared_ptr getWidgetAtPos(const vec2& _pos); virtual std::shared_ptr getSubObjectNamed(const std::string& _objectName); diff --git a/ewol/widget/ContextMenu.cpp b/ewol/widget/ContextMenu.cpp index 48c3d517..ad374ba8 100644 --- a/ewol/widget/ContextMenu.cpp +++ b/ewol/widget/ContextMenu.cpp @@ -49,10 +49,8 @@ ewol::widget::ContextMenu::~ContextMenu() { } -void ewol::widget::ContextMenu::calculateSize(const vec2& _availlable) { - //EWOL_DEBUG("CalculateSize=" << availlable); +void ewol::widget::ContextMenu::onSizeChange() { // pop-up fill all the display : - m_size = _availlable; ewol::Padding padding = m_shaper->getPadding(); EWOL_VERBOSE("our origin=" << m_origin << " size=" << m_size); if (nullptr != m_subWidget) { @@ -110,7 +108,8 @@ void ewol::widget::ContextMenu::calculateSize(const vec2& _availlable) { } EWOL_VERBOSE(" == > sub origin=" << subWidgetOrigin << " size=" << subWidgetSize); m_subWidget->setOrigin(subWidgetOrigin); - m_subWidget->calculateSize(subWidgetSize); + m_subWidget->setSize(subWidgetSize); + m_subWidget->onSizeChange(); } markToRedraw(); } diff --git a/ewol/widget/ContextMenu.h b/ewol/widget/ContextMenu.h index d8494f9e..98a1ab93 100644 --- a/ewol/widget/ContextMenu.h +++ b/ewol/widget/ContextMenu.h @@ -67,7 +67,7 @@ namespace ewol { public: // Derived function virtual void onRegenerateDisplay(); virtual bool onEventInput(const ewol::event::Input& _event); - virtual void calculateSize(const vec2& _availlable); + virtual void onSizeChange(); virtual void calculateMinMaxSize(); virtual std::shared_ptr getWidgetAtPos(const vec2& _pos); }; diff --git a/ewol/widget/Gird.cpp b/ewol/widget/Gird.cpp index e1ae0495..1a385f51 100644 --- a/ewol/widget/Gird.cpp +++ b/ewol/widget/Gird.cpp @@ -47,9 +47,8 @@ void ewol::widget::Gird::setBorderSize(const ivec2& _newBorderSize) { requestUpdateSize(); } -void ewol::widget::Gird::calculateSize(const vec2& _availlable) { +void ewol::widget::Gird::onSizeChange() { //EWOL_DEBUG("Update size"); - m_size = _availlable; m_size -= m_borderSize*2; for (size_t iii=0; iiisetOrigin(vec2ClipInt32(tmpOrigin)); // all time set oll the space . - m_subWidget[iii].widget->calculateSize(vec2ClipInt32(vec2(abs(m_sizeCol[m_subWidget[iii].col]), m_uniformSizeRow))); + m_subWidget[iii].widget->setSize(vec2ClipInt32(vec2(abs(m_sizeCol[m_subWidget[iii].col]), m_uniformSizeRow))); + m_subWidget[iii].widget->onSizeChange(); } } m_size += m_borderSize*2; diff --git a/ewol/widget/Gird.h b/ewol/widget/Gird.h index 5a0b1a6b..aa2ac3ca 100644 --- a/ewol/widget/Gird.h +++ b/ewol/widget/Gird.h @@ -140,7 +140,7 @@ namespace ewol { virtual void systemDraw(const ewol::DrawProperty& _displayProp); virtual void onRegenerateDisplay(); virtual std::shared_ptr getWidgetAtPos(const vec2& pos); - virtual void calculateSize(const vec2& _availlable); + virtual void onSizeChange(); virtual void calculateMinMaxSize(); }; }; diff --git a/ewol/widget/Joystick.cpp b/ewol/widget/Joystick.cpp index 76b89f32..584cbacb 100644 --- a/ewol/widget/Joystick.cpp +++ b/ewol/widget/Joystick.cpp @@ -55,13 +55,6 @@ ewol::widget::Joystick::~Joystick() { } - -void ewol::widget::Joystick::calculateSize(const vec2& availlable) { - float minimumSize = std::min(availlable.x(), availlable.y()); - m_size.setValue(minimumSize, minimumSize); - markToRedraw(); -} - void ewol::widget::Joystick::onRegenerateDisplay() { if (true == needRedraw()) { // clean the object list ... diff --git a/ewol/widget/Joystick.h b/ewol/widget/Joystick.h index 0336e9c1..41e997f8 100644 --- a/ewol/widget/Joystick.h +++ b/ewol/widget/Joystick.h @@ -83,7 +83,6 @@ namespace ewol { void getProperty(float& _distance, float& _angle); public: // Derived function - virtual void calculateSize(const vec2& _availlable); virtual void onRegenerateDisplay(); virtual bool onEventInput(const ewol::event::Input& _event); }; diff --git a/ewol/widget/PopUp.cpp b/ewol/widget/PopUp.cpp index a1e35f49..0ae751a8 100644 --- a/ewol/widget/PopUp.cpp +++ b/ewol/widget/PopUp.cpp @@ -43,45 +43,39 @@ void ewol::widget::PopUp::setShaperName(const std::string& _shaperName) { markToRedraw(); } -void ewol::widget::PopUp::calculateSize(const vec2& _available) { - #if 0 - //not call basic class ==> change methode to generate basic size ... - ewol::Widget::calculateSize(_available); - #else - vec2 size = _available; - size.setMax(m_minSize); - m_size = size; - #endif - if (nullptr != m_subWidget) { - ewol::Padding padding = m_shaper->getPadding(); - vec2 subWidgetSize = m_subWidget->getCalculateMinSize(); - if (true == m_subWidget->canExpand().x()) { - if (m_lockExpand->x() == true) { - subWidgetSize.setX(m_minSize.x()); - } else { - subWidgetSize.setX(m_size.x()-padding.xLeft()); - } - } - if (true == m_subWidget->canExpand().y()) { - if (m_lockExpand->y() == true) { - subWidgetSize.setY(m_minSize.y()); - } else { - subWidgetSize.setY(m_size.y()-padding.yButtom()); - } - } - // limit the size of the element : - //subWidgetSize.setMin(m_minSize); - // posiition at a int32_t pos : - subWidgetSize = vec2ClipInt32(subWidgetSize); - - // set config to the Sub-widget - vec2 subWidgetOrigin = m_origin + (m_size-subWidgetSize)/2.0f; - subWidgetOrigin = vec2ClipInt32(subWidgetOrigin); - - m_subWidget->setOrigin(subWidgetOrigin); - m_subWidget->calculateSize(subWidgetSize); - } +void ewol::widget::PopUp::onSizeChange() { markToRedraw(); + if (nullptr == m_subWidget) { + return; + } + ewol::Padding padding = m_shaper->getPadding(); + vec2 subWidgetSize = m_subWidget->getCalculateMinSize(); + if (true == m_subWidget->canExpand().x()) { + if (m_lockExpand->x() == true) { + subWidgetSize.setX(m_minSize.x()); + } else { + subWidgetSize.setX(m_size.x()-padding.xLeft()); + } + } + if (true == m_subWidget->canExpand().y()) { + if (m_lockExpand->y() == true) { + subWidgetSize.setY(m_minSize.y()); + } else { + subWidgetSize.setY(m_size.y()-padding.yButtom()); + } + } + // limit the size of the element : + //subWidgetSize.setMin(m_minSize); + // posiition at a int32_t pos : + subWidgetSize = vec2ClipInt32(subWidgetSize); + + // set config to the Sub-widget + vec2 subWidgetOrigin = m_origin + (m_size-subWidgetSize)/2.0f; + subWidgetOrigin = vec2ClipInt32(subWidgetOrigin); + + m_subWidget->setOrigin(subWidgetOrigin); + m_subWidget->setSize(subWidgetSize); + m_subWidget->onSizeChange(); } void ewol::widget::PopUp::systemDraw(const ewol::DrawProperty& _displayProp) { diff --git a/ewol/widget/PopUp.h b/ewol/widget/PopUp.h index cd6d1af8..ebca5f67 100644 --- a/ewol/widget/PopUp.h +++ b/ewol/widget/PopUp.h @@ -77,7 +77,7 @@ namespace ewol { virtual void periodicCall(const ewol::event::Time& _event); virtual void systemDraw(const ewol::DrawProperty& _displayProp); virtual void onRegenerateDisplay(); - virtual void calculateSize(const vec2& _available); + virtual void onSizeChange(); virtual bool onEventInput(const ewol::event::Input& _event); virtual std::shared_ptr getWidgetAtPos(const vec2& _pos); protected: diff --git a/ewol/widget/Sizer.cpp b/ewol/widget/Sizer.cpp index a6a65b9a..641fa8cd 100644 --- a/ewol/widget/Sizer.cpp +++ b/ewol/widget/Sizer.cpp @@ -37,210 +37,136 @@ ewol::widget::Sizer::~Sizer() { } -void ewol::widget::Sizer::calculateSize(const vec2& _availlable) { - ewol::Widget::calculateSize(_availlable); +void ewol::widget::Sizer::onSizeChange() { + ewol::Widget::onSizeChange(); vec2 tmpBorderSize = m_borderSize->getPixel(); - EWOL_VERBOSE("[" << getId() << "] update size : " << _availlable << " nbElement : " << m_subWidget.size() << " borderSize=" << tmpBorderSize << " from border=" << m_borderSize); - #if 1 - vec2 localWidgetSize = m_size - tmpBorderSize*2.0f; - // -1- calculate min-size and expand requested: - vec2 minSize(0.0f, 0.0f); - ivec2 nbWidgetExpand(0,0); + EWOL_VERBOSE("[" << getId() << "] update size : " << m_size << " nbElement : " << m_subWidget.size() << " borderSize=" << tmpBorderSize << " from border=" << m_borderSize); + vec2 localWidgetSize = m_size - tmpBorderSize*2.0f; + // -1- calculate min-size and expand requested: + vec2 minSize(0.0f, 0.0f); + ivec2 nbWidgetExpand(0,0); + for (auto &it : m_subWidget) { + if (it == nullptr) { + continue; + } + vec2 tmpSize = it->getCalculateMinSize(); + if (m_mode == ewol::widget::Sizer::modeVert) { + minSize = vec2(std::max(minSize.x(), tmpSize.x()), + minSize.x() + tmpSize.y()); + } else { + minSize = vec2(minSize.y() + tmpSize.y(), + std::max(minSize.y(), tmpSize.y())); + } + bvec2 expand = it->canExpand(); + nbWidgetExpand += ivec2(expand.x()==true?1:0, + expand.y()==true?1:0); + } + // -2- Calculate the size to add at every elements... + float deltaExpandSize = 0.0f; + if (nbWidgetExpand != ivec2(0,0)) { + if (m_mode == ewol::widget::Sizer::modeVert) { + deltaExpandSize = (localWidgetSize.y() - minSize.y()) / float(nbWidgetExpand.y()); + } else { + deltaExpandSize = (localWidgetSize.x() - minSize.x()) / float(nbWidgetExpand.x()); + } + if (deltaExpandSize<0.0) { + deltaExpandSize=0; + } + } + // -3- Configure all at the min size ... + for (auto &it : m_subWidget) { + if (it == nullptr) { + continue; + } + it->setSize(it->getCalculateMinSize()); + } + // -4- For each element we apply the minmax range and update if needed + while (deltaExpandSize > 0.0001f) { + float residualNext = 0.0f; + // get the number of element that need to devide... + int32_t countCalculation = nbWidgetExpand.x(); + if (m_mode == ewol::widget::Sizer::modeVert) { + countCalculation = nbWidgetExpand.y(); + } + // -4.1- Update every subWidget size for (auto &it : m_subWidget) { if (it == nullptr) { continue; } - vec2 tmpSize = it->getCalculateMinSize(); + vec2 tmpSizeMin = it->getSize(); + vec2 tmpSizeMax = it->getCalculateMaxSize(); + // Now update his size his size in X and the curent sizer size in Y: if (m_mode == ewol::widget::Sizer::modeVert) { - minSize = vec2(std::max(minSize.x(), tmpSize.x()), - minSize.x() + tmpSize.y()); - } else { - minSize = vec2(minSize.y() + tmpSize.y(), - std::max(minSize.y(), tmpSize.y())); - } - bvec2 expand = it->canExpand(); - nbWidgetExpand += ivec(expand.x()==true?1:0, - expand.y()==true?1:0); - } - // -2- Calculate the size to add at every elements... - float deltaExpandSize = 0.0f; - if (nbWidgetNotFixedSize != ivec2(0,0)) { - if (m_mode == ewol::widget::Sizer::modeVert) { - deltaExpandSize = (localWidgetSize.y() - minSize.y()) / float(nbWidgetExpand.y()); - } else { - deltaExpandSize = (localWidgetSize.x() - minSize.x()) / float(nbWidgetExpand.x()); - } - if (deltaExpandSize<0.0) { - deltaExpandSize=0; - } - } - // -3- Configure all at the min size ... - for (auto &it : m_subWidget) { - if (it == nullptr) { - continue; - } - it->ParrentSetSize(it->getCalculateMinSize()); - } - // -4- For each element we apply the minmax range and update if needed - while (deltaExpandSize > 0.0001f) { - float residualNext = 0.0f; - // get the number of element that need to devide... - int32_t countCalculation = nbWidgetExpand.x(); - if (m_mode == ewol::widget::Sizer::modeVert) { - countCalculation = nbWidgetExpand.y(); - } - // -4.1- Update every subWidget size - for (auto &it : m_subWidget) { - if (it == nullptr) { - continue; - } - vec2 tmpSizeMin = it->getSize(); - vec2 tmpSizeMax = it->getCalculateMaxSize(); - // Now update his size his size in X and the curent sizer size in Y: - if (m_mode == ewol::widget::Sizer::modeVert) { - if (it->canExpand().y() == true) { - float sizeExpand = tmpSizeMin.y() + deltaExpandSize; - if (sizeExpand > tmpSizeMax.y()) { - residualNext += (sizeExpand - tmpSizeMax.y()); - sizeExpand = tmpSizeMax.y(); - countCalculation--; - } - tmpSizeMin.setY(sizeExpand); - } - if (it->canExpand().x() == true) { - float sizeExpand = etk::avg(tmpSizeMin.x(), minSize.x(), tmpSizeMax.x()); - tmpSizeMin.setX(sizeExpand); - } - it->parrentSetSize(tmpSizeMin); - } else { - if (it->canExpand().x() == true) { - float sizeExpand = tmpSizeMin.x() + deltaExpandSize; - if (sizeExpand > tmpSizeMax.x()) { - residualNext += (sizeExpand - tmpSizeMax.x()); - sizeExpand = tmpSizeMax.x(); - countCalculation--; - } - tmpSizeMin.setX(sizeExpand); - } - if (it->canExpand().y() == true) { - float sizeExpand = etk::avg(tmpSizeMin.y(), minSize.y(), tmpSizeMax.y()); - tmpSizeMin.setY(sizeExpand); - } - it->parrentSetSize(tmpSizeMin); - } - } - // Reset size add ... - deltaExpandSize = 0.0f; - if (residualNext < 0.0001f) { - break; - } - if (countCalculation <= 0) { - break; - } - if (m_mode == ewol::widget::Sizer::modeVert) { - deltaExpandSize = residualNext / float(countCalculation); - } else { - deltaExpandSize = residualNext / float(countCalculation); - } - if (deltaExpandSize<0.0f) { - deltaExpandSize=0.0f; - break; - } - } - // -5- Set the origin for every element with the gravity update: - for (auto &it : m_subWidget) { - if (it == nullptr) { - continue; - } - // TODO : Set origin with the correct gravity - - } - #else - m_size -= tmpBorderSize*2.0f; - // calculate unExpandable size : - float unexpandableSize=0.0; - ivec2 nbWidgetNotFixedSize = ivec2(0,0); - for (auto &it : m_subWidget) { - if (it == nullptr) { - continue; - } - vec2 tmpSize = it->getCalculateMinSize(); - if (m_mode == ewol::widget::Sizer::modeVert) { - unexpandableSize += tmpSize.y(); if (it->canExpand().y() == true) { - nbWidgetNotFixedSize+=ivec2(0,1); + float sizeExpand = tmpSizeMin.y() + deltaExpandSize; + if (sizeExpand > tmpSizeMax.y()) { + residualNext += (sizeExpand - tmpSizeMax.y()); + sizeExpand = tmpSizeMax.y(); + countCalculation--; + } + tmpSizeMin.setY(sizeExpand); } - } else { - unexpandableSize += tmpSize.x(); if (it->canExpand().x() == true) { - nbWidgetNotFixedSize+=ivec2(1,0); + float sizeExpand = std::avg(tmpSizeMin.x(), minSize.x(), tmpSizeMax.x()); + tmpSizeMin.setX(sizeExpand); } - } - } - // 2 cases : 1 or more can Expand, or all is done ... - float sizeToAddAtEveryOne = 0; - // 2 cases : 1 or more can Expand, or all is done ... - if (nbWidgetNotFixedSize != ivec2(0,0)) { - if (m_mode == ewol::widget::Sizer::modeVert) { - sizeToAddAtEveryOne = (m_size.y() - unexpandableSize) / float(nbWidgetNotFixedSize.y()); + it->setSize(tmpSizeMin); } else { - sizeToAddAtEveryOne = (m_size.x() - unexpandableSize) / float(nbWidgetNotFixedSize.x()); - } - if (sizeToAddAtEveryOne<0.0) { - sizeToAddAtEveryOne=0; - } - } - // TODO : Need manage gravity ... - vec2 tmpOrigin = m_origin + tmpBorderSize; - for (auto &it : m_subWidget) { - if (it != nullptr) { - vec2 tmpSize = it->getCalculateMinSize(); - // set the origin : - EWOL_VERBOSE("[" << getId() << "] set ORIGIN : " << tmpOrigin << " & offset=" << m_offset); - it->setOrigin(vec2ClipInt32(tmpOrigin+m_offset)); - // Now update his size his size in X and the curent sizer size in Y: - if (m_mode == ewol::widget::Sizer::modeVert) { - if (it->canExpand().y() == true) { - vec2 expectedSize = vec2ClipInt32(vec2(m_size.x(), tmpSize.y()+sizeToAddAtEveryOne)); - it->calculateSize(expectedSize); - vec2 underSize = it->getSize(); - if (it->canExpand().x() == true) { - if (underSize.x() < expectedSize.x()) { - EWOL_WARNING("Subwidget request exapnd and does not expand ... ==> rules impose it ..."); - //it->setSize(vec2(expectedSize.x(), underSize.y()); - //underSize = it->getSize(); - } - } - if (it->canExpand().y() == true) { - if (underSize.y() < expectedSize.y()) { - EWOL_WARNING("Subwidget request exapnd and does not expand ... ==> rules impose it ..."); - //it->setSize(vec2(underSize.y(), expectedSize.x()); - } - } - tmpOrigin.setY(tmpOrigin.y() + tmpSize.y()+sizeToAddAtEveryOne); - } else { - it->calculateSize(vec2ClipInt32(vec2(m_size.x(), tmpSize.y()))); - tmpOrigin.setY(tmpOrigin.y() + tmpSize.y()); - } - } else { - if (it->canExpand().x() == true) { - it->calculateSize(vec2ClipInt32(vec2(tmpSize.x()+sizeToAddAtEveryOne, m_size.y()))); - tmpOrigin.setX(tmpOrigin.x() + tmpSize.x()+sizeToAddAtEveryOne); - } else { - it->calculateSize(vec2ClipInt32(vec2(tmpSize.x(), m_size.y()))); - - int32_t subSize = it->getSize().y(); - if (subSize <= m_size.y()) { - // move localy of half needed - it->setOrigin(it->getOrigin() + ivec2(0, (m_size.y()-subSize)/2)); - } - tmpOrigin.setX(tmpOrigin.x() + tmpSize.x()); + if (it->canExpand().x() == true) { + float sizeExpand = tmpSizeMin.x() + deltaExpandSize; + if (sizeExpand > tmpSizeMax.x()) { + residualNext += (sizeExpand - tmpSizeMax.x()); + sizeExpand = tmpSizeMax.x(); + countCalculation--; } + tmpSizeMin.setX(sizeExpand); } + if (it->canExpand().y() == true) { + float sizeExpand = std::avg(tmpSizeMin.y(), minSize.y(), tmpSizeMax.y()); + tmpSizeMin.setY(sizeExpand); + } + it->setSize(tmpSizeMin); } } - m_size += tmpBorderSize*2; - #endif + // Reset size add ... + deltaExpandSize = 0.0f; + if (residualNext < 0.0001f) { + break; + } + if (countCalculation <= 0) { + break; + } + if (m_mode == ewol::widget::Sizer::modeVert) { + deltaExpandSize = residualNext / float(countCalculation); + } else { + deltaExpandSize = residualNext / float(countCalculation); + } + if (deltaExpandSize<0.0f) { + deltaExpandSize=0.0f; + break; + } + } + // -5- Set the origin for every element with the gravity update: + vec2 tmpOrigin = m_origin + tmpBorderSize; + for (auto &it : m_subWidget) { + if (it == nullptr) { + continue; + } + it->setOrigin(vec2ClipInt32(tmpOrigin+m_offset)); + vec2 size = it->getSize(); + if (m_mode == ewol::widget::Sizer::modeVert) { + tmpOrigin.setY(tmpOrigin.y() + size.y()); + } else { + tmpOrigin.setX(tmpOrigin.x() + size.x()); + } + // TODO : Set origin with the correct gravity + } + for (auto &it : m_subWidget) { + if (it == nullptr) { + continue; + } + it->onSizeChange(); + } markToRedraw(); } diff --git a/ewol/widget/Sizer.h b/ewol/widget/Sizer.h index e0d94dcc..0160c00c 100644 --- a/ewol/widget/Sizer.h +++ b/ewol/widget/Sizer.h @@ -141,7 +141,7 @@ namespace ewol { private: ewol::compositing::Drawing m_draw; //!< Compositing drawing element for display the border. public: // Derived function - virtual void calculateSize(const vec2& _availlable); + virtual void onSizeChange(); virtual void calculateMinMaxSize(); // overwrite the set fuction to start annimations ... virtual int32_t subWidgetAdd(std::shared_ptr _newWidget); diff --git a/ewol/widget/WSlider.cpp b/ewol/widget/WSlider.cpp index da8d8f9b..18ae53c2 100644 --- a/ewol/widget/WSlider.cpp +++ b/ewol/widget/WSlider.cpp @@ -43,17 +43,16 @@ ewol::widget::WSlider::~WSlider() { } -void ewol::widget::WSlider::calculateSize(const vec2& _availlable) { - //EWOL_DEBUG("Update size"); - ewol::widget::ContainerN::calculateSize(_availlable); - +void ewol::widget::WSlider::onSizeChange() { + ewol::widget::ContainerN::onSizeChange(); if (m_windowsDestination == m_windowsSources) { auto it = m_subWidget.begin(); std::advance(it, m_windowsDestination); if ( it != m_subWidget.end() && *it != nullptr) { (*it)->setOrigin(m_origin+m_offset); - (*it)->calculateSize(m_size); + (*it)->setSize(m_size); + (*it)->onSizeChange(); } } else { float factor = -1.0f; @@ -73,7 +72,8 @@ void ewol::widget::WSlider::calculateSize(const vec2& _availlable) { m_origin.y() + factor*(m_size.y()*m_slidingProgress)) + m_offset); } - (*it)->calculateSize(m_size); + (*it)->setSize(m_size); + (*it)->onSizeChange(); } it = m_subWidget.begin(); std::advance(it, m_windowsDestination); @@ -88,7 +88,8 @@ void ewol::widget::WSlider::calculateSize(const vec2& _availlable) { m_origin.y() + factor*(m_size.y()*m_slidingProgress - m_size.y())) + m_offset); } - (*it)->calculateSize(m_size); + (*it)->setSize(m_size); + (*it)->onSizeChange(); } } markToRedraw(); @@ -204,8 +205,7 @@ void ewol::widget::WSlider::periodicCall(const ewol::event::Time& _event) { m_slidingProgress += _event.getDeltaCall()/m_transitionSpeed; m_slidingProgress = std::avg(0.0f, m_slidingProgress, 1.0f); } - calculateSize(m_size); - markToRedraw(); + onSizeChange(); } void ewol::widget::WSlider::systemDraw(const ewol::DrawProperty& _displayProp) { diff --git a/ewol/widget/WSlider.h b/ewol/widget/WSlider.h index f168e066..aff85aad 100644 --- a/ewol/widget/WSlider.h +++ b/ewol/widget/WSlider.h @@ -101,7 +101,7 @@ namespace ewol { return m_transitionSlide; }; public: // Derived function - virtual void calculateSize(const vec2& _availlable); + virtual void onSizeChange(); virtual void systemDraw(const ewol::DrawProperty& _displayProp); virtual void onRegenerateDisplay(); virtual std::shared_ptr getWidgetAtPos(const vec2& _pos); diff --git a/ewol/widget/Widget.cpp b/ewol/widget/Widget.cpp index 674f2998..e5e0cf96 100644 --- a/ewol/widget/Widget.cpp +++ b/ewol/widget/Widget.cpp @@ -146,22 +146,7 @@ ewol::Widget::~Widget() { shortCutClean(); } -void ewol::Widget::calculateSize(const vec2& _available) { - vec2 size = _available; - if (m_userFill->x() == true) { - size.setX(std::max(size.x(), m_minSize.x())); - } else { - size.setX(std::min(size.x(), m_minSize.x())); - } - if (m_userFill->y() == true) { - size.setY(std::max(size.y(), m_minSize.y())); - } else { - size.setY(std::min(size.y(), m_minSize.y())); - } - if (m_size == size) { - return; - } - m_size = size; +void ewol::Widget::onSizeChange() { markToRedraw(); } diff --git a/ewol/widget/Widget.h b/ewol/widget/Widget.h index efc4acf5..5864b8cb 100644 --- a/ewol/widget/Widget.h +++ b/ewol/widget/Widget.h @@ -150,19 +150,23 @@ namespace ewol { */ virtual vec2 relativePosition(const vec2& _pos); /** - * @brief Parent set the possible diplay size of the current widget whith his own possibilities - * By default this save the widget available size in the widget size - * @param[in] _available Available x&y pixel size + * @brief Parent have set the size and the origin. the container need to update the subwidget property * @note : INTERNAL EWOL SYSTEM */ - virtual void calculateSize(const vec2& _available); + virtual void onSizeChange(); + virtual void calculateSize() {}; /** * @brief get the widget size * @return Requested size * @note : INTERNAL EWOL SYSTEM */ virtual vec2 getSize(); - virtual void parrentSetSize(const vec2& _value) { + /** + * @brief set the widget size + * @return Requested size + * @note : INTERNAL EWOL SYSTEM Do not modify the size yourself: calculation is complex and need knowledge of around widget + */ + virtual void setSize(const vec2& _value) { m_size = _value; } /** @@ -672,7 +676,7 @@ namespace ewol { virtual void onParameterChangeValue(const ewol::parameter::Ref& _paramPointer); public: /** - * @brief need to be call When the size of the current widget have change == > this force the system to recalculate all the widget positions + * @brief need to be call When the size of the current widget have change ==> this force the system to recalculate all the widget positions */ void requestUpdateSize(); /** diff --git a/ewol/widget/Windows.cpp b/ewol/widget/Windows.cpp index 1c8e169a..0d85db29 100644 --- a/ewol/widget/Windows.cpp +++ b/ewol/widget/Windows.cpp @@ -41,19 +41,21 @@ ewol::widget::Windows::~Windows() { m_popUpWidgetList.clear(); } -void ewol::widget::Windows::calculateSize(const vec2& _availlable) { - EWOL_DEBUG(" _availlable : " << _availlable); - m_size = _availlable; +void ewol::widget::Windows::onSizeChange() { + ewol::Widget::onSizeChange(); if (m_subWidget != nullptr) { m_subWidget->calculateMinMaxSize(); - // TODO : Check if min size is possible ... - // TODO : Herited from MinSize .. and expand ??? - m_subWidget->calculateSize(m_size); + // TODO : do it better ... and manage gravity ... + m_subWidget->setSize(m_size); + m_subWidget->setOrigin(vec2(0.0f, 0.0f)); + m_subWidget->onSizeChange(); } for (auto &it : m_popUpWidgetList) { if(it != nullptr) { it->calculateMinMaxSize(); - it->calculateSize(m_size); + it->setSize(m_size); + it->setOrigin(vec2(0.0f, 0.0f)); + it->onSizeChange(); } } } @@ -170,7 +172,7 @@ void ewol::widget::Windows::setSubWidget(std::shared_ptr _widget) } // Regenerate the size calculation : - calculateSize(m_size); + onSizeChange(); } void ewol::widget::Windows::popUpWidgetPush(std::shared_ptr _widget) { @@ -184,7 +186,7 @@ void ewol::widget::Windows::popUpWidgetPush(std::shared_ptr _widge // force the focus on the basic widget ==> this remove many time the virual keyboard area _widget->keepFocus(); // Regenerate the size calculation : - calculateSize(m_size); + onSizeChange(); // TODO : it is dangerous to access directly to the system ... getContext().resetIOEvent(); } diff --git a/ewol/widget/Windows.h b/ewol/widget/Windows.h index a56f0bc0..fcffbd2c 100644 --- a/ewol/widget/Windows.h +++ b/ewol/widget/Windows.h @@ -79,7 +79,7 @@ namespace ewol { virtual void systemDraw(const ewol::DrawProperty& _displayProp); public: // Derived function virtual void onRegenerateDisplay(); - virtual void calculateSize(const vec2& _availlable); + virtual void onSizeChange(); virtual std::shared_ptr getWidgetAtPos(const vec2& _pos); virtual void requestDestroyFromChild(const std::shared_ptr& _child); virtual std::shared_ptr getSubObjectNamed(const std::string& _objectName);