summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-12-17 07:04:07 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-12-17 07:04:07 +0200
commit8298f3fc47d2c859ffd1cd72f6b4b0c480565bcf (patch)
tree781dcb9348f67b86f9686ac1cc54158c939eaf8c /src
parent51a46787f7e37a5b9afac4d895e117824d7fce38 (diff)
DocumentWidget: Swipe animation glitches
Most crucially, sometimes the swipe placeholders would not get deleted at all because the visual offset animation was not finishing as expected. This would cause a number of problems with the document behavior.
Diffstat (limited to 'src')
-rw-r--r--src/ui/documentwidget.c30
-rw-r--r--src/ui/widget.c12
2 files changed, 33 insertions, 9 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index f4e56d63..d0a9a55d 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -445,6 +445,8 @@ void cancelAllRequests_DocumentWidget(iDocumentWidget *d) {
445} 445}
446 446
447void deinit_DocumentWidget(iDocumentWidget *d) { 447void deinit_DocumentWidget(iDocumentWidget *d) {
448// printf("\n* * * * * * * *\nDEINIT DOCUMENT: %s\n* * * * * * * *\n\n",
449// cstr_String(&d->widget.id)); fflush(stdout);
448 cancelAllRequests_DocumentWidget(d); 450 cancelAllRequests_DocumentWidget(d);
449 pauseAllPlayers_Media(media_GmDocument(d->doc), iTrue); 451 pauseAllPlayers_Media(media_GmDocument(d->doc), iTrue);
450 removeTicker_App(animate_DocumentWidget_, d); 452 removeTicker_App(animate_DocumentWidget_, d);
@@ -2690,12 +2692,17 @@ static void setupSwipeOverlay_DocumentWidget_(iDocumentWidget *d, iWidget *overl
2690 const int toPos = width_Widget(overlay); 2692 const int toPos = width_Widget(overlay);
2691 setVisualOffset_Widget(overlay, fromPos, 0, 0); 2693 setVisualOffset_Widget(overlay, fromPos, 0, 0);
2692 /* Bigger screen, faster swipes. */ 2694 /* Bigger screen, faster swipes. */
2693 const float devFactor = (deviceType_App() == phone_AppDeviceType ? 1.0f : 2.0f); 2695 if (deviceType_App() == desktop_AppDeviceType) {
2694 float swipe = iClamp(d->swipeSpeed, devFactor * 400, devFactor * 1000) * gap_UI; 2696 setVisualOffset_Widget(overlay, toPos, 250, easeOut_AnimFlag | softer_AnimFlag);
2695 uint32_t span = ((toPos - fromPos) / swipe) * 1000; 2697 }
2696// printf("from:%d to:%d swipe:%f span:%u\n", fromPos, toPos, d->swipeSpeed, span); 2698 else {
2697 setVisualOffset_Widget(overlay, toPos, span, deviceType_App() == tablet_AppDeviceType ? 2699 const float devFactor = (deviceType_App() == phone_AppDeviceType ? 1.0f : 2.0f);
2698 easeOut_AnimFlag : 0); 2700 float swipe = iClamp(d->swipeSpeed, devFactor * 400, devFactor * 1000) * gap_UI;
2701 uint32_t span = ((toPos - fromPos) / swipe) * 1000;
2702 // printf("from:%d to:%d swipe:%f span:%u\n", fromPos, toPos, d->swipeSpeed, span);
2703 setVisualOffset_Widget(overlay, toPos, span, deviceType_App() == tablet_AppDeviceType ?
2704 easeOut_AnimFlag : 0);
2705 }
2699 setVisualOffset_Widget(w, 0, 0, 0); 2706 setVisualOffset_Widget(w, 0, 0, 0);
2700} 2707}
2701 2708
@@ -2722,9 +2729,12 @@ static iBool handleSwipe_DocumentWidget_(iDocumentWidget *d, const char *cmd) {
2722 return iTrue; 2729 return iTrue;
2723 } 2730 }
2724 iWidget *swipeParent = swipeParent_DocumentWidget_(d); 2731 iWidget *swipeParent = swipeParent_DocumentWidget_(d);
2732 if (findChild_Widget(swipeParent, "swipeout")) {
2733 return iTrue; /* too fast, previous animation hasn't finished */
2734 }
2725 /* The temporary "swipein" will display the previous page until the finger is lifted. */ 2735 /* The temporary "swipein" will display the previous page until the finger is lifted. */
2726 iDocumentWidget *swipeIn = findChild_Widget(swipeParent, "swipein"); 2736 iDocumentWidget *swipeIn = findChild_Widget(swipeParent, "swipein");
2727 if (!swipeIn) { 2737 if (!swipeIn) {
2728 swipeIn = new_DocumentWidget(); 2738 swipeIn = new_DocumentWidget();
2729 swipeIn->flags |= animationPlaceholder_DocumentWidgetFlag; 2739 swipeIn->flags |= animationPlaceholder_DocumentWidgetFlag;
2730 setId_Widget(as_Widget(swipeIn), "swipein"); 2740 setId_Widget(as_Widget(swipeIn), "swipein");
@@ -2761,12 +2771,15 @@ static iBool handleSwipe_DocumentWidget_(iDocumentWidget *d, const char *cmd) {
2761 if (offset < -get_Window()->pixelRatio * 10) { 2771 if (offset < -get_Window()->pixelRatio * 10) {
2762 int animSpan = 10; 2772 int animSpan = 10;
2763 if (!atNewest_History(d->mod.history) && ~flags_Widget(w) & dragged_WidgetFlag) { 2773 if (!atNewest_History(d->mod.history) && ~flags_Widget(w) & dragged_WidgetFlag) {
2774 iWidget *swipeParent = swipeParent_DocumentWidget_(d);
2775 if (findChild_Widget(swipeParent, "swipeout")) {
2776 return iTrue; /* too fast, previous animation hasn't finished */
2777 }
2764 /* Setup the drag. `d` will be moving with the finger. */ 2778 /* Setup the drag. `d` will be moving with the finger. */
2765 animSpan = 0; 2779 animSpan = 0;
2766 postCommand_Widget(d, "navigate.forward"); 2780 postCommand_Widget(d, "navigate.forward");
2767 setFlags_Widget(w, dragged_WidgetFlag, iTrue); 2781 setFlags_Widget(w, dragged_WidgetFlag, iTrue);
2768 /* Set up the swipe dummy. */ 2782 /* Set up the swipe dummy. */
2769 iWidget *swipeParent = swipeParent_DocumentWidget_(d);
2770 iDocumentWidget *target = new_DocumentWidget(); 2783 iDocumentWidget *target = new_DocumentWidget();
2771 target->flags |= animationPlaceholder_DocumentWidgetFlag; 2784 target->flags |= animationPlaceholder_DocumentWidgetFlag;
2772 setId_Widget(as_Widget(target), "swipeout"); 2785 setId_Widget(as_Widget(target), "swipeout");
@@ -2820,6 +2833,7 @@ static iBool handleSwipe_DocumentWidget_(iDocumentWidget *d, const char *cmd) {
2820// setupSwipeOverlay_DocumentWidget_(d, as_Widget(swipeOut)); 2833// setupSwipeOverlay_DocumentWidget_(d, as_Widget(swipeOut));
2821 return iTrue; 2834 return iTrue;
2822 } 2835 }
2836 iAssert(~d->flags & animationPlaceholder_DocumentWidgetFlag);
2823 setFlags_Widget(w, dragged_WidgetFlag, iFalse); 2837 setFlags_Widget(w, dragged_WidgetFlag, iFalse);
2824 setVisualOffset_Widget(w, 0, 250, easeOut_AnimFlag | softer_AnimFlag); 2838 setVisualOffset_Widget(w, 0, 250, easeOut_AnimFlag | softer_AnimFlag);
2825 return iTrue; 2839 return iTrue;
diff --git a/src/ui/widget.c b/src/ui/widget.c
index df74a744..1b90378a 100644
--- a/src/ui/widget.c
+++ b/src/ui/widget.c
@@ -144,8 +144,10 @@ static void visualOffsetAnimation_Widget_(void *ptr) {
144 iWidget *d = ptr; 144 iWidget *d = ptr;
145 postRefresh_App(); 145 postRefresh_App();
146 d->root->didAnimateVisualOffsets = iTrue; 146 d->root->didAnimateVisualOffsets = iTrue;
147// printf("'%s' visoffanim: fin:%d val:%f\n", cstr_String(&d->id),
148// isFinished_Anim(&d->visualOffset), value_Anim(&d->visualOffset)); fflush(stdout);
147 if (!isFinished_Anim(&d->visualOffset)) { 149 if (!isFinished_Anim(&d->visualOffset)) {
148 addTicker_App(visualOffsetAnimation_Widget_, ptr); 150 addTickerRoot_App(visualOffsetAnimation_Widget_, d->root, ptr);
149 } 151 }
150 else { 152 else {
151 d->flags &= ~visualOffset_WidgetFlag; 153 d->flags &= ~visualOffset_WidgetFlag;
@@ -919,6 +921,14 @@ int visualOffsetByReference_Widget(const iWidget *d) {
919// const float factor = width_Widget(d) / (float) size_Root(d->root).x; 921// const float factor = width_Widget(d) / (float) size_Root(d->root).x;
920 const int invOff = width_Widget(d) - iRound(value_Anim(&child->visualOffset)); 922 const int invOff = width_Widget(d) - iRound(value_Anim(&child->visualOffset));
921 offX -= invOff / 4; 923 offX -= invOff / 4;
924#if 0
925 if (invOff) {
926 printf(" [%p] %s (%p, fin:%d visoff:%d drag:%d): invOff %d\n", d, cstr_String(&child->id), child,
927 isFinished_Anim(&child->visualOffset),
928 (child->flags & visualOffset_WidgetFlag) != 0,
929 (child->flags & dragged_WidgetFlag) != 0, invOff); fflush(stdout);
930 }
931#endif
922 } 932 }
923 } 933 }
924 return offX; 934 return offX;