diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-06-13 06:52:36 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-06-13 06:52:36 +0300 |
commit | d24775473c5e95043481457b061660caac8a1524 (patch) | |
tree | a01511b5b5462ed320fe953c9732ce88a8d27e71 /src/ui/sidebarwidget.c | |
parent | 7a27cf99aecfb3112af1d61b908d62d1808f43e5 (diff) |
Touch: Swiping away the sidebar
Diffstat (limited to 'src/ui/sidebarwidget.c')
-rw-r--r-- | src/ui/sidebarwidget.c | 34 |
1 files changed, 20 insertions, 14 deletions
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) { | |||
625 | void init_SidebarWidget(iSidebarWidget *d, enum iSidebarSide side) { | 625 | void init_SidebarWidget(iSidebarWidget *d, enum iSidebarSide side) { |
626 | iWidget *w = as_Widget(d); | 626 | iWidget *w = as_Widget(d); |
627 | init_Widget(w); | 627 | init_Widget(w); |
628 | setId_Widget(w, side == left_SideBarSide ? "sidebar" : "sidebar2"); | 628 | setId_Widget(w, side == left_SidebarSide ? "sidebar" : "sidebar2"); |
629 | initCopy_String(&d->cmdPrefix, id_Widget(w)); | 629 | initCopy_String(&d->cmdPrefix, id_Widget(w)); |
630 | appendChar_String(&d->cmdPrefix, '.'); | 630 | appendChar_String(&d->cmdPrefix, '.'); |
631 | setBackgroundColor_Widget(w, none_ColorId); | 631 | setBackgroundColor_Widget(w, none_ColorId); |
@@ -659,7 +659,7 @@ void init_SidebarWidget(iSidebarWidget *d, enum iSidebarSide side) { | |||
659 | d->actions = NULL; | 659 | d->actions = NULL; |
660 | /* On a phone, the right sidebar is used exclusively for Identities. */ | 660 | /* On a phone, the right sidebar is used exclusively for Identities. */ |
661 | const iBool isPhone = deviceType_App() == phone_AppDeviceType; | 661 | const iBool isPhone = deviceType_App() == phone_AppDeviceType; |
662 | if (!isPhone || d->side == left_SideBarSide) { | 662 | if (!isPhone || d->side == left_SidebarSide) { |
663 | iWidget *buttons = new_Widget(); | 663 | iWidget *buttons = new_Widget(); |
664 | setId_Widget(buttons, "buttons"); | 664 | setId_Widget(buttons, "buttons"); |
665 | for (int i = 0; i < max_SidebarMode; i++) { | 665 | for (int i = 0; i < max_SidebarMode; i++) { |
@@ -715,24 +715,24 @@ void init_SidebarWidget(iSidebarWidget *d, enum iSidebarSide side) { | |||
715 | addChildFlags_Widget(content, iClob(d->blank), resizeChildren_WidgetFlag); | 715 | addChildFlags_Widget(content, iClob(d->blank), resizeChildren_WidgetFlag); |
716 | addChildFlags_Widget(vdiv, iClob(content), expand_WidgetFlag); | 716 | addChildFlags_Widget(vdiv, iClob(content), expand_WidgetFlag); |
717 | setMode_SidebarWidget(d, | 717 | setMode_SidebarWidget(d, |
718 | deviceType_App() == phone_AppDeviceType && d->side == right_SideBarSide ? | 718 | deviceType_App() == phone_AppDeviceType && d->side == right_SidebarSide ? |
719 | identities_SidebarMode : bookmarks_SidebarMode); | 719 | identities_SidebarMode : bookmarks_SidebarMode); |
720 | d->resizer = | 720 | d->resizer = |
721 | addChildFlags_Widget(w, | 721 | addChildFlags_Widget(w, |
722 | iClob(new_Widget()), | 722 | iClob(new_Widget()), |
723 | hover_WidgetFlag | commandOnClick_WidgetFlag | fixedWidth_WidgetFlag | | 723 | hover_WidgetFlag | commandOnClick_WidgetFlag | fixedWidth_WidgetFlag | |
724 | resizeToParentHeight_WidgetFlag | | 724 | resizeToParentHeight_WidgetFlag | |
725 | (side == left_SideBarSide ? moveToParentRightEdge_WidgetFlag | 725 | (side == left_SidebarSide ? moveToParentRightEdge_WidgetFlag |
726 | : moveToParentLeftEdge_WidgetFlag)); | 726 | : moveToParentLeftEdge_WidgetFlag)); |
727 | if (deviceType_App() == phone_AppDeviceType) { | 727 | if (deviceType_App() == phone_AppDeviceType) { |
728 | setFlags_Widget(d->resizer, hidden_WidgetFlag | disabled_WidgetFlag, iTrue); | 728 | setFlags_Widget(d->resizer, hidden_WidgetFlag | disabled_WidgetFlag, iTrue); |
729 | } | 729 | } |
730 | setId_Widget(d->resizer, side == left_SideBarSide ? "sidebar.grab" : "sidebar2.grab"); | 730 | setId_Widget(d->resizer, side == left_SidebarSide ? "sidebar.grab" : "sidebar2.grab"); |
731 | setBackgroundColor_Widget(d->resizer, none_ColorId); | 731 | setBackgroundColor_Widget(d->resizer, none_ColorId); |
732 | d->menu = NULL; | 732 | d->menu = NULL; |
733 | addAction_Widget(w, SDLK_r, KMOD_PRIMARY | KMOD_SHIFT, "feeds.refresh"); | 733 | addAction_Widget(w, SDLK_r, KMOD_PRIMARY | KMOD_SHIFT, "feeds.refresh"); |
734 | updateMetrics_SidebarWidget_(d); | 734 | updateMetrics_SidebarWidget_(d); |
735 | if (side == left_SideBarSide) { | 735 | if (side == left_SidebarSide) { |
736 | postCommand_App("~sidebar.update"); /* unread count */ | 736 | postCommand_App("~sidebar.update"); /* unread count */ |
737 | } | 737 | } |
738 | } | 738 | } |
@@ -799,7 +799,7 @@ static void itemClicked_SidebarWidget_(iSidebarWidget *d, iSidebarItem *item, si | |||
799 | updateContextMenu_SidebarWidget_(d); | 799 | updateContextMenu_SidebarWidget_(d); |
800 | arrange_Widget(d->menu); | 800 | arrange_Widget(d->menu); |
801 | openMenu_Widget(d->menu, | 801 | openMenu_Widget(d->menu, |
802 | d->side == left_SideBarSide | 802 | d->side == left_SidebarSide |
803 | ? topRight_Rect(itemRect_ListWidget(d->list, itemIndex)) | 803 | ? topRight_Rect(itemRect_ListWidget(d->list, itemIndex)) |
804 | : addX_I2(topLeft_Rect(itemRect_ListWidget(d->list, itemIndex)), | 804 | : addX_I2(topLeft_Rect(itemRect_ListWidget(d->list, itemIndex)), |
805 | -width_Widget(d->menu))); | 805 | -width_Widget(d->menu))); |
@@ -857,7 +857,7 @@ void setWidth_SidebarWidget(iSidebarWidget *d, float widthAsGaps) { | |||
857 | if (!isFixedWidth) { | 857 | if (!isFixedWidth) { |
858 | /* Even less space if the other sidebar is visible, too. */ | 858 | /* Even less space if the other sidebar is visible, too. */ |
859 | const int otherWidth = | 859 | const int otherWidth = |
860 | width_Widget(findWidget_App(d->side == left_SideBarSide ? "sidebar2" : "sidebar")); | 860 | width_Widget(findWidget_App(d->side == left_SidebarSide ? "sidebar2" : "sidebar")); |
861 | width = iClamp(width, 30 * gap_UI, size_Root(w->root).x - 50 * gap_UI - otherWidth); | 861 | width = iClamp(width, 30 * gap_UI, size_Root(w->root).x - 50 * gap_UI - otherWidth); |
862 | } | 862 | } |
863 | d->widthAsGaps = (float) width / (float) gap_UI; | 863 | d->widthAsGaps = (float) width / (float) gap_UI; |
@@ -938,7 +938,7 @@ static iBool handleSidebarCommand_SidebarWidget_(iSidebarWidget *d, const char * | |||
938 | } | 938 | } |
939 | const iBool isAnimated = prefs_App()->uiAnimations && | 939 | const iBool isAnimated = prefs_App()->uiAnimations && |
940 | argLabel_Command(cmd, "noanim") == 0 && | 940 | argLabel_Command(cmd, "noanim") == 0 && |
941 | (d->side == left_SideBarSide || deviceType_App() != phone_AppDeviceType); | 941 | (d->side == left_SidebarSide || deviceType_App() != phone_AppDeviceType); |
942 | int visX = 0; | 942 | int visX = 0; |
943 | if (isVisible_Widget(w)) { | 943 | if (isVisible_Widget(w)) { |
944 | visX = left_Rect(bounds_Widget(w)) - left_Rect(w->root->widget->rect); | 944 | visX = left_Rect(bounds_Widget(w)) - left_Rect(w->root->widget->rect); |
@@ -950,13 +950,13 @@ static iBool handleSidebarCommand_SidebarWidget_(iSidebarWidget *d, const char * | |||
950 | invalidate_ListWidget(d->list); | 950 | invalidate_ListWidget(d->list); |
951 | if (isAnimated) { | 951 | if (isAnimated) { |
952 | setFlags_Widget(w, horizontalOffset_WidgetFlag, iTrue); | 952 | setFlags_Widget(w, horizontalOffset_WidgetFlag, iTrue); |
953 | setVisualOffset_Widget(w, (d->side == left_SideBarSide ? -1 : 1) * w->rect.size.x, 0, 0); | 953 | setVisualOffset_Widget(w, (d->side == left_SidebarSide ? -1 : 1) * w->rect.size.x, 0, 0); |
954 | setVisualOffset_Widget(w, 0, 300, easeOut_AnimFlag | softer_AnimFlag); | 954 | setVisualOffset_Widget(w, 0, 300, easeOut_AnimFlag | softer_AnimFlag); |
955 | } | 955 | } |
956 | } | 956 | } |
957 | else if (isAnimated) { | 957 | else if (isAnimated) { |
958 | setFlags_Widget(w, horizontalOffset_WidgetFlag, iTrue); | 958 | setFlags_Widget(w, horizontalOffset_WidgetFlag, iTrue); |
959 | if (d->side == right_SideBarSide) { | 959 | if (d->side == right_SidebarSide) { |
960 | setVisualOffset_Widget(w, visX, 0, 0); | 960 | setVisualOffset_Widget(w, visX, 0, 0); |
961 | setVisualOffset_Widget(w, visX + w->rect.size.x, 300, easeOut_AnimFlag | softer_AnimFlag); | 961 | setVisualOffset_Widget(w, visX + w->rect.size.x, 300, easeOut_AnimFlag | softer_AnimFlag); |
962 | } | 962 | } |
@@ -984,7 +984,8 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) | |||
984 | /* Handle commands. */ | 984 | /* Handle commands. */ |
985 | if (isResize_UserEvent(ev)) { | 985 | if (isResize_UserEvent(ev)) { |
986 | checkModeButtonLayout_SidebarWidget_(d); | 986 | checkModeButtonLayout_SidebarWidget_(d); |
987 | if (deviceType_App() == phone_AppDeviceType && d->side == left_SideBarSide) { | 987 | if (deviceType_App() == phone_AppDeviceType && d->side == left_SidebarSide) { |
988 | setFlags_Widget(w, rightEdgeDraggable_WidgetFlag, isPortrait_App()); | ||
988 | /* In landscape, visibility of the toolbar is controlled separately. */ | 989 | /* In landscape, visibility of the toolbar is controlled separately. */ |
989 | if (isVisible_Widget(w)) { | 990 | if (isVisible_Widget(w)) { |
990 | postCommand_Widget(w, "sidebar.toggle"); | 991 | postCommand_Widget(w, "sidebar.toggle"); |
@@ -1038,6 +1039,11 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) | |||
1038 | postCommandf_App("sidebar.mode arg:%d toggle:1", identities_SidebarMode); | 1039 | postCommandf_App("sidebar.mode arg:%d toggle:1", identities_SidebarMode); |
1039 | return iTrue; | 1040 | return iTrue; |
1040 | } | 1041 | } |
1042 | else if (isPortraitPhone_App() && isVisible_Widget(w) && d->side == left_SidebarSide && | ||
1043 | equal_Command(cmd, "swipe.forward")) { | ||
1044 | postCommand_App("sidebar.toggle"); | ||
1045 | return iTrue; | ||
1046 | } | ||
1041 | else if (startsWith_CStr(cmd, cstr_String(&d->cmdPrefix))) { | 1047 | else if (startsWith_CStr(cmd, cstr_String(&d->cmdPrefix))) { |
1042 | if (handleSidebarCommand_SidebarWidget_(d, cmd + size_String(&d->cmdPrefix))) { | 1048 | if (handleSidebarCommand_SidebarWidget_(d, cmd + size_String(&d->cmdPrefix))) { |
1043 | return iTrue; | 1049 | return iTrue; |
@@ -1068,7 +1074,7 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) | |||
1068 | const int resMid = d->resizer->rect.size.x / 2; | 1074 | const int resMid = d->resizer->rect.size.x / 2; |
1069 | setWidth_SidebarWidget( | 1075 | setWidth_SidebarWidget( |
1070 | d, | 1076 | d, |
1071 | ((d->side == left_SideBarSide | 1077 | ((d->side == left_SidebarSide |
1072 | ? inner.x | 1078 | ? inner.x |
1073 | : (right_Rect(rect_Root(w->root)) - coord_Command(cmd).x)) + | 1079 | : (right_Rect(rect_Root(w->root)) - coord_Command(cmd).x)) + |
1074 | resMid) / (float) gap_UI); | 1080 | resMid) / (float) gap_UI); |
@@ -1547,7 +1553,7 @@ static void draw_SidebarWidget_(const iSidebarWidget *d) { | |||
1547 | if (isVisible_Widget(w)) { | 1553 | if (isVisible_Widget(w)) { |
1548 | drawVLine_Paint( | 1554 | drawVLine_Paint( |
1549 | &p, | 1555 | &p, |
1550 | addX_I2(d->side == left_SideBarSide ? topRight_Rect(bounds) : topLeft_Rect(bounds), -1), | 1556 | addX_I2(d->side == left_SidebarSide ? topRight_Rect(bounds) : topLeft_Rect(bounds), -1), |
1551 | height_Rect(bounds), | 1557 | height_Rect(bounds), |
1552 | uiSeparator_ColorId); | 1558 | uiSeparator_ColorId); |
1553 | } | 1559 | } |