diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-04-04 20:42:56 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-04-04 20:42:56 +0300 |
commit | 7c1645bb1fae8a233fd2afe088e8d198f17b4831 (patch) | |
tree | 9a1d6329ffaefe48f6961e0c23a661d4d4fe85cf | |
parent | 265667b8a428d26b588459cb150d242990cf92f5 (diff) |
Widget: Added a debug utility
Printing the list of parents.
-rw-r--r-- | src/ui/widget.c | 87 | ||||
-rw-r--r-- | src/ui/widget.h | 1 |
2 files changed, 56 insertions, 32 deletions
diff --git a/src/ui/widget.c b/src/ui/widget.c index baabf673..cef36a00 100644 --- a/src/ui/widget.c +++ b/src/ui/widget.c | |||
@@ -1475,12 +1475,39 @@ void refresh_Widget(const iAnyObject *d) { | |||
1475 | postRefresh_App(); | 1475 | postRefresh_App(); |
1476 | } | 1476 | } |
1477 | 1477 | ||
1478 | /* Debug utility for inspecting widget trees. */ | 1478 | void raise_Widget(iWidget *d) { |
1479 | #include "labelwidget.h" | 1479 | iPtrArray *onTop = onTop_RootData_(); |
1480 | static void printTree_Widget_(const iWidget *d, int indent) { | 1480 | if (d->flags & keepOnTop_WidgetFlag) { |
1481 | for (int i = 0; i < indent; ++i) { | 1481 | iAssert(indexOf_PtrArray(onTop, d) != iInvalidPos); |
1482 | fwrite(" ", 4, 1, stdout); | 1482 | removeOne_PtrArray(onTop, d); |
1483 | pushBack_PtrArray(onTop, d); | ||
1483 | } | 1484 | } |
1485 | } | ||
1486 | |||
1487 | iBool hasVisibleChildOnTop_Widget(const iWidget *parent) { | ||
1488 | iConstForEach(ObjectList, i, parent->children) { | ||
1489 | const iWidget *child = i.object; | ||
1490 | if (~child->flags & hidden_WidgetFlag && child->flags & keepOnTop_WidgetFlag) { | ||
1491 | return iTrue; | ||
1492 | } | ||
1493 | if (hasVisibleChildOnTop_Widget(child)) { | ||
1494 | return iTrue; | ||
1495 | } | ||
1496 | } | ||
1497 | return iFalse; | ||
1498 | } | ||
1499 | |||
1500 | iBeginDefineClass(Widget) | ||
1501 | .processEvent = processEvent_Widget, | ||
1502 | .draw = draw_Widget, | ||
1503 | iEndDefineClass(Widget) | ||
1504 | |||
1505 | /*---------------------------------------------------------------------------------------------- | ||
1506 | Debug utilities for inspecting widget trees. | ||
1507 | */ | ||
1508 | |||
1509 | #include "labelwidget.h" | ||
1510 | static void printInfo_Widget_(const iWidget *d) { | ||
1484 | printf("[%p] %s:\"%s\" ", d, class_Widget(d)->name, cstr_String(&d->id)); | 1511 | printf("[%p] %s:\"%s\" ", d, class_Widget(d)->name, cstr_String(&d->id)); |
1485 | if (isInstance_Object(d, &Class_LabelWidget)) { | 1512 | if (isInstance_Object(d, &Class_LabelWidget)) { |
1486 | printf("(%s|%s) ", | 1513 | printf("(%s|%s) ", |
@@ -1498,43 +1525,39 @@ static void printTree_Widget_(const iWidget *d, int indent) { | |||
1498 | d->flags & fixedWidth_WidgetFlag ? " fixW" : "", | 1525 | d->flags & fixedWidth_WidgetFlag ? " fixW" : "", |
1499 | d->flags & fixedHeight_WidgetFlag ? " fixH" : "", | 1526 | d->flags & fixedHeight_WidgetFlag ? " fixH" : "", |
1500 | d->flags & resizeToParentWidth_WidgetFlag ? " rsPrnW" : ""); | 1527 | d->flags & resizeToParentWidth_WidgetFlag ? " rsPrnW" : ""); |
1501 | iConstForEach(ObjectList, i, d->children) { | ||
1502 | printTree_Widget_(i.object, indent + 1); | ||
1503 | } | ||
1504 | } | 1528 | } |
1505 | 1529 | ||
1506 | void raise_Widget(iWidget *d) { | 1530 | static void printTree_Widget_(const iWidget *d, int indent) { |
1507 | iPtrArray *onTop = onTop_RootData_(); | 1531 | for (int i = 0; i < indent; ++i) { |
1508 | if (d->flags & keepOnTop_WidgetFlag) { | 1532 | fwrite(" ", 4, 1, stdout); |
1509 | iAssert(indexOf_PtrArray(onTop, d) != iInvalidPos); | ||
1510 | removeOne_PtrArray(onTop, d); | ||
1511 | pushBack_PtrArray(onTop, d); | ||
1512 | } | 1533 | } |
1513 | } | 1534 | printInfo_Widget_(d); |
1514 | 1535 | iConstForEach(ObjectList, i, d->children) { | |
1515 | iBool hasVisibleChildOnTop_Widget(const iWidget *parent) { | 1536 | printTree_Widget_(i.object, indent + 1); |
1516 | iConstForEach(ObjectList, i, parent->children) { | ||
1517 | const iWidget *child = i.object; | ||
1518 | if (~child->flags & hidden_WidgetFlag && child->flags & keepOnTop_WidgetFlag) { | ||
1519 | return iTrue; | ||
1520 | } | ||
1521 | if (hasVisibleChildOnTop_Widget(child)) { | ||
1522 | return iTrue; | ||
1523 | } | ||
1524 | } | 1537 | } |
1525 | return iFalse; | ||
1526 | } | 1538 | } |
1527 | 1539 | ||
1528 | void printTree_Widget(const iWidget *d) { | 1540 | void printTree_Widget(const iWidget *d) { |
1529 | if (!d) { | 1541 | if (!d) { |
1530 | printf("[NULL]\n"); | 1542 | puts("[NULL]"); |
1531 | return; | 1543 | return; |
1532 | } | 1544 | } |
1533 | printTree_Widget_(d, 0); | 1545 | printTree_Widget_(d, 0); |
1534 | } | 1546 | } |
1535 | 1547 | ||
1536 | iBeginDefineClass(Widget) | 1548 | void identify_Widget(const iWidget *d) { |
1537 | .processEvent = processEvent_Widget, | 1549 | if (!d) { |
1538 | .draw = draw_Widget, | 1550 | puts("[NULL}"); |
1539 | iEndDefineClass(Widget) | 1551 | return; |
1540 | 1552 | } | |
1553 | int indent = 0; | ||
1554 | for (const iWidget *w = d; w; w = w->parent, indent++) { | ||
1555 | if (indent > 0) { | ||
1556 | for (int i = 0; i < indent; ++i) { | ||
1557 | fwrite(" ", 2, 1, stdout); | ||
1558 | } | ||
1559 | } | ||
1560 | printInfo_Widget_(w); | ||
1561 | } | ||
1562 | fflush(stdout); | ||
1563 | } | ||
diff --git a/src/ui/widget.h b/src/ui/widget.h index 4c5b7d85..dc79a22c 100644 --- a/src/ui/widget.h +++ b/src/ui/widget.h | |||
@@ -259,3 +259,4 @@ void raise_Widget (iWidget *); | |||
259 | iBool hasVisibleChildOnTop_Widget | 259 | iBool hasVisibleChildOnTop_Widget |
260 | (const iWidget *parent); | 260 | (const iWidget *parent); |
261 | void printTree_Widget (const iWidget *); | 261 | void printTree_Widget (const iWidget *); |
262 | void identify_Widget (const iWidget *); /* prints to stdout */ | ||