summaryrefslogtreecommitdiff
path: root/src/ui/widget.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-05-15 22:38:13 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-05-15 22:38:13 +0300
commitafce90c9f6b52db97de29824d1afd1a0742550df (patch)
treec22eeafe577995215ef6edf448a35f8d8328cb8d /src/ui/widget.c
parentd268545d12db5b02ee5975acb311d5b3cd875d6a (diff)
Mobile: Various improvements and fixes
- fill the safe area with theme background - don't set button hover states if dragging/scrolling - edge-draggable widgets must be flagged as such - Preferences top panel offset matches sibling panels' offset - allow toolbar to unhide when document is not scrollable
Diffstat (limited to 'src/ui/widget.c')
-rw-r--r--src/ui/widget.c64
1 files changed, 53 insertions, 11 deletions
diff --git a/src/ui/widget.c b/src/ui/widget.c
index dd0c1b05..3a67bf4e 100644
--- a/src/ui/widget.c
+++ b/src/ui/widget.c
@@ -40,6 +40,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
40# include "../ios.h" 40# include "../ios.h"
41#endif 41#endif
42 42
43static void printInfo_Widget_(const iWidget *);
44
43void releaseChildren_Widget(iWidget *d) { 45void releaseChildren_Widget(iWidget *d) {
44 iForEach(ObjectList, i, d->children) { 46 iForEach(ObjectList, i, d->children) {
45 ((iWidget *) i.object)->parent = NULL; /* the actual reference being held */ 47 ((iWidget *) i.object)->parent = NULL; /* the actual reference being held */
@@ -59,12 +61,23 @@ void init_Widget(iWidget *d) {
59 d->bgColor = none_ColorId; 61 d->bgColor = none_ColorId;
60 d->frameColor = none_ColorId; 62 d->frameColor = none_ColorId;
61 init_Anim(&d->visualOffset, 0.0f); 63 init_Anim(&d->visualOffset, 0.0f);
64// init_Anim(&d->fadeOpacity, 0.0f);
62 d->children = NULL; 65 d->children = NULL;
63 d->parent = NULL; 66 d->parent = NULL;
64 d->commandHandler = NULL; 67 d->commandHandler = NULL;
65 iZap(d->padding); 68 iZap(d->padding);
66} 69}
67 70
71#if 0
72static void animateFadeOpacity_Widget_(void *ptr) {
73 iWidget *d = ptr;
74 postRefresh_App();
75 if (!isFinished_Anim(&d->fadeOpacity)) {
76 addTicker_App(animateFadeOpacity_Widget_, ptr);
77 }
78}
79#endif
80
68static void visualOffsetAnimation_Widget_(void *ptr) { 81static void visualOffsetAnimation_Widget_(void *ptr) {
69 iWidget *d = ptr; 82 iWidget *d = ptr;
70 postRefresh_App(); 83 postRefresh_App();
@@ -89,10 +102,12 @@ void deinit_Widget(iWidget *d) {
89 if (d->flags & visualOffset_WidgetFlag) { 102 if (d->flags & visualOffset_WidgetFlag) {
90 removeTicker_App(visualOffsetAnimation_Widget_, d); 103 removeTicker_App(visualOffsetAnimation_Widget_, d);
91 } 104 }
105// removeTicker_App(animateFadeOpacity_Widget_, d);
92 widgetDestroyed_Touch(d); 106 widgetDestroyed_Touch(d);
93} 107}
94 108
95static void aboutToBeDestroyed_Widget_(iWidget *d) { 109static void aboutToBeDestroyed_Widget_(iWidget *d) {
110 d->flags |= destroyPending_WidgetFlag;
96 if (isFocused_Widget(d)) { 111 if (isFocused_Widget(d)) {
97 setFocus_Widget(NULL); 112 setFocus_Widget(NULL);
98 return; 113 return;
@@ -371,10 +386,13 @@ iRect innerBounds_Widget(const iWidget *d) {
371 return ib; 386 return ib;
372} 387}
373 388
374//iLocalDef iBool isArranged_Widget_(const iWidget *d) { 389iRect innerBoundsWithoutVisualOffset_Widget(const iWidget *d) {
375// return !isCollapsed_Widget_(d) && ~d->flags & fixedPosition_WidgetFlag; 390 iRect ib = adjusted_Rect(boundsWithoutVisualOffset_Widget(d),
376//} 391 init_I2(d->padding[0], d->padding[1]),
377 392 init_I2(-d->padding[2], -d->padding[3]));
393 ib.size = max_I2(zero_I2(), ib.size);
394 return ib;
395}
378 396
379static size_t numArrangedChildren_Widget_(const iWidget *d) { 397static size_t numArrangedChildren_Widget_(const iWidget *d) {
380 size_t count = 0; 398 size_t count = 0;
@@ -743,6 +761,16 @@ static void applyVisualOffset_Widget_(const iWidget *d, iInt2 *pos) {
743 pos->y += off; 761 pos->y += off;
744 } 762 }
745 } 763 }
764 if (d->flags & topPanelOffset_WidgetFlag) {
765 iConstForEach(ObjectList, i, children_Widget(parent_Widget(d))) {
766 const iWidget *child = i.object;
767 if (child == d) continue;
768 if (child->flags & (visualOffset_WidgetFlag | dragged_WidgetFlag)) {
769 const int invOff = size_Root(d->root).x - iRound(value_Anim(&child->visualOffset));
770 pos->x -= invOff / 3;
771 }
772 }
773 }
746} 774}
747 775
748iRect bounds_Widget(const iWidget *d) { 776iRect bounds_Widget(const iWidget *d) {
@@ -942,7 +970,7 @@ iBool dispatchEvent_Widget(iWidget *d, const SDL_Event *ev) {
942} 970}
943 971
944iBool scrollOverflow_Widget(iWidget *d, int delta) { 972iBool scrollOverflow_Widget(iWidget *d, int delta) {
945 iRect bounds = bounds_Widget(d); 973 iRect bounds = boundsWithoutVisualOffset_Widget(d);
946 const iInt2 rootSize = size_Root(d->root); 974 const iInt2 rootSize = size_Root(d->root);
947 const iRect winRect = safeRect_Root(d->root); 975 const iRect winRect = safeRect_Root(d->root);
948 const int yTop = top_Rect(winRect); 976 const int yTop = top_Rect(winRect);
@@ -1046,6 +1074,7 @@ void drawBackground_Widget(const iWidget *d) {
1046 if (d->flags & noBackground_WidgetFlag) { 1074 if (d->flags & noBackground_WidgetFlag) {
1047 return; 1075 return;
1048 } 1076 }
1077// iAnim *fadeOpacity = (iAnim *) &d->fadeOpacity;
1049 if (d->flags & hidden_WidgetFlag && ~d->flags & visualOffset_WidgetFlag) { 1078 if (d->flags & hidden_WidgetFlag && ~d->flags & visualOffset_WidgetFlag) {
1050 return; 1079 return;
1051 } 1080 }
@@ -1063,10 +1092,24 @@ void drawBackground_Widget(const iWidget *d) {
1063 init_Paint(&p); 1092 init_Paint(&p);
1064 drawSoftShadow_Paint(&p, bounds_Widget(d), 12 * gap_UI, black_ColorId, 30); 1093 drawSoftShadow_Paint(&p, bounds_Widget(d), 12 * gap_UI, black_ColorId, 30);
1065 } 1094 }
1066 1095 const iBool isFaded = fadeBackground &&
1067 if (fadeBackground && ~d->flags & noFadeBackground_WidgetFlag) { 1096 ~d->flags & noFadeBackground_WidgetFlag &&
1097 ~d->flags & destroyPending_WidgetFlag;
1098#if 0
1099 if (isFaded && fadeOpacity->to != 1.0f) {
1100 setValue_Anim(fadeOpacity, 1.0f, 150);
1101 animateFadeOpacity_Widget_((void *) d);
1102 }
1103 else if (!isFaded && fadeOpacity->to != 0.0f) {
1104 setValue_Anim(fadeOpacity, 0.0f, 150);
1105 animateFadeOpacity_Widget_((void *) d);
1106 }
1107 if (value_Anim(fadeOpacity) > 0.0f) {
1108#endif
1109 if (isFaded) {
1068 iPaint p; 1110 iPaint p;
1069 init_Paint(&p); 1111 init_Paint(&p);
1112// p.alpha = (uint8_t) (2 * 0x50 * value_Anim(&d->fadeOpacity));
1070 p.alpha = 0x50; 1113 p.alpha = 0x50;
1071 SDL_SetRenderDrawBlendMode(renderer_Window(get_Window()), SDL_BLENDMODE_BLEND); 1114 SDL_SetRenderDrawBlendMode(renderer_Window(get_Window()), SDL_BLENDMODE_BLEND);
1072 int fadeColor; 1115 int fadeColor;
@@ -1081,9 +1124,7 @@ void drawBackground_Widget(const iWidget *d) {
1081 fadeColor = gray50_ColorId; 1124 fadeColor = gray50_ColorId;
1082 break; 1125 break;
1083 } 1126 }
1084 fillRect_Paint(&p, 1127 fillRect_Paint(&p, rect_Root(d->root), fadeColor);
1085 rect_Root(d->root),
1086 fadeColor);
1087 SDL_SetRenderDrawBlendMode(renderer_Window(get_Window()), SDL_BLENDMODE_NONE); 1128 SDL_SetRenderDrawBlendMode(renderer_Window(get_Window()), SDL_BLENDMODE_NONE);
1088 } 1129 }
1089 if (d->bgColor >= 0 || d->frameColor >= 0) { 1130 if (d->bgColor >= 0 || d->frameColor >= 0) {
@@ -1603,7 +1644,8 @@ static void printInfo_Widget_(const iWidget *d) {
1603 cstr_String(text_LabelWidget((const iLabelWidget *) d)), 1644 cstr_String(text_LabelWidget((const iLabelWidget *) d)),
1604 cstr_String(command_LabelWidget((const iLabelWidget *) d))); 1645 cstr_String(command_LabelWidget((const iLabelWidget *) d)));
1605 } 1646 }
1606 printf("size:%dx%d {min:%dx%d} [%d..%d %d:%d] flags:%08llx%s%s%s%s%s%s%s\n", 1647 printf("pos:%d,%d size:%dx%d {min:%dx%d} [%d..%d %d:%d] flags:%08llx%s%s%s%s%s%s%s\n",
1648 d->rect.pos.x, d->rect.pos.y,
1607 d->rect.size.x, d->rect.size.y, 1649 d->rect.size.x, d->rect.size.y,
1608 d->minSize.x, d->minSize.y, 1650 d->minSize.x, d->minSize.y,
1609 d->padding[0], d->padding[2], 1651 d->padding[0], d->padding[2],