summaryrefslogtreecommitdiff
path: root/src/ui/listwidget.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-12-04 07:40:56 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-12-04 07:40:56 +0200
commit723fcbf263bd2f5ff6c259a47091ebf685b50723 (patch)
tree5ed11977ee09fa542ed62a12c73117a27140d04e /src/ui/listwidget.c
parentad86fbe2cffa2bea07d004782e711932c5c91a79 (diff)
Mobile: Sidebar is now a vertically sliding panel
Switched the phone sidebar to use the iOS half/full-height sliding sheet design. This is better for finger reachability and for retaining access to the current page.
Diffstat (limited to 'src/ui/listwidget.c')
-rw-r--r--src/ui/listwidget.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/src/ui/listwidget.c b/src/ui/listwidget.c
index 82e4e451..d12afc4c 100644
--- a/src/ui/listwidget.c
+++ b/src/ui/listwidget.c
@@ -81,6 +81,7 @@ void init_ListWidget(iListWidget *d) {
81 setThumb_ScrollWidget(d->scroll, 0, 0); 81 setThumb_ScrollWidget(d->scroll, 0, 0);
82 init_SmoothScroll(&d->scrollY, w, scrollBegan_ListWidget_); 82 init_SmoothScroll(&d->scrollY, w, scrollBegan_ListWidget_);
83 d->itemHeight = 0; 83 d->itemHeight = 0;
84 d->scrollMode = normal_ScrollMode;
84 d->noHoverWhileScrolling = iFalse; 85 d->noHoverWhileScrolling = iFalse;
85 init_PtrArray(&d->items); 86 init_PtrArray(&d->items);
86 d->hoverItem = iInvalidPos; 87 d->hoverItem = iInvalidPos;
@@ -187,6 +188,10 @@ void setScrollPos_ListWidget(iListWidget *d, int pos) {
187 refresh_Widget(as_Widget(d)); 188 refresh_Widget(as_Widget(d));
188} 189}
189 190
191void setScrollMode_ListWidget(iListWidget *d, enum iScrollMode mode) {
192 d->scrollMode = mode;
193}
194
190void scrollOffset_ListWidget(iListWidget *d, int offset) { 195void scrollOffset_ListWidget(iListWidget *d, int offset) {
191 moveSpan_SmoothScroll(&d->scrollY, offset, 0); 196 moveSpan_SmoothScroll(&d->scrollY, offset, 0);
192} 197}
@@ -366,12 +371,28 @@ static iBool endDrag_ListWidget_(iListWidget *d, iInt2 endPos) {
366 return iTrue; 371 return iTrue;
367} 372}
368 373
374static iBool isScrollDisabled_ListWidget_(const iListWidget *d, const SDL_Event *ev) {
375 int dir = 0;
376 if (ev->type == SDL_MOUSEWHEEL) {
377 dir = iSign(ev->wheel.y);
378 }
379 switch (d->scrollMode) {
380 case disabledAtTopBothDirections_ScrollMode:
381 return scrollPos_ListWidget(d) <= 0;
382 case disabledAtTopUpwards_ScrollMode:
383 return scrollPos_ListWidget(d) <= 0 && dir > 0;
384 default:
385 break;
386 }
387 return iFalse;
388}
389
369static iBool processEvent_ListWidget_(iListWidget *d, const SDL_Event *ev) { 390static iBool processEvent_ListWidget_(iListWidget *d, const SDL_Event *ev) {
370 iWidget *w = as_Widget(d); 391 iWidget *w = as_Widget(d);
371 if (isMetricsChange_UserEvent(ev)) { 392 if (isMetricsChange_UserEvent(ev)) {
372 invalidate_ListWidget(d); 393 invalidate_ListWidget(d);
373 } 394 }
374 else if (processEvent_SmoothScroll(&d->scrollY, ev)) { 395 else if (!isScrollDisabled_ListWidget_(d, ev) && processEvent_SmoothScroll(&d->scrollY, ev)) {
375 return iTrue; 396 return iTrue;
376 } 397 }
377 else if (isCommand_SDLEvent(ev)) { 398 else if (isCommand_SDLEvent(ev)) {
@@ -420,6 +441,18 @@ static iBool processEvent_ListWidget_(iListWidget *d, const SDL_Event *ev) {
420 } 441 }
421 } 442 }
422 if (ev->type == SDL_MOUSEWHEEL && isHover_Widget(w)) { 443 if (ev->type == SDL_MOUSEWHEEL && isHover_Widget(w)) {
444 if (isScrollDisabled_ListWidget_(d, ev)) {
445 if (ev->wheel.which == SDL_TOUCH_MOUSEID) {
446 /* TODO: Could generalize this selection of the scrollable parent. */
447 extern iWidgetClass Class_SidebarWidget;
448 iWidget *sidebar = findParentClass_Widget(w, &Class_SidebarWidget);
449 if (sidebar) {
450 transferAffinity_Touch(w, sidebar);
451 d->noHoverWhileScrolling = iTrue;
452 }
453 }
454 return iFalse;
455 }
423 int amount = -ev->wheel.y; 456 int amount = -ev->wheel.y;
424 if (isPerPixel_MouseWheelEvent(&ev->wheel)) { 457 if (isPerPixel_MouseWheelEvent(&ev->wheel)) {
425 stop_Anim(&d->scrollY.pos); 458 stop_Anim(&d->scrollY.pos);