[DEV] continue good integration of gravity in sizer ...
This commit is contained in:
parent
46699c20b6
commit
5b93b312f3
@ -41,7 +41,122 @@ void ewol::widget::Sizer::calculateSize(const vec2& _availlable) {
|
||||
ewol::Widget::calculateSize(_availlable);
|
||||
vec2 tmpBorderSize = m_borderSize->getPixel();
|
||||
EWOL_VERBOSE("[" << getId() << "] update size : " << _availlable << " nbElement : " << m_subWidget.size() << " borderSize=" << tmpBorderSize << " from border=" << m_borderSize);
|
||||
m_size -= tmpBorderSize*2;
|
||||
#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);
|
||||
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 += 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);
|
||||
@ -125,6 +240,7 @@ void ewol::widget::Sizer::calculateSize(const vec2& _availlable) {
|
||||
}
|
||||
}
|
||||
m_size += tmpBorderSize*2;
|
||||
#endif
|
||||
markToRedraw();
|
||||
}
|
||||
|
||||
|
@ -162,6 +162,9 @@ namespace ewol {
|
||||
* @note : INTERNAL EWOL SYSTEM
|
||||
*/
|
||||
virtual vec2 getSize();
|
||||
virtual void parrentSetSize(const vec2& _value) {
|
||||
m_size = _value;
|
||||
}
|
||||
/**
|
||||
* @brief calculate the minimum and maximum size (need to estimate expend properties of the widget)
|
||||
* @note : INTERNAL EWOL SYSTEM
|
||||
|
Loading…
x
Reference in New Issue
Block a user