187 if (
mLayout == LayoutPolicy::Absolute) {
189 std::list<Widget*>::const_iterator currChild(
mChildren.begin());
190 std::list<Widget*>::const_iterator
const endChildren(
mChildren.end());
191 for (; currChild != endChildren; ++currChild) {
192 if (!(*currChild)->isVisible()) {
195 (*currChild)->resizeToContent(recursion);
207 int visibleChilds = 0;
209 std::list<Widget*>::const_iterator currChild(
mChildren.begin());
210 std::list<Widget*>::const_iterator endChildren(
mChildren.end());
211 for (; currChild != endChildren; ++currChild) {
212 if (!(*currChild)->isVisible()) {
216 (*currChild)->resizeToContent(recursion);
218 Rectangle const & rec = (*currChild)->getDimension();
219 childMaxW = std::max(childMaxW, rec.
width);
220 childMaxH = std::max(childMaxH, rec.
height);
222 std::max(layoutMaxW, rec.
width + (*currChild)->getMarginLeft() + (*currChild)->getMarginRight());
224 std::max(layoutMaxH, rec.
height + (*currChild)->getMarginTop() + (*currChild)->getMarginBottom());
231 Rectangle dimensions(0, 0, childMaxW, childMaxH);
233 if (
mLayout == LayoutPolicy::AutoSize && visibleChilds > 0) {
236 for (; currChild != endChildren; ++currChild) {
237 if (!(*currChild)->isVisible()) {
240 Rectangle const & rec = (*currChild)->getDimension();
241 int const childW = rec.
x + rec.
width + (*currChild)->getMarginLeft() + (*currChild)->getMarginRight();
242 int const childH = rec.
y + rec.
height + (*currChild)->getMarginTop() + (*currChild)->getMarginBottom();
243 totalW = std::max(totalW, childW);
244 totalH = std::max(totalH, childH);
248 }
else if (
mLayout == LayoutPolicy::Vertical && visibleChilds > 0) {
260 for (; currChild != endChildren; ++currChild) {
261 if (!(*currChild)->isVisible()) {
264 dimensions.
x = (*currChild)->getMarginLeft();
265 dimensions.
y += (*currChild)->getMarginTop();
266 int const layoutW = (*currChild)->getWidth() + (*currChild)->getMarginLeft() +
267 ((*currChild)->getMarginRight() > 0 ? (*currChild)->getMarginRight() : 0);
268 dimensions.
width = (*currChild)->getWidth() + (layoutMaxW - layoutW);
269 dimensions.
height = (*currChild)->getHeight();
270 (*currChild)->setDimension(dimensions);
271 dimensions.
y += (*currChild)->getHeight() + (*currChild)->getMarginBottom() +
getVerticalSpacing();
275 totalW = std::max(layoutMaxW, childMaxW) + diffW;
276 totalH = dimensions.
y + diffH;
277 }
else if (
mLayout == LayoutPolicy::Horizontal && visibleChilds > 0) {
289 for (; currChild != endChildren; ++currChild) {
290 if (!(*currChild)->isVisible()) {
293 dimensions.
x += (*currChild)->getMarginLeft();
294 dimensions.
y = (*currChild)->getMarginTop();
295 dimensions.
width = (*currChild)->getWidth();
296 int const layoutH = (*currChild)->getHeight() + (*currChild)->getMarginTop() +
297 ((*currChild)->getMarginBottom() > 0 ? (*currChild)->getMarginBottom() : 0);
298 dimensions.
height = (*currChild)->getHeight() + (layoutMaxH - layoutH);
299 (*currChild)->setDimension(dimensions);
304 totalW = dimensions.
x + diffW;
305 totalH = std::max(layoutMaxH, childMaxH) + diffH;
306 }
else if (
mLayout == LayoutPolicy::Circular && visibleChilds > 0) {
307 float const angle = 360.0F / visibleChilds;
319 for (; currChild != endChildren; ++currChild) {
320 if (!(*currChild)->isVisible()) {
323 float const tmpAngle =
324 static_cast<float>(
static_cast<int>((angle * i) + 270) % 360) / (180.0F /
Mathf::pi());
325 int const x =
static_cast<int>(
326 (xRadius * std::cos(tmpAngle)) - (
static_cast<float>((*currChild)->getWidth()) / 2.0F));
327 int const y =
static_cast<int>(
328 (yRadius * std::sin(tmpAngle)) - (
static_cast<float>((*currChild)->getHeight()) / 2.0F));
329 minW = std::min(minW, x);
330 maxW = std::max(maxW, x + (*currChild)->getWidth());
331 minH = std::min(minH, y);
332 maxH = std::max(maxH, y + (*currChild)->getHeight());
334 (*currChild)->setPosition(x, y);
338 w = std::abs(minW) + std::abs(maxW);
339 h = std::abs(minH) + std::abs(maxH);
341 int const centerX = w / 2;
342 int const centerY = h / 2;
346 for (; currChild != endChildren; ++currChild) {
347 if (!(*currChild)->isVisible()) {
350 int const x = (*currChild)->getX() + centerX;
351 int const y = (*currChild)->getY() + centerY;
353 (*currChild)->setPosition(x, y);
374 if (
mLayout == LayoutPolicy::Absolute) {
376 std::list<Widget*>::const_iterator currChild(
mChildren.begin());
377 std::list<Widget*>::const_iterator
const endChildren(
mChildren.end());
378 for (; currChild != endChildren; ++currChild) {
379 if (!(*currChild)->isVisible()) {
382 (*currChild)->expandContent(recursion);
388 if (
mLayout == LayoutPolicy::AutoSize) {
393 int const spaceW = childrenArea.
width;
394 int const spaceH = childrenArea.
height;
395 int neededSpaceW = 0;
396 int neededSpaceH = 0;
401 int maxHExpander = 0;
402 int maxVExpander = 0;
403 int expanderNeededSpaceW = 0;
404 int expanderNeededSpaceH = 0;
405 unsigned int visibleChilds = 0;
406 std::list<Widget*> hExpander;
407 std::list<Widget*> vExpander;
409 std::list<Widget*>::const_iterator currChild(
mChildren.begin());
410 std::list<Widget*>::const_iterator endChildren(
mChildren.end());
411 for (; currChild != endChildren; ++currChild) {
412 if (!(*currChild)->isVisible()) {
417 neededSpaceW += (*currChild)->getWidth() + (*currChild)->getMarginLeft() + (*currChild)->getMarginRight() +
419 neededSpaceH += (*currChild)->getHeight() + (*currChild)->getMarginTop() + (*currChild)->getMarginBottom() +
422 if ((*currChild)->isVerticalExpand()) {
423 maxVExpander = std::max(maxVExpander, (*currChild)->getHeight());
424 maxMinH = std::max(maxMinH, (*currChild)->getMinSize().getHeight());
425 minMaxH = std::min(minMaxH, (*currChild)->getMaxSize().getHeight());
427 vExpander.push_back((*currChild));
429 if ((*currChild)->isHorizontalExpand()) {
430 maxHExpander = std::max(maxHExpander, (*currChild)->getWidth());
431 maxMinW = std::max(maxMinW, (*currChild)->getMinSize().getWidth());
432 minMaxW = std::min(minMaxW, (*currChild)->getMaxSize().getWidth());
434 hExpander.push_back((*currChild));
438 if (
mLayout == LayoutPolicy::Vertical && visibleChilds > 0) {
441 int freeSpace = spaceH - neededSpaceH;
443 if (!vExpander.empty()) {
448 maxVExpander = std::min(minMaxH, maxVExpander);
450 maxVExpander = std::max(maxMinH, maxVExpander);
453 int const maxNeeded =
455 int const tmpSpace = (freeSpace + expanderNeededSpaceH) - maxNeeded;
458 freeSpace = tmpSpace;
461 if (freeSpace > 0 || h > 0) {
463 auto it = vExpander.begin();
465 int expanders = vExpander.size();
467 for (; it != vExpander.end(); ++it) {
468 int const layoutH = (*it)->getHeight() + (*it)->getMarginTop() +
469 ((*it)->getMarginBottom() > 0 ? (*it)->getMarginBottom() : 0);
471 int const diff = h > 0 ? 0 : (*it)->getHeight() + (maxVExpander - layoutH);
472 int delta = ((freeSpace - diff) / expanders) + diff;
476 delta = std::min(delta, freeSpace);
477 int const oldH = h > 0 ? h : (*it)->getHeight();
478 int tmpH = oldH + delta;
479 (*it)->setHeight(tmpH);
480 tmpH = (*it)->getHeight();
488 if (!vExpander.empty()) {
491 std::vector<Widget*> maxExpanders;
492 while ((freeSpace != 0) && maxExpanders.size() < vExpander.size()) {
493 auto it = vExpander.begin();
494 for (; it != vExpander.end(); ++it) {
495 int const h = (*it)->getHeight();
496 (*it)->setHeight(h + 1);
497 if (h != (*it)->getHeight()) {
499 if (freeSpace == 0) {
503 if (std::ranges::find(maxExpanders, *it) == maxExpanders.end()) {
504 maxExpanders.push_back(*it);
513 if (!hExpander.empty() || !vExpander.empty() || hexpand) {
517 for (; currChild != endChildren; ++currChild) {
518 if (!(*currChild)->isVisible()) {
521 if (hexpand || (*currChild)->isHorizontalExpand()) {
522 int const layoutW = (*currChild)->getMarginLeft() +
523 ((*currChild)->getMarginRight() > 0 ? (*currChild)->getMarginRight() : 0);
525 rec.
width = spaceW - layoutW;
527 rec.
width = (*currChild)->getWidth();
529 rec.
x = (*currChild)->getMarginLeft();
530 rec.
y += (*currChild)->getMarginTop();
531 rec.
height = (*currChild)->getHeight();
532 (*currChild)->setDimension(rec);
536 }
else if (
mLayout == LayoutPolicy::Horizontal && visibleChilds > 0) {
539 int freeSpace = spaceW - neededSpaceW;
542 if (!hExpander.empty()) {
546 maxHExpander = std::min(minMaxW, maxHExpander);
548 maxHExpander = std::max(maxMinW, maxHExpander);
551 int const maxNeeded =
553 int const tmpSpace = (freeSpace + expanderNeededSpaceW) - maxNeeded;
556 freeSpace = tmpSpace;
559 if (freeSpace > 0 || w > 0) {
560 auto it = hExpander.begin();
561 int expanders = hExpander.size();
562 for (; it != hExpander.end(); ++it) {
564 int const layoutW = (*it)->getWidth() + (*it)->getMarginLeft() +
565 ((*it)->getMarginRight() > 0 ? (*it)->getMarginRight() : 0);
567 int const diff = w > 0 ? 0 : (*it)->getWidth() + (maxHExpander - layoutW);
568 int delta = ((freeSpace - diff) / expanders) + diff;
572 delta = std::min(delta, freeSpace);
573 int const oldW = w > 0 ? w : (*it)->getWidth();
574 int tmpW = oldW + delta;
575 (*it)->setWidth(tmpW);
576 tmpW = (*it)->getWidth();
583 if (!hExpander.empty()) {
586 std::vector<Widget*> maxExpanders;
587 while ((freeSpace != 0) && maxExpanders.size() < hExpander.size()) {
588 auto it = hExpander.begin();
589 for (; it != hExpander.end(); ++it) {
590 int const w = (*it)->getWidth();
591 (*it)->setWidth(w + 1);
592 if (w != (*it)->getWidth()) {
594 if (freeSpace == 0) {
598 if (std::ranges::find(maxExpanders, *it) == maxExpanders.end()) {
599 maxExpanders.push_back(*it);
608 if (!hExpander.empty() || !vExpander.empty() || vexpand) {
612 for (; currChild != endChildren; ++currChild) {
613 if (!(*currChild)->isVisible()) {
616 if (vexpand || (*currChild)->isVerticalExpand()) {
617 int const layoutH = (*currChild)->getMarginTop() +
618 ((*currChild)->getMarginBottom() > 0 ? (*currChild)->getMarginBottom() : 0);
620 rec.
height = spaceH - layoutH;
622 rec.
height = (*currChild)->getHeight();
624 rec.
x += (*currChild)->getMarginLeft();
625 rec.
y = (*currChild)->getMarginTop();
626 rec.
width = (*currChild)->getWidth();
627 (*currChild)->setDimension(rec);
631 }
else if (
mLayout == LayoutPolicy::Circular && visibleChilds > 0) {
632 float const angle = 360.0F / visibleChilds;
637 for (; currChild != endChildren; ++currChild) {
638 if (!(*currChild)->isVisible()) {
641 childMaxW = std::max(childMaxW, (*currChild)->getWidth());
642 childMaxH = std::max(childMaxH, (*currChild)->getHeight());
646 float xRadius = (spaceW - childMaxW) / 2.0F;
647 float yRadius = (spaceH - childMaxH) / 2.0F;
648 float const centerX = spaceW / 2.0F;
649 float const centerY = spaceH / 2.0F;
651 xRadius =
static_cast<float>(childMaxW);
654 yRadius =
static_cast<float>(childMaxH);
662 for (; currChild != endChildren; ++currChild) {
663 if (!(*currChild)->isVisible()) {
666 float const tmpAngle =
667 static_cast<float>(
static_cast<int>((angle * i) + 270) % 360) / (180.0F /
Mathf::pi());
668 int x =
static_cast<int>(centerX + (xRadius * std::cos(tmpAngle)));
669 int y =
static_cast<int>(centerY + (yRadius * std::sin(tmpAngle)));
670 x -= (*currChild)->getWidth() / 2;
671 y -= (*currChild)->getHeight() / 2;
673 (*currChild)->setPosition(x, y);
681 for (; currChild != endChildren; ++currChild) {
682 if (!(*currChild)->isVisible()) {
685 (*currChild)->expandContent(recursion);