summaryrefslogtreecommitdiff
path: root/src/ui/widget.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-03-13 07:21:24 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-03-13 07:21:24 +0200
commit4d9c26488c25ecbadb3444f9d628a0bb6bc93fa2 (patch)
tree53db24e5251f386eceb40b688f4c792fbbf4cd4e /src/ui/widget.c
parentc273ca3ea79d8badd92e9704453d7306e0d85739 (diff)
Widget: Arranging cleanup wrt. collapsing
Diffstat (limited to 'src/ui/widget.c')
-rw-r--r--src/ui/widget.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/ui/widget.c b/src/ui/widget.c
index 4fad3c86..3c9edccb 100644
--- a/src/ui/widget.c
+++ b/src/ui/widget.c
@@ -304,10 +304,14 @@ iRect innerBounds_Widget(const iWidget *d) {
304 return ib; 304 return ib;
305} 305}
306 306
307iLocalDef iBool isArranged_Widget_(const iWidget *d) {
308 return !isCollapsed_Widget_(d) && ~d->flags & fixedPosition_WidgetFlag;
309}
310
307static size_t numArrangedChildren_Widget_(const iWidget *d) { 311static size_t numArrangedChildren_Widget_(const iWidget *d) {
308 size_t count = 0; 312 size_t count = 0;
309 iConstForEach(ObjectList, i, d->children) { 313 iConstForEach(ObjectList, i, d->children) {
310 if (~flags_Widget(i.object) & fixedPosition_WidgetFlag) { 314 if (isArranged_Widget_(d)) {
311 count++; 315 count++;
312 } 316 }
313 } 317 }
@@ -375,7 +379,7 @@ void arrange_Widget(iWidget *d) {
375 } 379 }
376 } 380 }
377 if (uncollapsed) { 381 if (uncollapsed) {
378 arrange_Widget(d); /* Redo with the next child sizes. */ 382 arrange_Widget(d); /* Redo with the new child sizes. */
379 return; 383 return;
380 } 384 }
381 const int expCount = numExpandingChildren_Widget_(d); 385 const int expCount = numExpandingChildren_Widget_(d);
@@ -384,7 +388,7 @@ void arrange_Widget(iWidget *d) {
384 iInt2 avail = innerRect_Widget_(d).size; 388 iInt2 avail = innerRect_Widget_(d).size;
385 iConstForEach(ObjectList, i, d->children) { 389 iConstForEach(ObjectList, i, d->children) {
386 const iWidget *child = constAs_Widget(i.object); 390 const iWidget *child = constAs_Widget(i.object);
387 if (child->flags & fixedPosition_WidgetFlag) { 391 if (!isArranged_Widget_(child)) {
388 continue; 392 continue;
389 } 393 }
390 if (~child->flags & expand_WidgetFlag) { 394 if (~child->flags & expand_WidgetFlag) {
@@ -394,8 +398,7 @@ void arrange_Widget(iWidget *d) {
394 avail = divi_I2(max_I2(zero_I2(), avail), expCount); 398 avail = divi_I2(max_I2(zero_I2(), avail), expCount);
395 iForEach(ObjectList, j, d->children) { 399 iForEach(ObjectList, j, d->children) {
396 iWidget *child = as_Widget(j.object); 400 iWidget *child = as_Widget(j.object);
397 if (isCollapsed_Widget_(child) || 401 if (!isArranged_Widget_(child)) {
398 child->flags & (parentCannotResize_WidgetFlag | fixedPosition_WidgetFlag)) {
399 continue; 402 continue;
400 } 403 }
401 if (child->flags & expand_WidgetFlag) { 404 if (child->flags & expand_WidgetFlag) {
@@ -433,7 +436,7 @@ void arrange_Widget(iWidget *d) {
433 } 436 }
434 iForEach(ObjectList, i, d->children) { 437 iForEach(ObjectList, i, d->children) {
435 iWidget *child = as_Widget(i.object); 438 iWidget *child = as_Widget(i.object);
436 if (!isCollapsed_Widget_(child) && ~child->flags & parentCannotResize_WidgetFlag) { 439 if (isArranged_Widget_(child)) {
437 if (dirs.x) setWidth_Widget_(child, child->flags & unpadded_WidgetFlag ? unpaddedChildSize.x : childSize.x); 440 if (dirs.x) setWidth_Widget_(child, child->flags & unpadded_WidgetFlag ? unpaddedChildSize.x : childSize.x);
438 if (dirs.y) setHeight_Widget_(child, child->flags & unpadded_WidgetFlag ? unpaddedChildSize.y : childSize.y); 441 if (dirs.y) setHeight_Widget_(child, child->flags & unpadded_WidgetFlag ? unpaddedChildSize.y : childSize.y);
439 } 442 }
@@ -443,14 +446,16 @@ void arrange_Widget(iWidget *d) {
443 if (d->flags & resizeChildrenToWidestChild_WidgetFlag) { 446 if (d->flags & resizeChildrenToWidestChild_WidgetFlag) {
444 const int widest = widestChild_Widget_(d); 447 const int widest = widestChild_Widget_(d);
445 iForEach(ObjectList, i, d->children) { 448 iForEach(ObjectList, i, d->children) {
446 setWidth_Widget_(as_Widget(i.object), widest); 449 if (isArranged_Widget_(i.object)) {
450 setWidth_Widget_(as_Widget(i.object), widest);
451 }
447 } 452 }
448 } 453 }
449 iInt2 pos = initv_I2(d->padding); 454 iInt2 pos = initv_I2(d->padding);
450 iForEach(ObjectList, i, d->children) { 455 iForEach(ObjectList, i, d->children) {
451 iWidget *child = as_Widget(i.object); 456 iWidget *child = as_Widget(i.object);
452 arrange_Widget(child); 457 arrange_Widget(child);
453 if (child->flags & fixedPosition_WidgetFlag) { 458 if (!isArranged_Widget_(child)) {
454 continue; 459 continue;
455 } 460 }
456 if (child->flags & centerHorizontal_WidgetFlag) { 461 if (child->flags & centerHorizontal_WidgetFlag) {
@@ -478,6 +483,9 @@ void arrange_Widget(iWidget *d) {
478 iRect bounds = zero_Rect(); 483 iRect bounds = zero_Rect();
479 iConstForEach(ObjectList, i, d->children) { 484 iConstForEach(ObjectList, i, d->children) {
480 const iWidget *child = constAs_Widget(i.object); 485 const iWidget *child = constAs_Widget(i.object);
486 if (isCollapsed_Widget_(child)) {
487 continue;
488 }
481 if (isEmpty_Rect(bounds)) { 489 if (isEmpty_Rect(bounds)) {
482 bounds = child->rect; 490 bounds = child->rect;
483 } 491 }