162 if (
mLayout == LayoutPolicy::Absolute) {
164 std::list<Widget*>::const_iterator currChild(
mChildren.begin());
165 std::list<Widget*>::const_iterator
const endChildren(
mChildren.end());
166 for (; currChild != endChildren; ++currChild) {
167 if (!(*currChild)->isVisible()) {
170 (*currChild)->resizeToContent(recursion);
182 int visibleChilds = 0;
184 std::list<Widget*>::const_iterator currChild(
mChildren.begin());
185 std::list<Widget*>::const_iterator endChildren(
mChildren.end());
186 for (; currChild != endChildren; ++currChild) {
187 if (!(*currChild)->isVisible()) {
191 (*currChild)->resizeToContent(recursion);
193 Rectangle const & rec = (*currChild)->getDimension();
194 childMaxW = std::max(childMaxW, rec.
width);
195 childMaxH = std::max(childMaxH, rec.
height);
197 std::max(layoutMaxW, rec.
width + (*currChild)->getMarginLeft() + (*currChild)->getMarginRight());
199 std::max(layoutMaxH, rec.
height + (*currChild)->getMarginTop() + (*currChild)->getMarginBottom());
206 Rectangle dimensions(0, 0, childMaxW, childMaxH);
208 if (
mLayout == LayoutPolicy::AutoSize && visibleChilds > 0) {
211 for (; currChild != endChildren; ++currChild) {
212 if (!(*currChild)->isVisible()) {
215 Rectangle const & rec = (*currChild)->getDimension();
216 int const childW = rec.
x + rec.
width + (*currChild)->getMarginLeft() + (*currChild)->getMarginRight();
217 int const childH = rec.
y + rec.
height + (*currChild)->getMarginTop() + (*currChild)->getMarginBottom();
218 totalW = std::max(totalW, childW);
219 totalH = std::max(totalH, childH);
223 }
else if (
mLayout == LayoutPolicy::Vertical && visibleChilds > 0) {
226 for (; currChild != endChildren; ++currChild) {
227 if (!(*currChild)->isVisible()) {
230 dimensions.
x = (*currChild)->getMarginLeft();
231 dimensions.
y += (*currChild)->getMarginTop();
232 int const layoutW = (*currChild)->getWidth() + (*currChild)->getMarginLeft() +
233 ((*currChild)->getMarginRight() > 0 ? (*currChild)->getMarginRight() : 0);
234 dimensions.
width = (*currChild)->getWidth() + (layoutMaxW - layoutW);
235 dimensions.
height = (*currChild)->getHeight();
236 (*currChild)->setDimension(dimensions);
237 dimensions.
y += (*currChild)->getHeight() + (*currChild)->getMarginBottom() +
getVerticalSpacing();
241 totalW = std::max(layoutMaxW, childMaxW) + diffW;
242 totalH = dimensions.
y + diffH;
243 }
else if (
mLayout == LayoutPolicy::Horizontal && visibleChilds > 0) {
246 for (; currChild != endChildren; ++currChild) {
247 if (!(*currChild)->isVisible()) {
250 dimensions.
x += (*currChild)->getMarginLeft();
251 dimensions.
y = (*currChild)->getMarginTop();
252 dimensions.
width = (*currChild)->getWidth();
253 int const layoutH = (*currChild)->getHeight() + (*currChild)->getMarginTop() +
254 ((*currChild)->getMarginBottom() > 0 ? (*currChild)->getMarginBottom() : 0);
255 dimensions.
height = (*currChild)->getHeight() + (layoutMaxH - layoutH);
256 (*currChild)->setDimension(dimensions);
261 totalW = dimensions.
x + diffW;
262 totalH = std::max(layoutMaxH, childMaxH) + diffH;
263 }
else if (
mLayout == LayoutPolicy::Circular && visibleChilds > 0) {
264 float const angle = 360.0F / visibleChilds;
276 for (; currChild != endChildren; ++currChild) {
277 if (!(*currChild)->isVisible()) {
280 float const tmpAngle =
281 static_cast<float>(
static_cast<int>((angle * i) + 270) % 360) / (180.0F /
Mathf::pi());
282 int const x =
static_cast<int>(
283 (xRadius * std::cos(tmpAngle)) - (
static_cast<float>((*currChild)->getWidth()) / 2.0F));
284 int const y =
static_cast<int>(
285 (yRadius * std::sin(tmpAngle)) - (
static_cast<float>((*currChild)->getHeight()) / 2.0F));
286 minW = std::min(minW, x);
287 maxW = std::max(maxW, x + (*currChild)->getWidth());
288 minH = std::min(minH, y);
289 maxH = std::max(maxH, y + (*currChild)->getHeight());
291 (*currChild)->setPosition(x, y);
295 w = std::abs(minW) + std::abs(maxW);
296 h = std::abs(minH) + std::abs(maxH);
298 int const centerX = w / 2;
299 int const centerY = h / 2;
303 for (; currChild != endChildren; ++currChild) {
304 if (!(*currChild)->isVisible()) {
307 int const x = (*currChild)->getX() + centerX;
308 int const y = (*currChild)->getY() + centerY;
310 (*currChild)->setPosition(x, y);
331 if (
mLayout == LayoutPolicy::Absolute) {
333 std::list<Widget*>::const_iterator currChild(
mChildren.begin());
334 std::list<Widget*>::const_iterator
const endChildren(
mChildren.end());
335 for (; currChild != endChildren; ++currChild) {
336 if (!(*currChild)->isVisible()) {
339 (*currChild)->expandContent(recursion);
345 if (
mLayout == LayoutPolicy::AutoSize) {
350 int const spaceW = childrenArea.
width;
351 int const spaceH = childrenArea.
height;
352 int neededSpaceW = 0;
353 int neededSpaceH = 0;
358 int maxHExpander = 0;
359 int maxVExpander = 0;
360 int expanderNeededSpaceW = 0;
361 int expanderNeededSpaceH = 0;
362 unsigned int visibleChilds = 0;
363 std::list<Widget*> hExpander;
364 std::list<Widget*> vExpander;
366 std::list<Widget*>::const_iterator currChild(
mChildren.begin());
367 std::list<Widget*>::const_iterator endChildren(
mChildren.end());
368 for (; currChild != endChildren; ++currChild) {
369 if (!(*currChild)->isVisible()) {
374 neededSpaceW += (*currChild)->getWidth() + (*currChild)->getMarginLeft() + (*currChild)->getMarginRight() +
376 neededSpaceH += (*currChild)->getHeight() + (*currChild)->getMarginTop() + (*currChild)->getMarginBottom() +
379 if ((*currChild)->isVerticalExpand()) {
380 maxVExpander = std::max(maxVExpander, (*currChild)->getHeight());
381 maxMinH = std::max(maxMinH, (*currChild)->getMinSize().getHeight());
382 minMaxH = std::min(minMaxH, (*currChild)->getMaxSize().getHeight());
384 vExpander.push_back((*currChild));
386 if ((*currChild)->isHorizontalExpand()) {
387 maxHExpander = std::max(maxHExpander, (*currChild)->getWidth());
388 maxMinW = std::max(maxMinW, (*currChild)->getMinSize().getWidth());
389 minMaxW = std::min(minMaxW, (*currChild)->getMaxSize().getWidth());
391 hExpander.push_back((*currChild));
395 if (
mLayout == LayoutPolicy::Vertical && visibleChilds > 0) {
398 int freeSpace = spaceH - neededSpaceH;
400 if (!vExpander.empty()) {
405 maxVExpander = std::min(minMaxH, maxVExpander);
407 maxVExpander = std::max(maxMinH, maxVExpander);
410 int const maxNeeded =
412 int const tmpSpace = (freeSpace + expanderNeededSpaceH) - maxNeeded;
415 freeSpace = tmpSpace;
418 if (freeSpace > 0 || h > 0) {
420 auto it = vExpander.begin();
422 int expanders = vExpander.size();
424 for (; it != vExpander.end(); ++it) {
425 int const layoutH = (*it)->getHeight() + (*it)->getMarginTop() +
426 ((*it)->getMarginBottom() > 0 ? (*it)->getMarginBottom() : 0);
428 int const diff = h > 0 ? 0 : (*it)->getHeight() + (maxVExpander - layoutH);
429 int delta = ((freeSpace - diff) / expanders) + diff;
433 delta = std::min(delta, freeSpace);
434 int const oldH = h > 0 ? h : (*it)->getHeight();
435 int tmpH = oldH + delta;
436 (*it)->setHeight(tmpH);
437 tmpH = (*it)->getHeight();
445 if (!vExpander.empty()) {
448 std::set<Widget*> maxExpanders;
449 while ((freeSpace != 0) && maxExpanders.size() < vExpander.size()) {
450 auto it = vExpander.begin();
451 for (; it != vExpander.end(); ++it) {
452 int const h = (*it)->getHeight();
453 (*it)->setHeight(h + 1);
454 if (h != (*it)->getHeight()) {
456 if (freeSpace == 0) {
460 maxExpanders.insert(*it);
468 if (!hExpander.empty() || !vExpander.empty() || hexpand) {
472 for (; currChild != endChildren; ++currChild) {
473 if (!(*currChild)->isVisible()) {
476 if (hexpand || (*currChild)->isHorizontalExpand()) {
477 int const layoutW = (*currChild)->getMarginLeft() +
478 ((*currChild)->getMarginRight() > 0 ? (*currChild)->getMarginRight() : 0);
479 rec.
width = spaceW - layoutW;
481 rec.
width = (*currChild)->getWidth();
483 rec.
x = (*currChild)->getMarginLeft();
484 rec.
y += (*currChild)->getMarginTop();
485 rec.
height = (*currChild)->getHeight();
486 (*currChild)->setDimension(rec);
490 }
else if (
mLayout == LayoutPolicy::Horizontal && visibleChilds > 0) {
493 int freeSpace = spaceW - neededSpaceW;
496 if (!hExpander.empty()) {
500 maxHExpander = std::min(minMaxW, maxHExpander);
502 maxHExpander = std::max(maxMinW, maxHExpander);
505 int const maxNeeded =
507 int const tmpSpace = (freeSpace + expanderNeededSpaceW) - maxNeeded;
510 freeSpace = tmpSpace;
513 if (freeSpace > 0 || w > 0) {
514 auto it = hExpander.begin();
515 int expanders = hExpander.size();
516 for (; it != hExpander.end(); ++it) {
518 int const layoutW = (*it)->getWidth() + (*it)->getMarginLeft() +
519 ((*it)->getMarginRight() > 0 ? (*it)->getMarginRight() : 0);
520 int const diff = w > 0 ? 0 : (*it)->getWidth() + (maxHExpander - layoutW);
521 int delta = ((freeSpace - diff) / expanders) + diff;
525 delta = std::min(delta, freeSpace);
526 int const oldW = w > 0 ? w : (*it)->getWidth();
527 int tmpW = oldW + delta;
528 (*it)->setWidth(tmpW);
529 tmpW = (*it)->getWidth();
536 if (!hExpander.empty()) {
539 std::set<Widget*> maxExpanders;
540 while ((freeSpace != 0) && maxExpanders.size() < hExpander.size()) {
541 auto it = hExpander.begin();
542 for (; it != hExpander.end(); ++it) {
543 int const w = (*it)->getWidth();
544 (*it)->setWidth(w + 1);
545 if (w != (*it)->getWidth()) {
547 if (freeSpace == 0) {
551 maxExpanders.insert(*it);
559 if (!hExpander.empty() || !vExpander.empty() || vexpand) {
563 for (; currChild != endChildren; ++currChild) {
564 if (!(*currChild)->isVisible()) {
567 if (vexpand || (*currChild)->isVerticalExpand()) {
568 int const layoutH = (*currChild)->getMarginTop() +
569 ((*currChild)->getMarginBottom() > 0 ? (*currChild)->getMarginBottom() : 0);
570 rec.
height = spaceH - layoutH;
572 rec.
height = (*currChild)->getHeight();
574 rec.
x += (*currChild)->getMarginLeft();
575 rec.
y = (*currChild)->getMarginTop();
576 rec.
width = (*currChild)->getWidth();
577 (*currChild)->setDimension(rec);
581 }
else if (
mLayout == LayoutPolicy::Circular && visibleChilds > 0) {
582 float const angle = 360.0F / visibleChilds;
587 for (; currChild != endChildren; ++currChild) {
588 if (!(*currChild)->isVisible()) {
591 childMaxW = std::max(childMaxW, (*currChild)->getWidth());
592 childMaxH = std::max(childMaxH, (*currChild)->getHeight());
596 float xRadius = (spaceW - childMaxW) / 2.0F;
597 float yRadius = (spaceH - childMaxH) / 2.0F;
598 float const centerX = spaceW / 2.0F;
599 float const centerY = spaceH / 2.0F;
601 xRadius =
static_cast<float>(childMaxW);
604 yRadius =
static_cast<float>(childMaxH);
612 for (; currChild != endChildren; ++currChild) {
613 if (!(*currChild)->isVisible()) {
616 float const tmpAngle =
617 static_cast<float>(
static_cast<int>((angle * i) + 270) % 360) / (180.0F /
Mathf::pi());
618 int x =
static_cast<int>(centerX + (xRadius * std::cos(tmpAngle)));
619 int y =
static_cast<int>(centerY + (yRadius * std::sin(tmpAngle)));
620 x -= (*currChild)->getWidth() / 2;
621 y -= (*currChild)->getHeight() / 2;
623 (*currChild)->setPosition(x, y);
631 for (; currChild != endChildren; ++currChild) {
632 if (!(*currChild)->isVisible()) {
635 (*currChild)->expandContent(recursion);