diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-11-27 09:28:26 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-11-27 09:28:26 +0200 |
commit | 474843be86b5521b7899b498a96818b3b7100528 (patch) | |
tree | 805853c899229c6f704b6a1e4cf953fa4e5baf73 /src/ui | |
parent | dded8a306546e7575ce591f4d19531910c958e86 (diff) |
Widget: Allow scrolling tall widgets
Useful for menus and dialogs that wouldn't fit inside the window.
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/util.c | 5 | ||||
-rw-r--r-- | src/ui/widget.c | 20 | ||||
-rw-r--r-- | src/ui/widget.h | 1 |
3 files changed, 24 insertions, 2 deletions
diff --git a/src/ui/util.c b/src/ui/util.c index 04604662..5cab8b4f 100644 --- a/src/ui/util.c +++ b/src/ui/util.c | |||
@@ -402,7 +402,7 @@ iWidget *makeMenu_Widget(iWidget *parent, const iMenuItem *items, size_t n) { | |||
402 | setFlags_Widget(menu, | 402 | setFlags_Widget(menu, |
403 | keepOnTop_WidgetFlag | collapse_WidgetFlag | hidden_WidgetFlag | | 403 | keepOnTop_WidgetFlag | collapse_WidgetFlag | hidden_WidgetFlag | |
404 | arrangeVertical_WidgetFlag | arrangeSize_WidgetFlag | | 404 | arrangeVertical_WidgetFlag | arrangeSize_WidgetFlag | |
405 | resizeChildrenToWidestChild_WidgetFlag, | 405 | resizeChildrenToWidestChild_WidgetFlag | overflowScrollable_WidgetFlag, |
406 | iTrue); | 406 | iTrue); |
407 | for (size_t i = 0; i < n; ++i) { | 407 | for (size_t i = 0; i < n; ++i) { |
408 | const iMenuItem *item = &items[i]; | 408 | const iMenuItem *item = &items[i]; |
@@ -740,7 +740,8 @@ iWidget *makeSheet_Widget(const char *id) { | |||
740 | setBackgroundColor_Widget(sheet, uiBackground_ColorId); | 740 | setBackgroundColor_Widget(sheet, uiBackground_ColorId); |
741 | setFlags_Widget(sheet, | 741 | setFlags_Widget(sheet, |
742 | mouseModal_WidgetFlag | keepOnTop_WidgetFlag | arrangeVertical_WidgetFlag | | 742 | mouseModal_WidgetFlag | keepOnTop_WidgetFlag | arrangeVertical_WidgetFlag | |
743 | arrangeSize_WidgetFlag | centerHorizontal_WidgetFlag, | 743 | arrangeSize_WidgetFlag | centerHorizontal_WidgetFlag | |
744 | overflowScrollable_WidgetFlag, | ||
744 | iTrue); | 745 | iTrue); |
745 | return sheet; | 746 | return sheet; |
746 | } | 747 | } |
diff --git a/src/ui/widget.c b/src/ui/widget.c index d8c2c421..4d50da38 100644 --- a/src/ui/widget.c +++ b/src/ui/widget.c | |||
@@ -572,6 +572,26 @@ iBool processEvent_Widget(iWidget *d, const SDL_Event *ev) { | |||
572 | postCommand_Widget(d, "mouse.moved coord:%d %d", ev->motion.x, ev->motion.y); | 572 | postCommand_Widget(d, "mouse.moved coord:%d %d", ev->motion.x, ev->motion.y); |
573 | return iTrue; | 573 | return iTrue; |
574 | } | 574 | } |
575 | else if (d->flags & overflowScrollable_WidgetFlag && ev->type == SDL_MOUSEWHEEL) { | ||
576 | iRect bounds = bounds_Widget(d); | ||
577 | const iInt2 winSize = rootSize_Window(get_Window()); | ||
578 | if (height_Rect(bounds) > winSize.y) { | ||
579 | int step = ev->wheel.y; | ||
580 | #if !defined (iPlatformApple) | ||
581 | step *= lineHeight_Text(uiLabel_FontId); | ||
582 | #endif | ||
583 | bounds.pos.y += step; | ||
584 | if (step > 0) { | ||
585 | bounds.pos.y = iMin(bounds.pos.y, 0); | ||
586 | } | ||
587 | else { | ||
588 | bounds.pos.y = iMax(bounds.pos.y, winSize.y - height_Rect(bounds)); | ||
589 | } | ||
590 | d->rect.pos = localCoord_Widget(d->parent, bounds.pos); | ||
591 | refresh_Widget(d); | ||
592 | return iTrue; | ||
593 | } | ||
594 | } | ||
575 | switch (ev->type) { | 595 | switch (ev->type) { |
576 | case SDL_USEREVENT: { | 596 | case SDL_USEREVENT: { |
577 | if (ev->user.code == command_UserEventCode && d->commandHandler && | 597 | if (ev->user.code == command_UserEventCode && d->commandHandler && |
diff --git a/src/ui/widget.h b/src/ui/widget.h index f5e255f2..278ae081 100644 --- a/src/ui/widget.h +++ b/src/ui/widget.h | |||
@@ -88,6 +88,7 @@ enum iWidgetFlag { | |||
88 | #define moveToParentRightEdge_WidgetFlag iBit64(34) | 88 | #define moveToParentRightEdge_WidgetFlag iBit64(34) |
89 | #define wrapText_WidgetFlag iBit64(35) | 89 | #define wrapText_WidgetFlag iBit64(35) |
90 | #define borderTop_WidgetFlag iBit64(36) | 90 | #define borderTop_WidgetFlag iBit64(36) |
91 | #define overflowScrollable_WidgetFlag iBit64(37) | ||
91 | 92 | ||
92 | enum iWidgetAddPos { | 93 | enum iWidgetAddPos { |
93 | back_WidgetAddPos, | 94 | back_WidgetAddPos, |