diff options
author | Yevgeny Makarov <jenkm> | 2020-11-24 04:22:20 +0300 |
---|---|---|
committer | Harley Acheson <harley.acheson@gmail.com> | 2020-11-24 04:22:20 +0300 |
commit | df31ecf0c3e3b406906dd8bbe99cb75273e9dc4b (patch) | |
tree | 402ec79c14d91a4a00bdd743279cb4ad1c32d2ae /source/blender/editors/interface/interface_handlers.c | |
parent | b6a50b5dcb461fe06cc3efc76b34e483a2ca6c0e (diff) |
UI: Add Trackpad Smooth Scrolling for Popovers
Adds smooth scrolling with the trackpad for popovers. Also fixes the position of the scroll arrows on high-DPI.
Differential Revision: https://developer.blender.org/D9533
Reviewed by Brecht Van Lommel
Diffstat (limited to 'source/blender/editors/interface/interface_handlers.c')
-rw-r--r-- | source/blender/editors/interface/interface_handlers.c | 73 |
1 files changed, 42 insertions, 31 deletions
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 7dd6e400ae7..4fe4bbaf189 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -9327,26 +9327,26 @@ static void ui_menu_scroll_apply_offset_y(ARegion *region, uiBlock *block, float { BLI_assert(dy != 0.0f); - if (ui_block_is_menu(block)) { - if (dy < 0.0f) { - /* Stop at top item, extra 0.5 UI_UNIT_Y makes it snap nicer. */ - float ymax = -FLT_MAX; - LISTBASE_FOREACH (uiBut *, bt, &block->buttons) { - ymax = max_ff(ymax, bt->rect.ymax); - } - if (ymax + dy - UI_UNIT_Y * 0.5f < block->rect.ymax - UI_MENU_SCROLL_PAD) { - dy = block->rect.ymax - ymax - UI_MENU_SCROLL_PAD; - } + const int scroll_pad = ui_block_is_menu(block) ? UI_MENU_SCROLL_PAD : UI_UNIT_Y * 0.5f; + + if (dy < 0.0f) { + /* Stop at top item, extra 0.5 UI_UNIT_Y makes it snap nicer. */ + float ymax = -FLT_MAX; + LISTBASE_FOREACH (uiBut *, bt, &block->buttons) { + ymax = max_ff(ymax, bt->rect.ymax); } - else { - /* Stop at bottom item, extra 0.5 UI_UNIT_Y makes it snap nicer. */ - float ymin = FLT_MAX; - LISTBASE_FOREACH (uiBut *, bt, &block->buttons) { - ymin = min_ff(ymin, bt->rect.ymin); - } - if (ymin + dy + UI_UNIT_Y * 0.5f > block->rect.ymin + UI_MENU_SCROLL_PAD) { - dy = block->rect.ymin - ymin + UI_MENU_SCROLL_PAD; - } + if (ymax + dy - UI_UNIT_Y * 0.5f < block->rect.ymax - scroll_pad) { + dy = block->rect.ymax - ymax - scroll_pad; + } + } + else { + /* Stop at bottom item, extra 0.5 UI_UNIT_Y makes it snap nicer. */ + float ymin = FLT_MAX; + LISTBASE_FOREACH (uiBut *, bt, &block->buttons) { + ymin = min_ff(ymin, bt->rect.ymin); + } + if (ymin + dy + UI_UNIT_Y * 0.5f > block->rect.ymin + scroll_pad) { + dy = block->rect.ymin - ymin + scroll_pad; } } @@ -9697,24 +9697,17 @@ static int ui_handle_menu_event(bContext *C, retval = WM_UI_HANDLER_BREAK; break; - case WHEELUPMOUSE: - case WHEELDOWNMOUSE: + /* Smooth scrolling for popovers. */ case MOUSEPAN: { if (IS_EVENT_MOD(event, shift, ctrl, alt, oskey)) { /* pass */ } else if (!ui_block_is_menu(block)) { - int type = event->type; - int val = event->val; - - /* Convert pan to scroll-wheel. */ - if (type == MOUSEPAN) { - ui_pan_to_scroll(event, &type, &val); - } + if (block->flag & (UI_BLOCK_CLIPTOP | UI_BLOCK_CLIPBOTTOM)) { + const float dy = event->y - event->prevy; + if (dy != 0.0f) { + ui_menu_scroll_apply_offset_y(region, block, dy); - if (type != MOUSEPAN) { - const int scroll_dir = (type == WHEELUPMOUSE) ? 1 : -1; - if (ui_menu_scroll_step(region, block, scroll_dir)) { if (but) { but->active->cancel = true; button_activate_exit(C, but, but->active, false, false); @@ -9726,6 +9719,24 @@ static int ui_handle_menu_event(bContext *C, } ATTR_FALLTHROUGH; } + case WHEELUPMOUSE: + case WHEELDOWNMOUSE: { + if (IS_EVENT_MOD(event, shift, ctrl, alt, oskey)) { + /* pass */ + } + else if (!ui_block_is_menu(block)) { + const int scroll_dir = (event->type == WHEELUPMOUSE) ? 1 : -1; + if (ui_menu_scroll_step(region, block, scroll_dir)) { + if (but) { + but->active->cancel = true; + button_activate_exit(C, but, but->active, false, false); + } + WM_event_add_mousemove(CTX_wm_window(C)); + } + break; + } + ATTR_FALLTHROUGH; + } case EVT_UPARROWKEY: case EVT_DOWNARROWKEY: case EVT_PAGEUPKEY: |