summaryrefslogtreecommitdiff
path: root/src/ui/widget.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-09-06 22:44:46 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-09-06 22:44:46 +0300
commit52a1652536e4e27751ac121009f85113e72afe7d (patch)
tree14738b1ee284e811b518c7726768b048c179607a /src/ui/widget.c
parent6bd9fbffec920c103d27bf780d60de314316bbd5 (diff)
Widget: API convenience; fixed position flag
Diffstat (limited to 'src/ui/widget.c')
-rw-r--r--src/ui/widget.c35
1 files changed, 27 insertions, 8 deletions
diff --git a/src/ui/widget.c b/src/ui/widget.c
index 11f1f2c0..c4003254 100644
--- a/src/ui/widget.c
+++ b/src/ui/widget.c
@@ -137,6 +137,7 @@ void setFlags_Widget(iWidget *d, int flags, iBool set) {
137 137
138void setPos_Widget(iWidget *d, iInt2 pos) { 138void setPos_Widget(iWidget *d, iInt2 pos) {
139 d->rect.pos = pos; 139 d->rect.pos = pos;
140 setFlags_Widget(d, fixedPosition_WidgetFlag, iTrue);
140} 141}
141 142
142void setSize_Widget(iWidget *d, iInt2 size) { 143void setSize_Widget(iWidget *d, iInt2 size) {
@@ -322,6 +323,9 @@ void arrange_Widget(iWidget *d) {
322 iForEach(ObjectList, i, d->children) { 323 iForEach(ObjectList, i, d->children) {
323 iWidget *child = as_Widget(i.object); 324 iWidget *child = as_Widget(i.object);
324 arrange_Widget(child); 325 arrange_Widget(child);
326 if (child->flags & fixedPosition_WidgetFlag) {
327 continue;
328 }
325 if (d->flags & (arrangeHorizontal_WidgetFlag | arrangeVertical_WidgetFlag)) { 329 if (d->flags & (arrangeHorizontal_WidgetFlag | arrangeVertical_WidgetFlag)) {
326 if (child->flags & moveToParentRightEdge_WidgetFlag) { 330 if (child->flags & moveToParentRightEdge_WidgetFlag) {
327 continue; /* Not part of the sequential arrangement .*/ 331 continue; /* Not part of the sequential arrangement .*/
@@ -460,6 +464,12 @@ iBool dispatchEvent_Widget(iWidget *d, const SDL_Event *ev) {
460 continue; 464 continue;
461 } 465 }
462 if (dispatchEvent_Widget(child, ev)) { 466 if (dispatchEvent_Widget(child, ev)) {
467 if (ev->type == SDL_MOUSEBUTTONDOWN) {
468 printf("widget %p ('%s' class:%s) ate the mouse down\n",
469 child, cstr_String(id_Widget(child)),
470 class_Widget(child)->name);
471 fflush(stdout);
472 }
463 return iTrue; 473 return iTrue;
464 } 474 }
465 } 475 }
@@ -637,8 +647,9 @@ size_t childCount_Widget(const iWidget *d) {
637 return size_ObjectList(d->children); 647 return size_ObjectList(d->children);
638} 648}
639 649
640iBool isVisible_Widget(const iWidget *d) { 650iBool isVisible_Widget(const iAnyObject *d) {
641 if (!d) return iFalse; 651 if (!d) return iFalse;
652 iAssert(isInstance_Object(d, &Class_Widget));
642 for (const iWidget *w = d; w; w = w->parent) { 653 for (const iWidget *w = d; w; w = w->parent) {
643 if (w->flags & hidden_WidgetFlag) { 654 if (w->flags & hidden_WidgetFlag) {
644 return iFalse; 655 return iFalse;
@@ -647,7 +658,8 @@ iBool isVisible_Widget(const iWidget *d) {
647 return iTrue; 658 return iTrue;
648} 659}
649 660
650iBool isDisabled_Widget(const iWidget *d) { 661iBool isDisabled_Widget(const iAnyObject *d) {
662 iAssert(isInstance_Object(d, &Class_Widget));
651 for (const iWidget *w = d; w; w = w->parent) { 663 for (const iWidget *w = d; w; w = w->parent) {
652 if (w->flags & disabled_WidgetFlag) { 664 if (w->flags & disabled_WidgetFlag) {
653 return iTrue; 665 return iTrue;
@@ -656,16 +668,19 @@ iBool isDisabled_Widget(const iWidget *d) {
656 return iFalse; 668 return iFalse;
657} 669}
658 670
659iBool isFocused_Widget(const iWidget *d) { 671iBool isFocused_Widget(const iAnyObject *d) {
672 iAssert(isInstance_Object(d, &Class_Widget));
660 return rootData_.focus == d; 673 return rootData_.focus == d;
661} 674}
662 675
663iBool isHover_Widget(const iWidget *d) { 676iBool isHover_Widget(const iAnyObject *d) {
677 iAssert(isInstance_Object(d, &Class_Widget));
664 return rootData_.hover == d; 678 return rootData_.hover == d;
665} 679}
666 680
667iBool isSelected_Widget(const iWidget *d) { 681iBool isSelected_Widget(const iAnyObject *d) {
668 return d && (d->flags & selected_WidgetFlag) != 0; 682 iAssert(isInstance_Object(d, &Class_Widget));
683 return d && (flags_Widget(d) & selected_WidgetFlag) != 0;
669} 684}
670 685
671iBool equalWidget_Command(const char *cmd, const iWidget *widget, const char *checkCommand) { 686iBool equalWidget_Command(const char *cmd, const iWidget *widget, const char *checkCommand) {
@@ -764,7 +779,7 @@ iWidget *mouseGrab_Widget(void) {
764 return rootData_.mouseGrab; 779 return rootData_.mouseGrab;
765} 780}
766 781
767void postCommand_Widget(const iWidget *d, const char *cmd, ...) { 782void postCommand_Widget(const iAnyObject *d, const char *cmd, ...) {
768 iString str; 783 iString str;
769 init_String(&str); { 784 init_String(&str); {
770 va_list args; 785 va_list args;
@@ -778,14 +793,18 @@ void postCommand_Widget(const iWidget *d, const char *cmd, ...) {
778 remove_Block(&str.chars, 0, 1); 793 remove_Block(&str.chars, 0, 1);
779 } 794 }
780 if (!isGlobal) { 795 if (!isGlobal) {
796 iAssert(isInstance_Object(d, &Class_Widget));
781 appendFormat_String(&str, " ptr:%p", d); 797 appendFormat_String(&str, " ptr:%p", d);
782 } 798 }
783 postCommandString_App(&str); 799 postCommandString_App(&str);
784 deinit_String(&str); 800 deinit_String(&str);
785} 801}
786 802
787void refresh_Widget(const iWidget *d) { 803void refresh_Widget(const iAnyObject *d) {
788 /* TODO: Could be widget specific, if parts of the tree are cached. */ 804 /* TODO: Could be widget specific, if parts of the tree are cached. */
805 /* TODO: The visbuffer in DocumentWidget and ListWidget could be moved to be a general
806 purpose feature of Widget. */
807 iAssert(isInstance_Object(d, &Class_Widget));
789 iUnused(d); 808 iUnused(d);
790 postRefresh_App(); 809 postRefresh_App();
791} 810}