[DEV] rework all the API of the sizing

This commit is contained in:
Edouard DUPIN 2016-02-01 23:50:01 +01:00
parent 5b93b312f3
commit 5ee58f3540
27 changed files with 243 additions and 353 deletions

View File

@ -460,7 +460,8 @@ void ewol::Context::forceRedrawAll() {
return; return;
} }
ivec2 size = getSize(); 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() { void ewol::Context::OS_Stop() {

View File

@ -62,20 +62,12 @@ ewol::widget::Button::~Button() {
} }
void ewol::widget::Button::onSizeChange() {
void ewol::widget::Button::calculateSize(const vec2& _availlable) {
ewol::Padding padding = m_shaper->getPadding(); ewol::Padding padding = m_shaper->getPadding();
ewol::Padding ret = calculateSizePadded(_availlable, padding); ewol::Padding ret = onSizeChangePadded(padding);
//EWOL_DEBUG(" configuring : origin=" << origin << " size=" << subElementSize << ""); //EWOL_DEBUG(" configuring : origin=" << origin << " size=" << subElementSize << "");
m_selectableAreaPos = vec2(ret.xLeft(), ret.yButtom()); m_selectableAreaPos = vec2(ret.xLeft(), ret.yButtom());
m_selectableAreaSize = m_size - (m_selectableAreaPos + vec2(ret.xRight(), ret.yTop())); 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()));
}
} }

View File

@ -155,7 +155,7 @@ namespace ewol {
virtual void onParameterChangeValue(const ewol::parameter::Ref& _paramPointer); virtual void onParameterChangeValue(const ewol::parameter::Ref& _paramPointer);
public: // Derived function public: // Derived function
virtual void calculateMinMaxSize(); virtual void calculateMinMaxSize();
virtual void calculateSize(const vec2& _availlable); virtual void onSizeChange();
virtual void onRegenerateDisplay(); virtual void onRegenerateDisplay();
virtual bool onEventInput(const ewol::event::Input& _event); virtual bool onEventInput(const ewol::event::Input& _event);
virtual bool onEventEntry(const ewol::event::Entry& _event); virtual bool onEventEntry(const ewol::event::Entry& _event);

View File

@ -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(); ewol::Padding padding = m_shaper->getPadding();
float boxSize = m_shaper->getConfigNumber(m_shaperIdSize); float boxSize = m_shaper->getConfigNumber(m_shaperIdSize);
padding.setXLeft(padding.xLeft()*2.0f + boxSize); 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 << ""); EWOL_DEBUG(" configuring : padding=" << padding << " boxSize=" << boxSize << "");
m_selectableAreaPos = vec2(ret.xLeft()/*-boxSize*/, ret.yButtom()); m_selectableAreaPos = vec2(ret.xLeft()/*-boxSize*/, ret.yButtom());
m_selectableAreaSize = m_size - (m_selectableAreaPos + vec2(ret.xRight(), ret.yTop())); m_selectableAreaSize = m_size - (m_selectableAreaPos + vec2(ret.xRight(), ret.yTop()));

View File

@ -90,7 +90,7 @@ namespace ewol {
virtual void onParameterChangeValue(const ewol::parameter::Ref& _paramPointer); virtual void onParameterChangeValue(const ewol::parameter::Ref& _paramPointer);
public: // Derived function public: // Derived function
virtual void calculateMinMaxSize(); virtual void calculateMinMaxSize();
virtual void calculateSize(const vec2& _availlable); virtual void onSizeChange();
virtual void onRegenerateDisplay(); virtual void onRegenerateDisplay();
virtual bool onEventInput(const ewol::event::Input& _event); virtual bool onEventInput(const ewol::event::Input& _event);
virtual bool onEventEntry(const ewol::event::Entry& _event); virtual bool onEventEntry(const ewol::event::Entry& _event);

View File

@ -104,31 +104,33 @@ void ewol::widget::Container::systemDraw(const ewol::DrawProperty& _displayProp)
} }
} }
void ewol::widget::Container::calculateSize(const vec2& _availlable) { void ewol::widget::Container::onSizeChange() {
if (nullptr!=m_subWidget) { ewol::Widget::onSizeChange();
vec2 origin = m_origin+m_offset; if (m_subWidget == nullptr) {
vec2 minSize = m_subWidget->getCalculateMinSize(); return;
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);
} }
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() { void ewol::widget::Container::calculateMinMaxSize() {
@ -203,7 +205,7 @@ void ewol::widget::Container::setOffset(const vec2& _newVal) {
if (m_offset != _newVal) { if (m_offset != _newVal) {
ewol::Widget::setOffset(_newVal); ewol::Widget::setOffset(_newVal);
// recalculate the new sise and position of sub widget ... // recalculate the new sise and position of sub widget ...
calculateSize(m_size); onSizeChange();
} }
} }

View File

@ -62,7 +62,7 @@ namespace ewol {
public: // Derived function public: // Derived function
virtual void systemDraw(const ewol::DrawProperty& _displayProp); virtual void systemDraw(const ewol::DrawProperty& _displayProp);
virtual void onRegenerateDisplay(); virtual void onRegenerateDisplay();
virtual void calculateSize(const vec2& _availlable); virtual void onSizeChange();
virtual void calculateMinMaxSize(); virtual void calculateMinMaxSize();
virtual std::shared_ptr<ewol::Widget> getWidgetAtPos(const vec2& _pos); virtual std::shared_ptr<ewol::Widget> getWidgetAtPos(const vec2& _pos);
virtual std::shared_ptr<ewol::Object> getSubObjectNamed(const std::string& _objectName); virtual std::shared_ptr<ewol::Object> getSubObjectNamed(const std::string& _objectName);

View File

@ -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) { ewol::Padding ewol::widget::Container2::onSizeChangePadded(const ewol::Padding& _padding) {
vec2 localAvaillable = _availlable - vec2(_padding.x(), _padding.y()); ewol::Widget::onSizeChange();
ewol::Widget::calculateSize(_availlable); vec2 localAvaillable = m_size - vec2(_padding.x(), _padding.y());
// set minimal size
if (m_userExpand->x() == true) {
m_size.setX(_availlable.x());
}
if (m_userExpand->y() == true) {
m_size.setY(_availlable.y());
}
// Checkin the filling properties == > for the subElements: // Checkin the filling properties == > for the subElements:
vec2 subElementSize = m_minSize; vec2 subElementSize = m_minSize;
if (m_userFill->x() == true) { 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]->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()); vec2 selectableAreaPos = origin-vec2(_padding.xLeft(), _padding.yButtom());
@ -252,7 +246,7 @@ void ewol::widget::Container2::setOffset(const vec2& _newVal) {
if (m_offset != _newVal) { if (m_offset != _newVal) {
ewol::Widget::setOffset(_newVal); ewol::Widget::setOffset(_newVal);
// recalculate the new sise and position of sub widget ... // recalculate the new sise and position of sub widget ...
calculateSize(m_size); calculateSize();
} }
} }

View File

@ -125,11 +125,10 @@ namespace ewol {
/** /**
* @brief Parent set the possible diplay size of the current widget whith his own possibilities * @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 * 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. * @param[in] _padding Padding of the widget.
* @note : INTERNAL EWOL SYSTEM * @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) * @brief calculate the minimum and maximum size (need to estimate expend properties of the widget)
* @param[in] _padding Padding of the widget. * @param[in] _padding Padding of the widget.
@ -161,8 +160,8 @@ namespace ewol {
public: // Derived function public: // Derived function
virtual void systemDraw(const ewol::DrawProperty& _displayProp); virtual void systemDraw(const ewol::DrawProperty& _displayProp);
virtual void onRegenerateDisplay(); virtual void onRegenerateDisplay();
virtual void calculateSize(const vec2& _availlable) { virtual void onSizeChange() {
calculateSizePadded(_availlable); onSizeChangePadded();
} }
virtual void calculateMinMaxSize() { virtual void calculateMinMaxSize() {
calculateMinMaxSizePadded(); calculateMinMaxSizePadded();

View File

@ -195,15 +195,15 @@ void ewol::widget::ContainerN::systemDraw(const ewol::DrawProperty& _displayProp
} }
} }
void ewol::widget::ContainerN::calculateSize(const vec2& _availlable) { void ewol::widget::ContainerN::onSizeChange() {
m_size = _availlable;
for (auto &it : m_subWidget) { for (auto &it : m_subWidget) {
if (it != nullptr) { if (it == nullptr) {
it->setOrigin(m_origin+m_offset); continue;
it->calculateSize(m_size);
} }
it->setOrigin(m_origin+m_offset);
it->setSize(m_size);
it->onSizeChange();
} }
markToRedraw();
} }
void ewol::widget::ContainerN::calculateMinMaxSize() { void ewol::widget::ContainerN::calculateMinMaxSize() {
@ -317,7 +317,7 @@ void ewol::widget::ContainerN::setOffset(const vec2& _newVal) {
if (m_offset != _newVal) { if (m_offset != _newVal) {
ewol::Widget::setOffset(_newVal); ewol::Widget::setOffset(_newVal);
// recalculate the new sise and position of sub widget ... // recalculate the new sise and position of sub widget ...
calculateSize(m_size); onSizeChange();
} }
} }

View File

@ -98,7 +98,7 @@ namespace ewol {
public:// Derived function public:// Derived function
virtual void systemDraw(const ewol::DrawProperty& _displayProp); virtual void systemDraw(const ewol::DrawProperty& _displayProp);
virtual void onRegenerateDisplay(); virtual void onRegenerateDisplay();
virtual void calculateSize(const vec2& _availlable); virtual void onSizeChange();
virtual void calculateMinMaxSize(); virtual void calculateMinMaxSize();
virtual std::shared_ptr<ewol::Widget> getWidgetAtPos(const vec2& _pos); virtual std::shared_ptr<ewol::Widget> getWidgetAtPos(const vec2& _pos);
virtual std::shared_ptr<ewol::Object> getSubObjectNamed(const std::string& _objectName); virtual std::shared_ptr<ewol::Object> getSubObjectNamed(const std::string& _objectName);

View File

@ -49,10 +49,8 @@ ewol::widget::ContextMenu::~ContextMenu() {
} }
void ewol::widget::ContextMenu::calculateSize(const vec2& _availlable) { void ewol::widget::ContextMenu::onSizeChange() {
//EWOL_DEBUG("CalculateSize=" << availlable);
// pop-up fill all the display : // pop-up fill all the display :
m_size = _availlable;
ewol::Padding padding = m_shaper->getPadding(); ewol::Padding padding = m_shaper->getPadding();
EWOL_VERBOSE("our origin=" << m_origin << " size=" << m_size); EWOL_VERBOSE("our origin=" << m_origin << " size=" << m_size);
if (nullptr != m_subWidget) { if (nullptr != m_subWidget) {
@ -110,7 +108,8 @@ void ewol::widget::ContextMenu::calculateSize(const vec2& _availlable) {
} }
EWOL_VERBOSE(" == > sub origin=" << subWidgetOrigin << " size=" << subWidgetSize); EWOL_VERBOSE(" == > sub origin=" << subWidgetOrigin << " size=" << subWidgetSize);
m_subWidget->setOrigin(subWidgetOrigin); m_subWidget->setOrigin(subWidgetOrigin);
m_subWidget->calculateSize(subWidgetSize); m_subWidget->setSize(subWidgetSize);
m_subWidget->onSizeChange();
} }
markToRedraw(); markToRedraw();
} }

View File

@ -67,7 +67,7 @@ namespace ewol {
public: // Derived function public: // Derived function
virtual void onRegenerateDisplay(); virtual void onRegenerateDisplay();
virtual bool onEventInput(const ewol::event::Input& _event); virtual bool onEventInput(const ewol::event::Input& _event);
virtual void calculateSize(const vec2& _availlable); virtual void onSizeChange();
virtual void calculateMinMaxSize(); virtual void calculateMinMaxSize();
virtual std::shared_ptr<ewol::Widget> getWidgetAtPos(const vec2& _pos); virtual std::shared_ptr<ewol::Widget> getWidgetAtPos(const vec2& _pos);
}; };

View File

@ -47,9 +47,8 @@ void ewol::widget::Gird::setBorderSize(const ivec2& _newBorderSize) {
requestUpdateSize(); requestUpdateSize();
} }
void ewol::widget::Gird::calculateSize(const vec2& _availlable) { void ewol::widget::Gird::onSizeChange() {
//EWOL_DEBUG("Update size"); //EWOL_DEBUG("Update size");
m_size = _availlable;
m_size -= m_borderSize*2; m_size -= m_borderSize*2;
for (size_t iii=0; iii<m_subWidget.size(); iii++) { for (size_t iii=0; iii<m_subWidget.size(); iii++) {
@ -77,7 +76,8 @@ void ewol::widget::Gird::calculateSize(const vec2& _availlable) {
// set the origin : // set the origin :
m_subWidget[iii].widget->setOrigin(vec2ClipInt32(tmpOrigin)); m_subWidget[iii].widget->setOrigin(vec2ClipInt32(tmpOrigin));
// all time set oll the space . // 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; m_size += m_borderSize*2;

View File

@ -140,7 +140,7 @@ namespace ewol {
virtual void systemDraw(const ewol::DrawProperty& _displayProp); virtual void systemDraw(const ewol::DrawProperty& _displayProp);
virtual void onRegenerateDisplay(); virtual void onRegenerateDisplay();
virtual std::shared_ptr<ewol::Widget> getWidgetAtPos(const vec2& pos); virtual std::shared_ptr<ewol::Widget> getWidgetAtPos(const vec2& pos);
virtual void calculateSize(const vec2& _availlable); virtual void onSizeChange();
virtual void calculateMinMaxSize(); virtual void calculateMinMaxSize();
}; };
}; };

View File

@ -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() { void ewol::widget::Joystick::onRegenerateDisplay() {
if (true == needRedraw()) { if (true == needRedraw()) {
// clean the object list ... // clean the object list ...

View File

@ -83,7 +83,6 @@ namespace ewol {
void getProperty(float& _distance, float& _angle); void getProperty(float& _distance, float& _angle);
public: // Derived function public: // Derived function
virtual void calculateSize(const vec2& _availlable);
virtual void onRegenerateDisplay(); virtual void onRegenerateDisplay();
virtual bool onEventInput(const ewol::event::Input& _event); virtual bool onEventInput(const ewol::event::Input& _event);
}; };

View File

@ -43,45 +43,39 @@ void ewol::widget::PopUp::setShaperName(const std::string& _shaperName) {
markToRedraw(); markToRedraw();
} }
void ewol::widget::PopUp::calculateSize(const vec2& _available) { void ewol::widget::PopUp::onSizeChange() {
#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);
}
markToRedraw(); 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) { void ewol::widget::PopUp::systemDraw(const ewol::DrawProperty& _displayProp) {

View File

@ -77,7 +77,7 @@ namespace ewol {
virtual void periodicCall(const ewol::event::Time& _event); virtual void periodicCall(const ewol::event::Time& _event);
virtual void systemDraw(const ewol::DrawProperty& _displayProp); virtual void systemDraw(const ewol::DrawProperty& _displayProp);
virtual void onRegenerateDisplay(); virtual void onRegenerateDisplay();
virtual void calculateSize(const vec2& _available); virtual void onSizeChange();
virtual bool onEventInput(const ewol::event::Input& _event); virtual bool onEventInput(const ewol::event::Input& _event);
virtual std::shared_ptr<ewol::Widget> getWidgetAtPos(const vec2& _pos); virtual std::shared_ptr<ewol::Widget> getWidgetAtPos(const vec2& _pos);
protected: protected:

View File

@ -37,210 +37,136 @@ ewol::widget::Sizer::~Sizer() {
} }
void ewol::widget::Sizer::calculateSize(const vec2& _availlable) { void ewol::widget::Sizer::onSizeChange() {
ewol::Widget::calculateSize(_availlable); ewol::Widget::onSizeChange();
vec2 tmpBorderSize = m_borderSize->getPixel(); vec2 tmpBorderSize = m_borderSize->getPixel();
EWOL_VERBOSE("[" << getId() << "] update size : " << _availlable << " nbElement : " << m_subWidget.size() << " borderSize=" << tmpBorderSize << " from border=" << m_borderSize); EWOL_VERBOSE("[" << getId() << "] update size : " << m_size << " nbElement : " << m_subWidget.size() << " borderSize=" << tmpBorderSize << " from border=" << m_borderSize);
#if 1 vec2 localWidgetSize = m_size - tmpBorderSize*2.0f;
vec2 localWidgetSize = m_size - tmpBorderSize*2.0f; // -1- calculate min-size and expand requested:
// -1- calculate min-size and expand requested: vec2 minSize(0.0f, 0.0f);
vec2 minSize(0.0f, 0.0f); ivec2 nbWidgetExpand(0,0);
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) { for (auto &it : m_subWidget) {
if (it == nullptr) { if (it == nullptr) {
continue; 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) { 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) { 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) { if (it->canExpand().x() == true) {
nbWidgetNotFixedSize+=ivec2(1,0); float sizeExpand = std::avg(tmpSizeMin.x(), minSize.x(), tmpSizeMax.x());
tmpSizeMin.setX(sizeExpand);
} }
} it->setSize(tmpSizeMin);
}
// 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());
} else { } else {
sizeToAddAtEveryOne = (m_size.x() - unexpandableSize) / float(nbWidgetNotFixedSize.x()); if (it->canExpand().x() == true) {
} float sizeExpand = tmpSizeMin.x() + deltaExpandSize;
if (sizeToAddAtEveryOne<0.0) { if (sizeExpand > tmpSizeMax.x()) {
sizeToAddAtEveryOne=0; residualNext += (sizeExpand - tmpSizeMax.x());
} sizeExpand = tmpSizeMax.x();
} countCalculation--;
// 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());
} }
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; // Reset size add ...
#endif 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(); markToRedraw();
} }

View File

@ -141,7 +141,7 @@ namespace ewol {
private: private:
ewol::compositing::Drawing m_draw; //!< Compositing drawing element for display the border. ewol::compositing::Drawing m_draw; //!< Compositing drawing element for display the border.
public: // Derived function public: // Derived function
virtual void calculateSize(const vec2& _availlable); virtual void onSizeChange();
virtual void calculateMinMaxSize(); virtual void calculateMinMaxSize();
// overwrite the set fuction to start annimations ... // overwrite the set fuction to start annimations ...
virtual int32_t subWidgetAdd(std::shared_ptr<ewol::Widget> _newWidget); virtual int32_t subWidgetAdd(std::shared_ptr<ewol::Widget> _newWidget);

View File

@ -43,17 +43,16 @@ ewol::widget::WSlider::~WSlider() {
} }
void ewol::widget::WSlider::calculateSize(const vec2& _availlable) { void ewol::widget::WSlider::onSizeChange() {
//EWOL_DEBUG("Update size"); ewol::widget::ContainerN::onSizeChange();
ewol::widget::ContainerN::calculateSize(_availlable);
if (m_windowsDestination == m_windowsSources) { if (m_windowsDestination == m_windowsSources) {
auto it = m_subWidget.begin(); auto it = m_subWidget.begin();
std::advance(it, m_windowsDestination); std::advance(it, m_windowsDestination);
if ( it != m_subWidget.end() if ( it != m_subWidget.end()
&& *it != nullptr) { && *it != nullptr) {
(*it)->setOrigin(m_origin+m_offset); (*it)->setOrigin(m_origin+m_offset);
(*it)->calculateSize(m_size); (*it)->setSize(m_size);
(*it)->onSizeChange();
} }
} else { } else {
float factor = -1.0f; 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_origin.y() + factor*(m_size.y()*m_slidingProgress))
+ m_offset); + m_offset);
} }
(*it)->calculateSize(m_size); (*it)->setSize(m_size);
(*it)->onSizeChange();
} }
it = m_subWidget.begin(); it = m_subWidget.begin();
std::advance(it, m_windowsDestination); 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_origin.y() + factor*(m_size.y()*m_slidingProgress - m_size.y()))
+ m_offset); + m_offset);
} }
(*it)->calculateSize(m_size); (*it)->setSize(m_size);
(*it)->onSizeChange();
} }
} }
markToRedraw(); markToRedraw();
@ -204,8 +205,7 @@ void ewol::widget::WSlider::periodicCall(const ewol::event::Time& _event) {
m_slidingProgress += _event.getDeltaCall()/m_transitionSpeed; m_slidingProgress += _event.getDeltaCall()/m_transitionSpeed;
m_slidingProgress = std::avg(0.0f, m_slidingProgress, 1.0f); m_slidingProgress = std::avg(0.0f, m_slidingProgress, 1.0f);
} }
calculateSize(m_size); onSizeChange();
markToRedraw();
} }
void ewol::widget::WSlider::systemDraw(const ewol::DrawProperty& _displayProp) { void ewol::widget::WSlider::systemDraw(const ewol::DrawProperty& _displayProp) {

View File

@ -101,7 +101,7 @@ namespace ewol {
return m_transitionSlide; return m_transitionSlide;
}; };
public: // Derived function public: // Derived function
virtual void calculateSize(const vec2& _availlable); virtual void onSizeChange();
virtual void systemDraw(const ewol::DrawProperty& _displayProp); virtual void systemDraw(const ewol::DrawProperty& _displayProp);
virtual void onRegenerateDisplay(); virtual void onRegenerateDisplay();
virtual std::shared_ptr<ewol::Widget> getWidgetAtPos(const vec2& _pos); virtual std::shared_ptr<ewol::Widget> getWidgetAtPos(const vec2& _pos);

View File

@ -146,22 +146,7 @@ ewol::Widget::~Widget() {
shortCutClean(); shortCutClean();
} }
void ewol::Widget::calculateSize(const vec2& _available) { void ewol::Widget::onSizeChange() {
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;
markToRedraw(); markToRedraw();
} }

View File

@ -150,19 +150,23 @@ namespace ewol {
*/ */
virtual vec2 relativePosition(const vec2& _pos); virtual vec2 relativePosition(const vec2& _pos);
/** /**
* @brief Parent set the possible diplay size of the current widget whith his own possibilities * @brief Parent have set the size and the origin. the container need to update the subwidget property
* By default this save the widget available size in the widget size
* @param[in] _available Available x&y pixel size
* @note : INTERNAL EWOL SYSTEM * @note : INTERNAL EWOL SYSTEM
*/ */
virtual void calculateSize(const vec2& _available); virtual void onSizeChange();
virtual void calculateSize() {};
/** /**
* @brief get the widget size * @brief get the widget size
* @return Requested size * @return Requested size
* @note : INTERNAL EWOL SYSTEM * @note : INTERNAL EWOL SYSTEM
*/ */
virtual vec2 getSize(); 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; m_size = _value;
} }
/** /**
@ -672,7 +676,7 @@ namespace ewol {
virtual void onParameterChangeValue(const ewol::parameter::Ref& _paramPointer); virtual void onParameterChangeValue(const ewol::parameter::Ref& _paramPointer);
public: 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(); void requestUpdateSize();
/** /**

View File

@ -41,19 +41,21 @@ ewol::widget::Windows::~Windows() {
m_popUpWidgetList.clear(); m_popUpWidgetList.clear();
} }
void ewol::widget::Windows::calculateSize(const vec2& _availlable) { void ewol::widget::Windows::onSizeChange() {
EWOL_DEBUG(" _availlable : " << _availlable); ewol::Widget::onSizeChange();
m_size = _availlable;
if (m_subWidget != nullptr) { if (m_subWidget != nullptr) {
m_subWidget->calculateMinMaxSize(); m_subWidget->calculateMinMaxSize();
// TODO : Check if min size is possible ... // TODO : do it better ... and manage gravity ...
// TODO : Herited from MinSize .. and expand ??? m_subWidget->setSize(m_size);
m_subWidget->calculateSize(m_size); m_subWidget->setOrigin(vec2(0.0f, 0.0f));
m_subWidget->onSizeChange();
} }
for (auto &it : m_popUpWidgetList) { for (auto &it : m_popUpWidgetList) {
if(it != nullptr) { if(it != nullptr) {
it->calculateMinMaxSize(); 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<ewol::Widget> _widget)
} }
// Regenerate the size calculation : // Regenerate the size calculation :
calculateSize(m_size); onSizeChange();
} }
void ewol::widget::Windows::popUpWidgetPush(std::shared_ptr<ewol::Widget> _widget) { void ewol::widget::Windows::popUpWidgetPush(std::shared_ptr<ewol::Widget> _widget) {
@ -184,7 +186,7 @@ void ewol::widget::Windows::popUpWidgetPush(std::shared_ptr<ewol::Widget> _widge
// force the focus on the basic widget ==> this remove many time the virual keyboard area // force the focus on the basic widget ==> this remove many time the virual keyboard area
_widget->keepFocus(); _widget->keepFocus();
// Regenerate the size calculation : // Regenerate the size calculation :
calculateSize(m_size); onSizeChange();
// TODO : it is dangerous to access directly to the system ... // TODO : it is dangerous to access directly to the system ...
getContext().resetIOEvent(); getContext().resetIOEvent();
} }

View File

@ -79,7 +79,7 @@ namespace ewol {
virtual void systemDraw(const ewol::DrawProperty& _displayProp); virtual void systemDraw(const ewol::DrawProperty& _displayProp);
public: // Derived function public: // Derived function
virtual void onRegenerateDisplay(); virtual void onRegenerateDisplay();
virtual void calculateSize(const vec2& _availlable); virtual void onSizeChange();
virtual std::shared_ptr<ewol::Widget> getWidgetAtPos(const vec2& _pos); virtual std::shared_ptr<ewol::Widget> getWidgetAtPos(const vec2& _pos);
virtual void requestDestroyFromChild(const std::shared_ptr<Object>& _child); virtual void requestDestroyFromChild(const std::shared_ptr<Object>& _child);
virtual std::shared_ptr<ewol::Object> getSubObjectNamed(const std::string& _objectName); virtual std::shared_ptr<ewol::Object> getSubObjectNamed(const std::string& _objectName);