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/widget.c | |
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/widget.c')
-rw-r--r-- | src/ui/widget.c | 20 |
1 files changed, 20 insertions, 0 deletions
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 && |