From 9b7651e70cca507fd742c13898b63f1a363d3274 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Mon, 17 May 2021 11:08:57 +0300 Subject: Mobile: Swipe improvements Edge swipe direction is determined in a more dynamic way. --- src/ui/mobile.c | 6 ++++-- src/ui/touch.c | 16 +++++++++------- src/ui/widget.c | 9 +++++---- src/ui/widget.h | 3 ++- 4 files changed, 20 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/ui/mobile.c b/src/ui/mobile.c index 1c7cad8e..9e877968 100644 --- a/src/ui/mobile.c +++ b/src/ui/mobile.c @@ -392,8 +392,11 @@ void finalizeSheet_Mobile(iWidget *sheet) { setFlags_Widget(detailStack, resizeWidthOfChildren_WidgetFlag, iTrue); addChild_Widget(mainDetailSplit, iClob(detailStack)); } - //setFlags_Widget(topPanel, topPanelOffset_WidgetFlag, iTrue); /* slide with children */ addChild_Widget(topPanel, iClob(makePadding_Widget(lineHeight_Text(defaultBig_FontId)))); + /* Slide top panel with detail panels. */ { + setFlags_Widget(topPanel, refChildrenOffset_WidgetFlag, iTrue); + topPanel->offsetRef = detailStack; + } if (prefsTabs) { iRelease(removeChild_Widget(sheet, child_Widget(sheet, 0))); /* heading */ iRelease(removeChild_Widget(sheet, findChild_Widget(sheet, "dialogbuttons"))); @@ -561,7 +564,6 @@ void finalizeSheet_Mobile(iWidget *sheet) { } addPanelChild_(owner, NULL, 0, 0, prevElement); destroy_Widget(pageContent); -// setFlags_Widget(owner, drawBackgroundToBottom_WidgetFlag, iTrue); } destroyPending_Root(sheet->root); /* Additional elements for preferences. */ diff --git a/src/ui/touch.c b/src/ui/touch.c index c373ebd3..e8f53bca 100644 --- a/src/ui/touch.c +++ b/src/ui/touch.c @@ -453,8 +453,8 @@ iBool processEvent_Touch(const SDL_Event *ev) { if (edge == left_TouchEdge) { dragging = findSlidePanel_Widget_(aff); if (dragging) { - printf("Selected for dragging: "); - identify_Widget(dragging); +// printf("Selected for dragging: "); +// identify_Widget(dragging); setFlags_Widget(dragging, dragged_WidgetFlag, iTrue); } } @@ -556,7 +556,7 @@ iBool processEvent_Touch(const SDL_Event *ev) { } /* Edge swipe aborted? */ if (touch->edge == left_TouchEdge) { - if (fing->dx < 0) { + if (fing->dx < 0 && x_F3(touch->pos[0]) < tapRadiusPt_ * window->pixelRatio) { touch->edge = none_TouchEdge; if (touch->edgeDragging) { setFlags_Widget(touch->edgeDragging, dragged_WidgetFlag, iFalse); @@ -631,17 +631,19 @@ iBool processEvent_Touch(const SDL_Event *ev) { continue; } /* Edge swipes do not generate momentum. */ + const size_t lastIndex = iMin(touch->posCount - 1, lastIndex_Touch_); const uint32_t duration = nowTime - touch->startTime; - const iFloat3 gestureVector = sub_F3(pos, touch->startPos); + const iFloat3 gestureVector = sub_F3(pos, touch->pos[lastIndex]); iFloat3 velocity = zero_F3(); if (touch->edge && fabsf(2 * x_F3(gestureVector)) > fabsf(y_F3(gestureVector)) && !isStationary_Touch_(touch)) { - dispatchClick_Touch_(touch, touch->edge == left_TouchEdge ? SDL_BUTTON_X1 - : SDL_BUTTON_X2); + const int swipeDir = x_F3(gestureVector) > 0 ? +1 : -1; + dispatchClick_Touch_(touch, + touch->edge == left_TouchEdge && swipeDir > 0 ? SDL_BUTTON_X1 : + touch->edge == right_TouchEdge && swipeDir < 0 ? SDL_BUTTON_X2 : 0); setHover_Widget(NULL); } else { - const size_t lastIndex = iMin(touch->posCount - 1, lastIndex_Touch_); const uint32_t elapsed = fing->timestamp - touch->posTime[lastIndex]; const float minVelocity = 400.0f; if (elapsed < 150) { diff --git a/src/ui/widget.c b/src/ui/widget.c index 475e7c1f..3439fb1b 100644 --- a/src/ui/widget.c +++ b/src/ui/widget.c @@ -58,6 +58,7 @@ void init_Widget(iWidget *d) { d->rect = zero_Rect(); d->minSize = zero_I2(); d->sizeRef = NULL; + d->offsetRef = NULL; d->bgColor = none_ColorId; d->frameColor = none_ColorId; init_Anim(&d->visualOffset, 0.0f); @@ -755,13 +756,13 @@ static void applyVisualOffset_Widget_(const iWidget *d, iInt2 *pos) { pos->y += off; } } - if (d->flags & topPanelOffset_WidgetFlag) { - iConstForEach(ObjectList, i, children_Widget(parent_Widget(d))) { + if (d->flags & refChildrenOffset_WidgetFlag) { + iConstForEach(ObjectList, i, children_Widget(d->offsetRef)) { const iWidget *child = i.object; if (child == d) continue; if (child->flags & (visualOffset_WidgetFlag | dragged_WidgetFlag)) { const int invOff = size_Root(d->root).x - iRound(value_Anim(&child->visualOffset)); - pos->x -= invOff / 3; + pos->x -= invOff / 4; } } } @@ -1092,7 +1093,7 @@ void drawBackground_Widget(const iWidget *d) { iPaint p; init_Paint(&p); p.alpha = 0x50; - if (flags_Widget(d) & visualOffset_WidgetFlag) { + if (flags_Widget(d) & (visualOffset_WidgetFlag | dragged_WidgetFlag)) { const float area = d->rect.size.x * d->rect.size.y; const float visibleArea = area_Rect(intersect_Rect(bounds_Widget(d), rect_Root(d->root))); p.alpha *= (area > 0 ? visibleArea / area : 0.0f); diff --git a/src/ui/widget.h b/src/ui/widget.h index 53dbbff2..79d45f23 100644 --- a/src/ui/widget.h +++ b/src/ui/widget.h @@ -119,7 +119,7 @@ enum iWidgetFlag { #define noFadeBackground_WidgetFlag iBit64(60) #define destroyPending_WidgetFlag iBit64(61) /* TODO: needed? */ #define edgeDraggable_WidgetFlag iBit64(62) -#define topPanelOffset_WidgetFlag iBit64(63) /* visual offset determined by the offset of siblings */ +#define refChildrenOffset_WidgetFlag iBit64(63) /* visual offset determined by the offset of referenced children */ enum iWidgetAddPos { back_WidgetAddPos, @@ -138,6 +138,7 @@ struct Impl_Widget { iRect rect; iInt2 minSize; iWidget * sizeRef; + iWidget * offsetRef; int padding[4]; /* left, top, right, bottom */ iAnim visualOffset; int bgColor; -- cgit v1.2.3