diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-09-06 22:44:46 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-09-06 22:44:46 +0300 |
commit | 52a1652536e4e27751ac121009f85113e72afe7d (patch) | |
tree | 14738b1ee284e811b518c7726768b048c179607a /src/ui | |
parent | 6bd9fbffec920c103d27bf780d60de314316bbd5 (diff) |
Widget: API convenience; fixed position flag
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/widget.c | 35 | ||||
-rw-r--r-- | src/ui/widget.h | 19 |
2 files changed, 39 insertions, 15 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 | ||
138 | void setPos_Widget(iWidget *d, iInt2 pos) { | 138 | void 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 | ||
142 | void setSize_Widget(iWidget *d, iInt2 size) { | 143 | void 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 | ||
640 | iBool isVisible_Widget(const iWidget *d) { | 650 | iBool 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 | ||
650 | iBool isDisabled_Widget(const iWidget *d) { | 661 | iBool 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 | ||
659 | iBool isFocused_Widget(const iWidget *d) { | 671 | iBool 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 | ||
663 | iBool isHover_Widget(const iWidget *d) { | 676 | iBool 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 | ||
667 | iBool isSelected_Widget(const iWidget *d) { | 681 | iBool 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 | ||
671 | iBool equalWidget_Command(const char *cmd, const iWidget *widget, const char *checkCommand) { | 686 | iBool 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 | ||
767 | void postCommand_Widget(const iWidget *d, const char *cmd, ...) { | 782 | void 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 | ||
787 | void refresh_Widget(const iWidget *d) { | 803 | void 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 | } |
diff --git a/src/ui/widget.h b/src/ui/widget.h index b1b7a1d7..25208c30 100644 --- a/src/ui/widget.h +++ b/src/ui/widget.h | |||
@@ -59,6 +59,7 @@ enum iWidgetFlag { | |||
59 | keepOnTop_WidgetFlag = iBit(13), /* gets events first; drawn last */ | 59 | keepOnTop_WidgetFlag = iBit(13), /* gets events first; drawn last */ |
60 | mouseModal_WidgetFlag = iBit(14), /* eats all unprocessed mouse events */ | 60 | mouseModal_WidgetFlag = iBit(14), /* eats all unprocessed mouse events */ |
61 | /* arrange behavior */ | 61 | /* arrange behavior */ |
62 | fixedPosition_WidgetFlag = iBit(16), | ||
62 | arrangeHorizontal_WidgetFlag = iBit(17), /* arrange children horizontally */ | 63 | arrangeHorizontal_WidgetFlag = iBit(17), /* arrange children horizontally */ |
63 | arrangeVertical_WidgetFlag = iBit(18), /* arrange children vertically */ | 64 | arrangeVertical_WidgetFlag = iBit(18), /* arrange children vertically */ |
64 | arrangeWidth_WidgetFlag = iBit(19), /* area of children becomes parent size */ | 65 | arrangeWidth_WidgetFlag = iBit(19), /* area of children becomes parent size */ |
@@ -142,16 +143,20 @@ void draw_Widget (const iWidget *); | |||
142 | void drawBackground_Widget(const iWidget *); | 143 | void drawBackground_Widget(const iWidget *); |
143 | void drawChildren_Widget (const iWidget *); | 144 | void drawChildren_Widget (const iWidget *); |
144 | 145 | ||
146 | iLocalDef int width_Widget(const iAnyObject *d) { | ||
147 | iAssert(isInstance_Object(d, &Class_Widget)); | ||
148 | return ((const iWidget *) d)->rect.size.x; | ||
149 | } | ||
145 | iLocalDef iObjectList *children_Widget(iAnyObject *d) { | 150 | iLocalDef iObjectList *children_Widget(iAnyObject *d) { |
146 | iAssert(isInstance_Object(d, &Class_Widget)); | 151 | iAssert(isInstance_Object(d, &Class_Widget)); |
147 | return ((iWidget *) d)->children; | 152 | return ((iWidget *) d)->children; |
148 | } | 153 | } |
149 | 154 | ||
150 | iBool isVisible_Widget (const iWidget *); | 155 | iBool isVisible_Widget (const iAnyObject *); |
151 | iBool isDisabled_Widget (const iWidget *); | 156 | iBool isDisabled_Widget (const iAnyObject *); |
152 | iBool isFocused_Widget (const iWidget *); | 157 | iBool isFocused_Widget (const iAnyObject *); |
153 | iBool isHover_Widget (const iWidget *); | 158 | iBool isHover_Widget (const iAnyObject *); |
154 | iBool isSelected_Widget (const iWidget *); | 159 | iBool isSelected_Widget (const iAnyObject *); |
155 | iBool isCommand_Widget (const iWidget *d, const SDL_Event *ev, const char *cmd); | 160 | iBool isCommand_Widget (const iWidget *d, const SDL_Event *ev, const char *cmd); |
156 | iBool hasParent_Widget (const iWidget *d, const iWidget *someParent); | 161 | iBool hasParent_Widget (const iWidget *d, const iWidget *someParent); |
157 | void setId_Widget (iWidget *, const char *id); | 162 | void setId_Widget (iWidget *, const char *id); |
@@ -172,8 +177,8 @@ size_t childIndex_Widget (const iWidget *, const iAnyObject *child); /* O(n) | |||
172 | void arrange_Widget (iWidget *); | 177 | void arrange_Widget (iWidget *); |
173 | iBool dispatchEvent_Widget(iWidget *, const SDL_Event *); | 178 | iBool dispatchEvent_Widget(iWidget *, const SDL_Event *); |
174 | iBool processEvent_Widget (iWidget *, const SDL_Event *); | 179 | iBool processEvent_Widget (iWidget *, const SDL_Event *); |
175 | void postCommand_Widget (const iWidget *, const char *cmd, ...); | 180 | void postCommand_Widget (const iAnyObject *, const char *cmd, ...); |
176 | void refresh_Widget (const iWidget *); | 181 | void refresh_Widget (const iAnyObject *); |
177 | 182 | ||
178 | void setFocus_Widget (iWidget *); | 183 | void setFocus_Widget (iWidget *); |
179 | iWidget *focus_Widget (void); | 184 | iWidget *focus_Widget (void); |