From fe238b29132b43f07aa88cf6bb60bec1ff0d3f8d Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Mon, 14 Jun 2021 15:36:48 +0300 Subject: Swiping and sidebar; various tweaks When a page is opened from the sidebar, swiping back will now reopen the sidebar. Another swipe will dismiss the sidebar and navigate back as usual. Attempted to cache theme colors in GmDocument, but there were issues with theme changes. --- src/ui/documentwidget.c | 103 +++++++++++++++++++++++++++++++++++++----------- src/ui/documentwidget.h | 8 +++- src/ui/sidebarwidget.c | 14 +++++-- src/ui/text.c | 4 +- src/ui/touch.c | 49 +++++++---------------- src/ui/widget.c | 55 +++++++++++++------------- src/ui/widget.h | 9 +++-- 7 files changed, 146 insertions(+), 96 deletions(-) (limited to 'src/ui') diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index eae5d713..3fc22bdf 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c @@ -130,7 +130,8 @@ void deinit_PersistentDocumentState(iPersistentDocumentState *d) { void serialize_PersistentDocumentState(const iPersistentDocumentState *d, iStream *outs) { serialize_String(d->url, outs); - writeU16_Stream(outs, d->reloadInterval & 7); + uint16_t params = d->reloadInterval & 7; + writeU16_Stream(outs, params); serialize_History(d->history, outs); } @@ -223,6 +224,7 @@ enum iDocumentWidgetFlag { movingSelectMarkEnd_DocumentWidgetFlag = iBit(11), otherRootByDefault_DocumentWidgetFlag = iBit(12), /* links open to other root by default */ urlChanged_DocumentWidgetFlag = iBit(13), + openedFromSidebar_DocumentWidgetFlag = iBit(14), }; enum iDocumentLinkOrdinalMode { @@ -1606,7 +1608,8 @@ static void updateFromCachedResponse_DocumentWidget_(iDocumentWidget *d, float n format_String(&d->sourceHeader, cstr_Lang("pageinfo.header.cached")); set_Block(&d->sourceContent, &resp->body); updateDocument_DocumentWidget_(d, resp, cachedDoc, iTrue); - setCachedDocument_History(d->mod.history, d->doc); + setCachedDocument_History(d->mod.history, d->doc, + (d->flags & openedFromSidebar_DocumentWidgetFlag) != 0); } d->state = ready_RequestState; postProcessRequestContent_DocumentWidget_(d, iTrue); @@ -1626,6 +1629,9 @@ static void updateFromCachedResponse_DocumentWidget_(iDocumentWidget *d, float n static iBool updateFromHistory_DocumentWidget_(iDocumentWidget *d) { const iRecentUrl *recent = findUrl_History(d->mod.history, withSpacesEncoded_String(d->mod.url)); if (recent && recent->cachedResponse) { + iChangeFlags(d->flags, + openedFromSidebar_DocumentWidgetFlag, + recent->flags.openedFromSidebar); updateFromCachedResponse_DocumentWidget_( d, recent->normScrollY, recent->cachedResponse, recent->cachedDoc); return iTrue; @@ -2282,6 +2288,9 @@ static iBool handleSwipe_DocumentWidget_(iDocumentWidget *d, const char *cmd) { /* The temporary "swipeIn" will display the previous page until the finger is lifted. */ iDocumentWidget *swipeIn = findChild_Widget(swipeParent, "swipein"); if (!swipeIn) { + const iBool sidebarSwipe = (isPortraitPhone_App() && + d->flags & openedFromSidebar_DocumentWidgetFlag && + !isVisible_Widget(findWidget_App("sidebar"))); swipeIn = new_DocumentWidget(); setId_Widget(as_Widget(swipeIn), "swipein"); setFlags_Widget(as_Widget(swipeIn), @@ -2290,16 +2299,18 @@ static iBool handleSwipe_DocumentWidget_(iDocumentWidget *d, const char *cmd) { swipeIn->widget.rect.pos = windowToInner_Widget(swipeParent, localToWindow_Widget(w, w->rect.pos)); swipeIn->widget.rect.size = d->widget.rect.size; swipeIn->widget.offsetRef = parent_Widget(w); - iRecentUrl *recent = new_RecentUrl(); - preceding_History(d->mod.history, recent); - if (recent->cachedDoc) { - iChangeRef(swipeIn->doc, recent->cachedDoc); - updateScrollMax_DocumentWidget_(d); - setValue_Anim(&swipeIn->scrollY.pos, size_GmDocument(swipeIn->doc).y * recent->normScrollY, 0); - updateVisible_DocumentWidget_(swipeIn); - swipeIn->drawBufs->flags |= updateTimestampBuf_DrawBufsFlag | updateSideBuf_DrawBufsFlag; + if (!sidebarSwipe) { + iRecentUrl *recent = new_RecentUrl(); + preceding_History(d->mod.history, recent); + if (recent->cachedDoc) { + iChangeRef(swipeIn->doc, recent->cachedDoc); + updateScrollMax_DocumentWidget_(d); + setValue_Anim(&swipeIn->scrollY.pos, size_GmDocument(swipeIn->doc).y * recent->normScrollY, 0); + updateVisible_DocumentWidget_(swipeIn); + swipeIn->drawBufs->flags |= updateTimestampBuf_DrawBufsFlag | updateSideBuf_DrawBufsFlag; + } + delete_RecentUrl(recent); } - delete_RecentUrl(recent); addChildPos_Widget(swipeParent, iClob(swipeIn), front_WidgetAddPos); } } @@ -2326,7 +2337,9 @@ static iBool handleSwipe_DocumentWidget_(iDocumentWidget *d, const char *cmd) { destroy_Widget(as_Widget(target)); /* will be actually deleted after animation finishes */ } if (flags_Widget(w) & dragged_WidgetFlag) { - setVisualOffset_Widget(w, width_Widget(w) + offset, animSpan, 0); + setVisualOffset_Widget(w, width_Widget(w) + + width_Widget(d) * offset / size_Root(w->root).x, + animSpan, 0); } else { setVisualOffset_Widget(w, offset / 4, animSpan, 0); @@ -2426,6 +2439,7 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) return iFalse; } else if (equal_Command(cmd, "theme.changed") && document_App() == d) { +// invalidateTheme_History(d->mod.history); /* cached colors */ updateTheme_DocumentWidget_(d); updateVisible_DocumentWidget_(d); updateTrust_DocumentWidget_(d, NULL); @@ -2691,7 +2705,8 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) (startsWithCase_String(meta_GmRequest(d->request), "text/") || !cmp_String(&d->sourceMime, mimeType_Gempub))) { setCachedResponse_History(d->mod.history, lockResponse_GmRequest(d->request)); - setCachedDocument_History(d->mod.history, d->doc); /* keeps a ref */ + setCachedDocument_History(d->mod.history, d->doc, /* keeps a ref */ + (d->flags & openedFromSidebar_DocumentWidgetFlag) != 0); unlockResponse_GmRequest(d->request); } } @@ -2821,6 +2836,15 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) return iTrue; } else if (equal_Command(cmd, "navigate.back") && document_App() == d) { + if (isPortraitPhone_App()) { + if (d->flags & openedFromSidebar_DocumentWidgetFlag && + !isVisible_Widget(findWidget_App("sidebar"))) { + postCommand_App("sidebar.toggle"); + showToolbars_Root(get_Root(), iTrue); + return iTrue; + } + d->flags &= ~openedFromSidebar_DocumentWidgetFlag; + } if (d->request) { postCommandf_Root(w->root, "document.request.cancelled doc:%p url:%s", d, cstr_String(d->mod.url)); @@ -3499,7 +3523,7 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e pushBack_Array( &items, &(iMenuItem){ delete_Icon " " uiTextCaution_ColorEscape - " ${link.file.delete}", + "${link.file.delete}", 0, 0, format_CStr("!file.delete confirm:1 path:%s", @@ -4366,7 +4390,7 @@ static void drawSideElements_DocumentWidget_(const iDocumentWidget *d) { iDrawBufs * dbuf = d->drawBufs; iPaint p; init_Paint(&p); - setClip_Paint(&p, bounds); + setClip_Paint(&p, boundsWithoutVisualOffset_Widget(w)); /* Side icon and current heading. */ if (prefs_App()->sideIcon && opacity > 0 && dbuf->sideIconBuf) { const iInt2 texSize = size_SDLTexture(dbuf->sideIconBuf); @@ -4616,12 +4640,17 @@ static void prerender_DocumentWidget_(iAny *context) { } static void draw_DocumentWidget_(const iDocumentWidget *d) { - const iWidget *w = constAs_Widget(d); - const iRect bounds = bounds_Widget(w); + const iWidget *w = constAs_Widget(d); + const iRect bounds = bounds_Widget(w); + const iRect boundsWithoutVisOff = boundsWithoutVisualOffset_Widget(w); + const iRect clipBounds = intersect_Rect(bounds, boundsWithoutVisOff); if (width_Rect(bounds) <= 0) { return; } -// draw_Widget(w); + /* TODO: Come up with a better palette caching system. + It should be able to recompute cached colors in `History` when the theme has changed. + Cache the theme seed in `GmDocument`? */ +// makePaletteGlobal_GmDocument(d->doc); if (d->drawBufs->flags & updateTimestampBuf_DrawBufsFlag) { updateTimestampBuf_DocumentWidget_(d); } @@ -4638,7 +4667,7 @@ static void draw_DocumentWidget_(const iDocumentWidget *d) { }; init_Paint(&ctx.paint); render_DocumentWidget_(d, &ctx, iFalse /* just the mandatory parts */); - setClip_Paint(&ctx.paint, bounds); + setClip_Paint(&ctx.paint, clipBounds); int yTop = docBounds.pos.y - pos_SmoothScroll(&d->scrollY); draw_VisBuf(d->visBuf, init_I2(bounds.pos.x, yTop), ySpan_Rect(bounds)); /* Text markers. */ @@ -4673,7 +4702,6 @@ static void draw_DocumentWidget_(const iDocumentWidget *d) { } } drawMedia_DocumentWidget_(d, &ctx.paint); - unsetClip_Paint(&ctx.paint); /* Fill the top and bottom, in case the document is short. */ if (yTop > top_Rect(bounds)) { fillRect_Paint(&ctx.paint, @@ -4687,6 +4715,7 @@ static void draw_DocumentWidget_(const iDocumentWidget *d) { init_Rect(bounds.pos.x, yBottom, bounds.size.x, bottom_Rect(bounds) - yBottom), tmBackground_ColorId); } + unsetClip_Paint(&ctx.paint); drawSideElements_DocumentWidget_(d); if (prefs_App()->hoverLink && d->hoverLink) { const int font = uiLabel_FontId; @@ -4748,6 +4777,23 @@ static void draw_DocumentWidget_(const iDocumentWidget *d) { drawCentered_Text(uiLabelBold_FontId, rect, iFalse, uiBackground_ColorId, "%zu bytes selected", size_Range(&mark)); } + if (w->offsetRef) { + const int offX = visualOffsetByReference_Widget(w); + if (offX) { + setClip_Paint(&ctx.paint, clipBounds); + SDL_SetRenderDrawBlendMode(renderer_Window(get_Window()), SDL_BLENDMODE_BLEND); + ctx.paint.alpha = iAbs(offX) / (float) get_Window()->size.x * 300; + fillRect_Paint(&ctx.paint, bounds, backgroundFadeColor_Widget()); + SDL_SetRenderDrawBlendMode(renderer_Window(get_Window()), SDL_BLENDMODE_NONE); + unsetClip_Paint(&ctx.paint); + } + else { + /* TODO: Should have a better place to do this; drawing is supposed to be immutable. */ + iWidget *mut = iConstCast(iWidget *, w); + mut->offsetRef = NULL; + mut->flags &= ~refChildrenOffset_WidgetFlag; + } + } } /*----------------------------------------------------------------------------------------------*/ @@ -4814,10 +4860,13 @@ static void setUrl_DocumentWidget_(iDocumentWidget *d, const iString *url) { if (!equal_String(d->mod.url, url)) { d->flags |= urlChanged_DocumentWidgetFlag; set_String(d->mod.url, url); -} + } } -void setUrlFromCache_DocumentWidget(iDocumentWidget *d, const iString *url, iBool isFromCache) { +void setUrlFlags_DocumentWidget(iDocumentWidget *d, const iString *url, int setUrlFlags) { + iChangeFlags(d->flags, openedFromSidebar_DocumentWidgetFlag, + (setUrlFlags & openedFromSidebar_DocumentWidgetSetUrlFlag) != 0); + const iBool isFromCache = (setUrlFlags & useCachedContentIfAvailable_DocumentWidgetSetUrlFlag) != 0; setLinkNumberMode_DocumentWidget_(d, iFalse); setUrl_DocumentWidget_(d, urlFragmentStripped_String(url)); /* See if there a username in the URL. */ @@ -4829,6 +4878,7 @@ void setUrlFromCache_DocumentWidget(iDocumentWidget *d, const iString *url, iBoo void setUrlAndSource_DocumentWidget(iDocumentWidget *d, const iString *url, const iString *mime, const iBlock *source) { + d->flags &= ~openedFromSidebar_DocumentWidgetFlag; setLinkNumberMode_DocumentWidget_(d, iFalse); setUrl_DocumentWidget_(d, url); parseUser_DocumentWidget_(d); @@ -4846,12 +4896,12 @@ iDocumentWidget *duplicate_DocumentWidget(const iDocumentWidget *orig) { delete_History(d->mod.history); d->initNormScrollY = normScrollPos_DocumentWidget_(d); d->mod.history = copy_History(orig->mod.history); - setUrlFromCache_DocumentWidget(d, orig->mod.url, iTrue); + setUrlFlags_DocumentWidget(d, orig->mod.url, useCachedContentIfAvailable_DocumentWidgetSetUrlFlag); return d; } void setUrl_DocumentWidget(iDocumentWidget *d, const iString *url) { - setUrlFromCache_DocumentWidget(d, url, iFalse); + setUrlFlags_DocumentWidget(d, url, 0); } void setInitialScroll_DocumentWidget(iDocumentWidget *d, float normScrollY) { @@ -4862,6 +4912,11 @@ void setRedirectCount_DocumentWidget(iDocumentWidget *d, int count) { d->redirectCount = count; } +void setOpenedFromSidebar_DocumentWidget(iDocumentWidget *d, iBool fromSidebar) { + iChangeFlags(d->flags, openedFromSidebar_DocumentWidgetFlag, fromSidebar); + setCachedDocument_History(d->mod.history, d->doc, fromSidebar); +} + iBool isRequestOngoing_DocumentWidget(const iDocumentWidget *d) { return d->request != NULL; } diff --git a/src/ui/documentwidget.h b/src/ui/documentwidget.h index c038f981..1921b25a 100644 --- a/src/ui/documentwidget.h +++ b/src/ui/documentwidget.h @@ -45,11 +45,17 @@ const iString * bookmarkTitle_DocumentWidget (const iDocumentWidget *); const iString * feedTitle_DocumentWidget (const iDocumentWidget *); int documentWidth_DocumentWidget (const iDocumentWidget *); +enum iDocumentWidgetSetUrlFlags { + useCachedContentIfAvailable_DocumentWidgetSetUrlFlag = iBit(1), + openedFromSidebar_DocumentWidgetSetUrlFlag = iBit(2), +}; + void setUrl_DocumentWidget (iDocumentWidget *, const iString *url); -void setUrlFromCache_DocumentWidget (iDocumentWidget *, const iString *url, iBool isFromCache); +void setUrlFlags_DocumentWidget (iDocumentWidget *, const iString *url, int setUrlFlags); void setUrlAndSource_DocumentWidget (iDocumentWidget *, const iString *url, const iString *mime, const iBlock *source); void setInitialScroll_DocumentWidget (iDocumentWidget *, float normScrollY); /* set after content received */ void setRedirectCount_DocumentWidget (iDocumentWidget *, int count); void setSource_DocumentWidget (iDocumentWidget *, const iString *sourceText); +void setOpenedFromSidebar_DocumentWidget(iDocumentWidget *, iBool fromSidebar); void updateSize_DocumentWidget (iDocumentWidget *); diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c index 4f3ea637..f7181037 100644 --- a/src/ui/sidebarwidget.c +++ b/src/ui/sidebarwidget.c @@ -773,6 +773,7 @@ static void itemClicked_SidebarWidget_(iSidebarWidget *d, iSidebarItem *item, si const iGmHeading *head = constAt_Array(headings_GmDocument(doc), item->id); postCommandf_App("document.goto loc:%p", head->text.start); dismissPortraitPhoneSidebars_Root(as_Widget(d)->root); + setOpenedFromSidebar_DocumentWidget(document_App(), iTrue); break; } case feeds_SidebarMode: { @@ -783,7 +784,7 @@ static void itemClicked_SidebarWidget_(iSidebarWidget *d, iSidebarItem *item, si case bookmarks_SidebarMode: case history_SidebarMode: { if (!isEmpty_String(&item->url)) { - postCommandf_Root(get_Root(), "open newtab:%d url:%s", + postCommandf_Root(get_Root(), "open fromsidebar:1 newtab:%d url:%s", openTabMode_Sym(modState_Keys()), cstr_String(&item->url)); } @@ -944,13 +945,16 @@ static iBool handleSidebarCommand_SidebarWidget_(iSidebarWidget *d, const char * visX = left_Rect(bounds_Widget(w)) - left_Rect(w->root->widget->rect); } setFlags_Widget(w, hidden_WidgetFlag, isVisible_Widget(w)); + /* Safe area inset for mobile. */ + const int safePad = (d->side == left_SidebarSide ? left_Rect(safeRect_Root(w->root)) : 0); if (isVisible_Widget(w)) { setFlags_Widget(w, keepOnTop_WidgetFlag, iFalse); w->rect.size.x = d->widthAsGaps * gap_UI; invalidate_ListWidget(d->list); if (isAnimated) { setFlags_Widget(w, horizontalOffset_WidgetFlag, iTrue); - setVisualOffset_Widget(w, (d->side == left_SidebarSide ? -1 : 1) * w->rect.size.x, 0, 0); + setVisualOffset_Widget( + w, (d->side == left_SidebarSide ? -1 : 1) * (w->rect.size.x + safePad), 0, 0); setVisualOffset_Widget(w, 0, 300, easeOut_AnimFlag | softer_AnimFlag); } } @@ -958,11 +962,13 @@ static iBool handleSidebarCommand_SidebarWidget_(iSidebarWidget *d, const char * setFlags_Widget(w, horizontalOffset_WidgetFlag, iTrue); if (d->side == right_SidebarSide) { setVisualOffset_Widget(w, visX, 0, 0); - setVisualOffset_Widget(w, visX + w->rect.size.x, 300, easeOut_AnimFlag | softer_AnimFlag); + setVisualOffset_Widget( + w, visX + w->rect.size.x + safePad, 300, easeOut_AnimFlag | softer_AnimFlag); } else { setFlags_Widget(w, keepOnTop_WidgetFlag, iTrue); - setVisualOffset_Widget(w, -w->rect.size.x, 300, easeOut_AnimFlag | softer_AnimFlag); + setVisualOffset_Widget( + w, -w->rect.size.x - safePad, 300, easeOut_AnimFlag | softer_AnimFlag); } } arrange_Widget(w->parent); diff --git a/src/ui/text.c b/src/ui/text.c index ffe08fca..8a2a9ff8 100644 --- a/src/ui/text.c +++ b/src/ui/text.c @@ -389,7 +389,9 @@ static void initCache_Text_(iText *d) { d->cacheRowAllocStep = iMax(2, textSize / 6); /* Allocate initial (empty) rows. These will be assigned actual locations in the cache once at least one glyph is stored. */ - for (int h = d->cacheRowAllocStep; h <= 2 * textSize + d->cacheRowAllocStep; h += d->cacheRowAllocStep) { + for (int h = d->cacheRowAllocStep; + h <= 2.5 * textSize + d->cacheRowAllocStep; + h += d->cacheRowAllocStep) { pushBack_Array(&d->cacheRows, &(iCacheRow){ .height = 0 }); } d->cacheBottom = 0; diff --git a/src/ui/touch.c b/src/ui/touch.c index 36bac267..dac1152e 100644 --- a/src/ui/touch.c +++ b/src/ui/touch.c @@ -65,6 +65,7 @@ struct Impl_Touch { iBool isLeftDown; iBool isTouchDrag; iBool isTapAndHold; + iBool didPostEdgeMove; iBool didBeginOnTouchDrag; int pinchId; enum iTouchEdge edge; @@ -391,6 +392,12 @@ static void checkNewPinch_TouchState_(iTouchState *d, iTouch *newTouch) { pinch.touchIds[1] = other->id; newTouch->pinchId = other->pinchId = pinch.id; clearWidgetMomentum_TouchState_(d, affinity); + if (other->edge && other->didPostEdgeMove) { + postCommandf_App("edgeswipe.ended abort:1 side:%d id:%llu", other->edge, other->id); + other->didPostEdgeMove = iFalse; + } + other->edge = none_TouchEdge; + newTouch->edge = none_TouchEdge; /* Remember current positions to determine pinch amount. */ newTouch->startPos = newTouch->pos[0]; other->startPos = other->pos[0]; @@ -476,7 +483,6 @@ iBool processEvent_Touch(const SDL_Event *ev) { } else if (x > rootSize.x - edgeWidth) { edge = right_TouchEdge; -// puts("DOWN on right edge"); } iWidget *aff = hitChild_Window(window, init_I2(iRound(x), iRound(y_F3(pos)))); #if 0 @@ -523,6 +529,7 @@ iBool processEvent_Touch(const SDL_Event *ev) { (int) (x_F3(pos) - x_F3(touch->startPos)), touch->edge, touch->id); + touch->didPostEdgeMove = iTrue; return iTrue; } if (touch && touch->affinity) { @@ -595,39 +602,6 @@ iBool processEvent_Touch(const SDL_Event *ev) { } } iAssert(touch->edge == none_TouchEdge); -#if 0 - /* Edge swipe aborted? */ - if (touch->edge == left_TouchEdge) { - 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); - setVisualOffset_Widget(touch->edgeDragging, 0, 200, easeOut_AnimFlag); - touch->edgeDragging = NULL; - } - } - else if (touch->edgeDragging) { - setVisualOffset_Widget(touch->edgeDragging, x_F3(pos) - x_F3(touch->startPos), 10, 0); - } - } - if (touch->edge == right_TouchEdge) { - if (fing->dx > 0 && x_F3(touch->pos[0]) > window->size.x - tapRadiusPt_ * window->pixelRatio) { - puts("touch->edge==right returned to right edge, aborted"); - touch->edge = none_TouchEdge; - if (touch->edgeDragging) { - setFlags_Widget(touch->edgeDragging, dragged_WidgetFlag, iFalse); - setVisualOffset_Widget(touch->edgeDragging, 0, 200, easeOut_AnimFlag); - touch->edgeDragging = NULL; - } - } - else if (touch->edgeDragging) { - setVisualOffset_Widget(touch->edgeDragging, x_F3(pos) - x_F3(touch->startPos), 10, 0); - } - } - if (touch->edge) { - pixels.y = 0; - } -#endif if (touch->axis == x_TouchAxis) { pixels.y = 0; } @@ -671,7 +645,12 @@ iBool processEvent_Touch(const SDL_Event *ev) { } #endif if (touch->edge && !isStationary_Touch_(touch)) { - postCommandf_App("edgeswipe.ended side:%d id:%llu", touch->edge, touch->id); + const iFloat3 gesture = gestureVector_Touch_(touch); + const float pixel = window->pixelRatio; + const int moveDir = x_F3(gesture) < -pixel ? -1 : x_F3(gesture) > pixel ? +1 : 0; + const int didAbort = (touch->edge == left_TouchEdge && moveDir < 0) || + (touch->edge == right_TouchEdge && moveDir > 0); + postCommandf_App("edgeswipe.ended abort:%d side:%d id:%llu", didAbort, touch->edge, touch->id); remove_ArrayIterator(&i); continue; } diff --git a/src/ui/widget.c b/src/ui/widget.c index 11ec1b07..85672c04 100644 --- a/src/ui/widget.c +++ b/src/ui/widget.c @@ -760,16 +760,24 @@ void arrange_Widget(iWidget *d) { } iBool isBeingVisuallyOffsetByReference_Widget(const iWidget *d) { - if (d->flags & refChildrenOffset_WidgetFlag) { + return visualOffsetByReference_Widget(d) != 0; +} + +int visualOffsetByReference_Widget(const iWidget *d) { + if (d->offsetRef && d->flags & refChildrenOffset_WidgetFlag) { + int offX = 0; iConstForEach(ObjectList, i, children_Widget(d->offsetRef)) { const iWidget *child = i.object; if (child == d) continue; if (child->flags & (visualOffset_WidgetFlag | dragged_WidgetFlag)) { - return iTrue; +// const float factor = width_Widget(d) / (float) size_Root(d->root).x; + const int invOff = width_Widget(d) - iRound(value_Anim(&child->visualOffset)); + offX -= invOff / 4; } } + return offX; } - return iFalse; + return 0; } static void applyVisualOffset_Widget_(const iWidget *d, iInt2 *pos) { @@ -786,14 +794,7 @@ static void applyVisualOffset_Widget_(const iWidget *d, iInt2 *pos) { pos->y -= value_Anim(d->animOffsetRef); } 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 / 4; - } - } + pos->x += visualOffsetByReference_Widget(d); } } @@ -1081,7 +1082,9 @@ iBool processEvent_Widget(iWidget *d, const SDL_Event *ev) { if (~d->flags & dragged_WidgetFlag) { setFlags_Widget(d, dragged_WidgetFlag, iTrue); } - setVisualOffset_Widget(d, arg_Command(command_UserEvent(ev)), 10, 0); + setVisualOffset_Widget(d, arg_Command(command_UserEvent(ev)) * + width_Widget(d) / size_Root(d->root).x, + 10, 0); return iTrue; } } @@ -1129,6 +1132,17 @@ iBool processEvent_Widget(iWidget *d, const SDL_Event *ev) { return iFalse; } +int backgroundFadeColor_Widget(void) { + switch (colorTheme_App()) { + case light_ColorTheme: + return gray25_ColorId; + case pureWhite_ColorTheme: + return gray50_ColorId; + default: + return black_ColorId; + } +} + void drawBackground_Widget(const iWidget *d) { if (d->flags & noBackground_WidgetFlag) { return; @@ -1151,8 +1165,7 @@ void drawBackground_Widget(const iWidget *d) { drawSoftShadow_Paint(&p, bounds_Widget(d), 12 * gap_UI, black_ColorId, 30); } const iBool isFaded = fadeBackground && - ~d->flags & noFadeBackground_WidgetFlag;/* && - ~d->flags & destroyPending_WidgetFlag;*/ + ~d->flags & noFadeBackground_WidgetFlag; if (isFaded) { iPaint p; init_Paint(&p); @@ -1163,19 +1176,7 @@ void drawBackground_Widget(const iWidget *d) { p.alpha *= (area > 0 ? visibleArea / area : 0.0f); } SDL_SetRenderDrawBlendMode(renderer_Window(get_Window()), SDL_BLENDMODE_BLEND); - int fadeColor; - switch (colorTheme_App()) { - default: - fadeColor = black_ColorId; - break; - case light_ColorTheme: - fadeColor = gray25_ColorId; - break; - case pureWhite_ColorTheme: - fadeColor = gray50_ColorId; - break; - } - fillRect_Paint(&p, rect_Root(d->root), fadeColor); + fillRect_Paint(&p, rect_Root(d->root), backgroundFadeColor_Widget()); SDL_SetRenderDrawBlendMode(renderer_Window(get_Window()), SDL_BLENDMODE_NONE); } if (d->bgColor >= 0 || d->frameColor >= 0) { diff --git a/src/ui/widget.h b/src/ui/widget.h index b2310f21..acb8fa9d 100644 --- a/src/ui/widget.h +++ b/src/ui/widget.h @@ -242,10 +242,9 @@ iBool isSelected_Widget (const iAnyObject *); iBool isUnderKeyRoot_Widget (const iAnyObject *); iBool isCommand_Widget (const iWidget *d, const SDL_Event *ev, const char *cmd); iBool hasParent_Widget (const iWidget *d, const iWidget *someParent); -iBool isAffectedByVisualOffset_Widget - (const iWidget *); -iBool isBeingVisuallyOffsetByReference_Widget - (const iWidget *); +iBool isAffectedByVisualOffset_Widget (const iWidget *); +iBool isBeingVisuallyOffsetByReference_Widget (const iWidget *); +int visualOffsetByReference_Widget (const iWidget *); void setId_Widget (iWidget *, const char *id); void setFlags_Widget (iWidget *, int64_t flags, iBool set); void setPos_Widget (iWidget *, iInt2 pos); @@ -278,6 +277,8 @@ void refresh_Widget (const iAnyObject *); iBool equalWidget_Command (const char *cmd, const iWidget *widget, const char *checkCommand); +int backgroundFadeColor_Widget (void); + void setFocus_Widget (iWidget *); iWidget * focus_Widget (void); void setHover_Widget (iWidget *); -- cgit v1.2.3