diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-03-13 08:57:43 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-03-13 08:57:43 +0200 |
commit | 97d8767043174ba7901014cc904579e1a741ef30 (patch) | |
tree | f7eb54246df4aa8a8fa4ca2f2cdfab0a95325d0d /src/ui/widget.c | |
parent | 4d9c26488c25ecbadb3444f9d628a0bb6bc93fa2 (diff) |
Arrange URL child indicators; widget arrangement
The indicators in the URL input field are now arranged horizontally, so they don't overlap.
Improved arrangement of (un)collapsed widgets.
Diffstat (limited to 'src/ui/widget.c')
-rw-r--r-- | src/ui/widget.c | 54 |
1 files changed, 35 insertions, 19 deletions
diff --git a/src/ui/widget.c b/src/ui/widget.c index 3c9edccb..19546235 100644 --- a/src/ui/widget.c +++ b/src/ui/widget.c | |||
@@ -209,6 +209,16 @@ void setPadding_Widget(iWidget *d, int left, int top, int right, int bottom) { | |||
209 | d->padding[3] = bottom; | 209 | d->padding[3] = bottom; |
210 | } | 210 | } |
211 | 211 | ||
212 | void showCollapsed_Widget(iWidget *d, iBool show) { | ||
213 | const iBool isVisible = !(d->flags & hidden_WidgetFlag); | ||
214 | if ((isVisible && !show) || (!isVisible && show)) { | ||
215 | setFlags_Widget(d, hidden_WidgetFlag, !show); | ||
216 | /* The entire UI may be affected, if parents are resized due to the (un)collapsing. */ | ||
217 | arrange_Widget(get_Window()->root); | ||
218 | postRefresh_App(); | ||
219 | } | ||
220 | } | ||
221 | |||
212 | void setVisualOffset_Widget(iWidget *d, int value, uint32_t span, int animFlags) { | 222 | void setVisualOffset_Widget(iWidget *d, int value, uint32_t span, int animFlags) { |
213 | setFlags_Widget(d, visualOffset_WidgetFlag, iTrue); | 223 | setFlags_Widget(d, visualOffset_WidgetFlag, iTrue); |
214 | if (span == 0) { | 224 | if (span == 0) { |
@@ -349,36 +359,37 @@ void arrange_Widget(iWidget *d) { | |||
349 | if (!d->children) { | 359 | if (!d->children) { |
350 | return; | 360 | return; |
351 | } | 361 | } |
352 | /* Resize children to fill the parent widget. */ | ||
353 | const size_t childCount = numArrangedChildren_Widget_(d); | 362 | const size_t childCount = numArrangedChildren_Widget_(d); |
363 | /* There may still be unarranged children that need arranging internally. */ | ||
354 | if (childCount == 0) { | 364 | if (childCount == 0) { |
365 | iForEach(ObjectList, i, d->children) { | ||
366 | iWidget *child = as_Widget(i.object); | ||
367 | if (isArranged_Widget_(child)) { | ||
368 | arrange_Widget(child); | ||
369 | } | ||
370 | } | ||
355 | return; | 371 | return; |
356 | } | 372 | } |
373 | /* Resize children to fill the parent widget. */ | ||
357 | if (d->flags & resizeChildren_WidgetFlag) { | 374 | if (d->flags & resizeChildren_WidgetFlag) { |
358 | const iInt2 dirs = init_I2((d->flags & resizeWidthOfChildren_WidgetFlag) != 0, | 375 | const iInt2 dirs = init_I2((d->flags & resizeWidthOfChildren_WidgetFlag) != 0, |
359 | (d->flags & resizeHeightOfChildren_WidgetFlag) != 0); | 376 | (d->flags & resizeHeightOfChildren_WidgetFlag) != 0); |
360 | /* Collapse hidden children. */ | 377 | /* Collapse hidden children. */ |
361 | iBool uncollapsed = iFalse; | 378 | iBool collapseChanged = iFalse; |
362 | iForEach(ObjectList, c, d->children) { | 379 | iForEach(ObjectList, c, d->children) { |
363 | iWidget *child = as_Widget(c.object); | 380 | iWidget *child = as_Widget(c.object); |
364 | if (isCollapsed_Widget_(child)) { | 381 | if (!isCollapsed_Widget_(child) && child->flags & wasCollapsed_WidgetFlag) { |
365 | if (d->flags & arrangeHorizontal_WidgetFlag) { | ||
366 | setWidth_Widget_(child, 0); | ||
367 | } | ||
368 | if (d->flags & arrangeVertical_WidgetFlag) { | ||
369 | setHeight_Widget_(child, 0); | ||
370 | } | ||
371 | } | ||
372 | else if (child->flags & wasCollapsed_WidgetFlag) { | ||
373 | setFlags_Widget(child, wasCollapsed_WidgetFlag, iFalse); | 382 | setFlags_Widget(child, wasCollapsed_WidgetFlag, iFalse); |
374 | /* Undo collapse and determine the normal size again. */ | 383 | /* Undo collapse and determine the normal size again. */ |
375 | if (child->flags & arrangeSize_WidgetFlag) { | 384 | arrange_Widget(d); |
376 | arrange_Widget(d); | 385 | collapseChanged = iTrue; |
377 | uncollapsed = iTrue; | 386 | } |
378 | } | 387 | else if (isCollapsed_Widget_(child) && ~child->flags & wasCollapsed_WidgetFlag) { |
388 | setFlags_Widget(child, wasCollapsed_WidgetFlag, iTrue); | ||
389 | collapseChanged = iTrue; | ||
379 | } | 390 | } |
380 | } | 391 | } |
381 | if (uncollapsed) { | 392 | if (collapseChanged) { |
382 | arrange_Widget(d); /* Redo with the new child sizes. */ | 393 | arrange_Widget(d); /* Redo with the new child sizes. */ |
383 | return; | 394 | return; |
384 | } | 395 | } |
@@ -436,7 +447,7 @@ void arrange_Widget(iWidget *d) { | |||
436 | } | 447 | } |
437 | iForEach(ObjectList, i, d->children) { | 448 | iForEach(ObjectList, i, d->children) { |
438 | iWidget *child = as_Widget(i.object); | 449 | iWidget *child = as_Widget(i.object); |
439 | if (isArranged_Widget_(child)) { | 450 | if (isArranged_Widget_(child) && ~child->flags & parentCannotResize_WidgetFlag) { |
440 | if (dirs.x) setWidth_Widget_(child, child->flags & unpadded_WidgetFlag ? unpaddedChildSize.x : childSize.x); | 451 | if (dirs.x) setWidth_Widget_(child, child->flags & unpadded_WidgetFlag ? unpaddedChildSize.x : childSize.x); |
441 | if (dirs.y) setHeight_Widget_(child, child->flags & unpadded_WidgetFlag ? unpaddedChildSize.y : childSize.y); | 452 | if (dirs.y) setHeight_Widget_(child, child->flags & unpadded_WidgetFlag ? unpaddedChildSize.y : childSize.y); |
442 | } | 453 | } |
@@ -446,8 +457,9 @@ void arrange_Widget(iWidget *d) { | |||
446 | if (d->flags & resizeChildrenToWidestChild_WidgetFlag) { | 457 | if (d->flags & resizeChildrenToWidestChild_WidgetFlag) { |
447 | const int widest = widestChild_Widget_(d); | 458 | const int widest = widestChild_Widget_(d); |
448 | iForEach(ObjectList, i, d->children) { | 459 | iForEach(ObjectList, i, d->children) { |
449 | if (isArranged_Widget_(i.object)) { | 460 | iWidget *child = as_Widget(i.object); |
450 | setWidth_Widget_(as_Widget(i.object), widest); | 461 | if (isArranged_Widget_(child) && ~child->flags & parentCannotResize_WidgetFlag) { |
462 | setWidth_Widget_(child, widest); | ||
451 | } | 463 | } |
452 | } | 464 | } |
453 | } | 465 | } |
@@ -505,6 +517,10 @@ void arrange_Widget(iWidget *d) { | |||
505 | arrange_Widget(child); | 517 | arrange_Widget(child); |
506 | } | 518 | } |
507 | } | 519 | } |
520 | if (d->flags & moveToParentRightEdge_WidgetFlag) { | ||
521 | /* TODO: Fix this: not DRY. See beginning of method. */ | ||
522 | d->rect.pos.x = width_Rect(innerRect_Widget_(d->parent)) - width_Rect(d->rect); | ||
523 | } | ||
508 | } | 524 | } |
509 | if (d->flags & arrangeHeight_WidgetFlag) { | 525 | if (d->flags & arrangeHeight_WidgetFlag) { |
510 | setHeight_Widget_(d, bounds.size.y); | 526 | setHeight_Widget_(d, bounds.size.y); |