From d24775473c5e95043481457b061660caac8a1524 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Sun, 13 Jun 2021 06:52:36 +0300 Subject: Touch: Swiping away the sidebar --- src/ui/mobile.c | 4 ++-- src/ui/root.c | 4 ++-- src/ui/sidebarwidget.c | 34 ++++++++++++++++++++-------------- src/ui/sidebarwidget.h | 4 ++-- src/ui/touch.c | 5 ++++- src/ui/util.c | 2 +- src/ui/widget.c | 18 +++++++++++------- src/ui/widget.h | 4 ++-- 8 files changed, 44 insertions(+), 31 deletions(-) diff --git a/src/ui/mobile.c b/src/ui/mobile.c index 7794d686..1bf289a7 100644 --- a/src/ui/mobile.c +++ b/src/ui/mobile.c @@ -120,7 +120,7 @@ static iBool mainDetailSplitHandler_(iWidget *mainDetailSplit, const char *cmd) } iForEach(ObjectList, i, children_Widget(detailStack)) { iWidget *panel = i.object; - setFlags_Widget(panel, edgeDraggable_WidgetFlag, !isSideBySide); + setFlags_Widget(panel, leftEdgeDraggable_WidgetFlag, !isSideBySide); if (isSideBySide) { setVisualOffset_Widget(panel, 0, 0, 0); } @@ -414,7 +414,7 @@ void finalizeSheet_Mobile(iWidget *sheet) { setFlags_Widget(sheet, frameless_WidgetFlag | //resizeWidthOfChildren_WidgetFlag | - edgeDraggable_WidgetFlag | + leftEdgeDraggable_WidgetFlag | commandOnClick_WidgetFlag, iTrue); iPtrArray * contents = collect_PtrArray(new_PtrArray()); /* two-column pages */ diff --git a/src/ui/root.c b/src/ui/root.c index 76f4c0d7..2d69970d 100644 --- a/src/ui/root.c +++ b/src/ui/root.c @@ -1185,9 +1185,9 @@ void createUserInterface_Root(iRoot *d) { } /* Sidebars. */ { iWidget *content = findChild_Widget(root, "tabs.content"); - iSidebarWidget *sidebar1 = new_SidebarWidget(left_SideBarSide); + iSidebarWidget *sidebar1 = new_SidebarWidget(left_SidebarSide); addChildPos_Widget(content, iClob(sidebar1), front_WidgetAddPos); - iSidebarWidget *sidebar2 = new_SidebarWidget(right_SideBarSide); + iSidebarWidget *sidebar2 = new_SidebarWidget(right_SidebarSide); if (deviceType_App() != phone_AppDeviceType) { addChildPos_Widget(content, iClob(sidebar2), back_WidgetAddPos); } diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c index 2e1e138e..4f3ea637 100644 --- a/src/ui/sidebarwidget.c +++ b/src/ui/sidebarwidget.c @@ -625,7 +625,7 @@ static void updateMetrics_SidebarWidget_(iSidebarWidget *d) { void init_SidebarWidget(iSidebarWidget *d, enum iSidebarSide side) { iWidget *w = as_Widget(d); init_Widget(w); - setId_Widget(w, side == left_SideBarSide ? "sidebar" : "sidebar2"); + setId_Widget(w, side == left_SidebarSide ? "sidebar" : "sidebar2"); initCopy_String(&d->cmdPrefix, id_Widget(w)); appendChar_String(&d->cmdPrefix, '.'); setBackgroundColor_Widget(w, none_ColorId); @@ -659,7 +659,7 @@ void init_SidebarWidget(iSidebarWidget *d, enum iSidebarSide side) { d->actions = NULL; /* On a phone, the right sidebar is used exclusively for Identities. */ const iBool isPhone = deviceType_App() == phone_AppDeviceType; - if (!isPhone || d->side == left_SideBarSide) { + if (!isPhone || d->side == left_SidebarSide) { iWidget *buttons = new_Widget(); setId_Widget(buttons, "buttons"); for (int i = 0; i < max_SidebarMode; i++) { @@ -715,24 +715,24 @@ void init_SidebarWidget(iSidebarWidget *d, enum iSidebarSide side) { addChildFlags_Widget(content, iClob(d->blank), resizeChildren_WidgetFlag); addChildFlags_Widget(vdiv, iClob(content), expand_WidgetFlag); setMode_SidebarWidget(d, - deviceType_App() == phone_AppDeviceType && d->side == right_SideBarSide ? + deviceType_App() == phone_AppDeviceType && d->side == right_SidebarSide ? identities_SidebarMode : bookmarks_SidebarMode); d->resizer = addChildFlags_Widget(w, iClob(new_Widget()), hover_WidgetFlag | commandOnClick_WidgetFlag | fixedWidth_WidgetFlag | resizeToParentHeight_WidgetFlag | - (side == left_SideBarSide ? moveToParentRightEdge_WidgetFlag + (side == left_SidebarSide ? moveToParentRightEdge_WidgetFlag : moveToParentLeftEdge_WidgetFlag)); if (deviceType_App() == phone_AppDeviceType) { setFlags_Widget(d->resizer, hidden_WidgetFlag | disabled_WidgetFlag, iTrue); } - setId_Widget(d->resizer, side == left_SideBarSide ? "sidebar.grab" : "sidebar2.grab"); + setId_Widget(d->resizer, side == left_SidebarSide ? "sidebar.grab" : "sidebar2.grab"); setBackgroundColor_Widget(d->resizer, none_ColorId); d->menu = NULL; addAction_Widget(w, SDLK_r, KMOD_PRIMARY | KMOD_SHIFT, "feeds.refresh"); updateMetrics_SidebarWidget_(d); - if (side == left_SideBarSide) { + if (side == left_SidebarSide) { postCommand_App("~sidebar.update"); /* unread count */ } } @@ -799,7 +799,7 @@ static void itemClicked_SidebarWidget_(iSidebarWidget *d, iSidebarItem *item, si updateContextMenu_SidebarWidget_(d); arrange_Widget(d->menu); openMenu_Widget(d->menu, - d->side == left_SideBarSide + d->side == left_SidebarSide ? topRight_Rect(itemRect_ListWidget(d->list, itemIndex)) : addX_I2(topLeft_Rect(itemRect_ListWidget(d->list, itemIndex)), -width_Widget(d->menu))); @@ -857,7 +857,7 @@ void setWidth_SidebarWidget(iSidebarWidget *d, float widthAsGaps) { if (!isFixedWidth) { /* Even less space if the other sidebar is visible, too. */ const int otherWidth = - width_Widget(findWidget_App(d->side == left_SideBarSide ? "sidebar2" : "sidebar")); + width_Widget(findWidget_App(d->side == left_SidebarSide ? "sidebar2" : "sidebar")); width = iClamp(width, 30 * gap_UI, size_Root(w->root).x - 50 * gap_UI - otherWidth); } d->widthAsGaps = (float) width / (float) gap_UI; @@ -938,7 +938,7 @@ static iBool handleSidebarCommand_SidebarWidget_(iSidebarWidget *d, const char * } const iBool isAnimated = prefs_App()->uiAnimations && argLabel_Command(cmd, "noanim") == 0 && - (d->side == left_SideBarSide || deviceType_App() != phone_AppDeviceType); + (d->side == left_SidebarSide || deviceType_App() != phone_AppDeviceType); int visX = 0; if (isVisible_Widget(w)) { visX = left_Rect(bounds_Widget(w)) - left_Rect(w->root->widget->rect); @@ -950,13 +950,13 @@ static iBool handleSidebarCommand_SidebarWidget_(iSidebarWidget *d, const char * 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, 0, 0); setVisualOffset_Widget(w, 0, 300, easeOut_AnimFlag | softer_AnimFlag); } } else if (isAnimated) { setFlags_Widget(w, horizontalOffset_WidgetFlag, iTrue); - if (d->side == right_SideBarSide) { + if (d->side == right_SidebarSide) { setVisualOffset_Widget(w, visX, 0, 0); setVisualOffset_Widget(w, visX + w->rect.size.x, 300, easeOut_AnimFlag | softer_AnimFlag); } @@ -984,7 +984,8 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) /* Handle commands. */ if (isResize_UserEvent(ev)) { checkModeButtonLayout_SidebarWidget_(d); - if (deviceType_App() == phone_AppDeviceType && d->side == left_SideBarSide) { + if (deviceType_App() == phone_AppDeviceType && d->side == left_SidebarSide) { + setFlags_Widget(w, rightEdgeDraggable_WidgetFlag, isPortrait_App()); /* In landscape, visibility of the toolbar is controlled separately. */ if (isVisible_Widget(w)) { postCommand_Widget(w, "sidebar.toggle"); @@ -1038,6 +1039,11 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) postCommandf_App("sidebar.mode arg:%d toggle:1", identities_SidebarMode); return iTrue; } + else if (isPortraitPhone_App() && isVisible_Widget(w) && d->side == left_SidebarSide && + equal_Command(cmd, "swipe.forward")) { + postCommand_App("sidebar.toggle"); + return iTrue; + } else if (startsWith_CStr(cmd, cstr_String(&d->cmdPrefix))) { if (handleSidebarCommand_SidebarWidget_(d, cmd + size_String(&d->cmdPrefix))) { return iTrue; @@ -1068,7 +1074,7 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) const int resMid = d->resizer->rect.size.x / 2; setWidth_SidebarWidget( d, - ((d->side == left_SideBarSide + ((d->side == left_SidebarSide ? inner.x : (right_Rect(rect_Root(w->root)) - coord_Command(cmd).x)) + resMid) / (float) gap_UI); @@ -1547,7 +1553,7 @@ static void draw_SidebarWidget_(const iSidebarWidget *d) { if (isVisible_Widget(w)) { drawVLine_Paint( &p, - addX_I2(d->side == left_SideBarSide ? topRight_Rect(bounds) : topLeft_Rect(bounds), -1), + addX_I2(d->side == left_SidebarSide ? topRight_Rect(bounds) : topLeft_Rect(bounds), -1), height_Rect(bounds), uiSeparator_ColorId); } diff --git a/src/ui/sidebarwidget.h b/src/ui/sidebarwidget.h index 2e418aa4..130242ab 100644 --- a/src/ui/sidebarwidget.h +++ b/src/ui/sidebarwidget.h @@ -36,8 +36,8 @@ enum iSidebarMode { const char * icon_SidebarMode (enum iSidebarMode mode); enum iSidebarSide { - left_SideBarSide, - right_SideBarSide, + left_SidebarSide, + right_SidebarSide, }; enum iFeedsMode { diff --git a/src/ui/touch.c b/src/ui/touch.c index c7c5a410..236601e8 100644 --- a/src/ui/touch.c +++ b/src/ui/touch.c @@ -274,8 +274,9 @@ static void update_TouchState_(void *ptr) { // setHover_Widget(NULL); postCommandf_App("edgeswipe.ended abort:1 side:%d id:%llu", touch->edge, touch->id); touch->edge = none_TouchEdge; + remove_ArrayIterator(&i); } - else continue; + continue; } /* Holding a touch will reset previous momentum for this widget. */ if (isStationary_Touch_(touch)) { @@ -362,6 +363,7 @@ static void update_TouchState_(void *ptr) { } } +#if 0 static iWidget *findSlidePanel_Widget_(iWidget *d) { for (iWidget *w = d; w; w = parent_Widget(w)) { if (isVisible_Widget(w) && flags_Widget(w) & edgeDraggable_WidgetFlag) { @@ -370,6 +372,7 @@ static iWidget *findSlidePanel_Widget_(iWidget *d) { } return NULL; } +#endif static void checkNewPinch_TouchState_(iTouchState *d, iTouch *newTouch) { iWidget *affinity = newTouch->affinity; diff --git a/src/ui/util.c b/src/ui/util.c index 9cc848de..f2449096 100644 --- a/src/ui/util.c +++ b/src/ui/util.c @@ -1317,7 +1317,7 @@ void updateValueInput_Widget(iWidget *d, const char *title, const char *prompt) static iBool messageHandler_(iWidget *msg, const char *cmd) { /* Almost any command dismisses the sheet. */ - /* TODO: Use a "notification" prefix (like `) to ignore all types of commands line this? */ + /* TODO: Add a "notification" type of user events to separate them from user actions. */ if (!(equal_Command(cmd, "media.updated") || equal_Command(cmd, "media.player.update") || equal_Command(cmd, "bookmarks.request.finished") || diff --git a/src/ui/widget.c b/src/ui/widget.c index bedcb146..f1d1dae4 100644 --- a/src/ui/widget.c +++ b/src/ui/widget.c @@ -1058,15 +1058,19 @@ iBool processEvent_Widget(iWidget *d, const SDL_Event *ev) { } if (ev->user.code == command_UserEventCode) { const char *cmd = command_UserEvent(ev); - if (d->flags & edgeDraggable_WidgetFlag && - isVisible_Widget(d) && - ~d->flags & disabled_WidgetFlag && + if (d->flags & (leftEdgeDraggable_WidgetFlag | rightEdgeDraggable_WidgetFlag) && + isVisible_Widget(d) && ~d->flags & disabled_WidgetFlag && equal_Command(cmd, "edgeswipe.moved")) { - if (~d->flags & dragged_WidgetFlag) { - setFlags_Widget(d, dragged_WidgetFlag, iTrue); + /* Check the side. */ + const int side = argLabel_Command(cmd, "side"); + if ((side == 1 && d->flags & leftEdgeDraggable_WidgetFlag) || + (side == 2 && d->flags & rightEdgeDraggable_WidgetFlag)) { + if (~d->flags & dragged_WidgetFlag) { + setFlags_Widget(d, dragged_WidgetFlag, iTrue); + } + setVisualOffset_Widget(d, arg_Command(command_UserEvent(ev)), 10, 0); + return iTrue; } - setVisualOffset_Widget(d, arg_Command(command_UserEvent(ev)), 10, 0); - return iTrue; } if (d->flags & dragged_WidgetFlag && equal_Command(cmd, "edgeswipe.ended")) { if (argLabel_Command(cmd, "abort")) { diff --git a/src/ui/widget.h b/src/ui/widget.h index 8de62b7a..7255b975 100644 --- a/src/ui/widget.h +++ b/src/ui/widget.h @@ -87,7 +87,7 @@ enum iWidgetFlag { }; /* 64-bit extended flags */ -//#define wasCollapsed_WidgetFlag iBit64(32) +#define rightEdgeDraggable_WidgetFlag iBit64(32) #define disabledWhenHidden_WidgetFlag iBit64(32) #define centerHorizontal_WidgetFlag iBit64(33) #define moveToParentLeftEdge_WidgetFlag iBit64(34) @@ -118,7 +118,7 @@ enum iWidgetFlag { #define ignoreForParentWidth_WidgetFlag iBit64(59) #define noFadeBackground_WidgetFlag iBit64(60) #define destroyPending_WidgetFlag iBit64(61) /* TODO: needed? */ -#define edgeDraggable_WidgetFlag iBit64(62) +#define leftEdgeDraggable_WidgetFlag iBit64(62) #define refChildrenOffset_WidgetFlag iBit64(63) /* visual offset determined by the offset of referenced children */ enum iWidgetAddPos { -- cgit v1.2.3