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
This commit is contained in:
parent
b6a50b5dcb
commit
df31ecf0c3
|
@ -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;
|
||||
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);
|
||||
|
||||
/* Convert pan to scroll-wheel. */
|
||||
if (type == MOUSEPAN) {
|
||||
ui_pan_to_scroll(event, &type, &val);
|
||||
}
|
||||
|
||||
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:
|
||||
|
|
|
@ -62,9 +62,9 @@ struct wmTimer;
|
|||
#define UI_MENU_SUBMENU_PADDING (6 * UI_DPI_FAC)
|
||||
|
||||
/* menu scrolling */
|
||||
#define UI_MENU_SCROLL_ARROW 12
|
||||
#define UI_MENU_SCROLL_MOUSE (UI_MENU_SCROLL_ARROW + 2)
|
||||
#define UI_MENU_SCROLL_PAD 4
|
||||
#define UI_MENU_SCROLL_ARROW (12 * UI_DPI_FAC)
|
||||
#define UI_MENU_SCROLL_MOUSE (UI_MENU_SCROLL_ARROW + 2 * UI_DPI_FAC)
|
||||
#define UI_MENU_SCROLL_PAD (4 * UI_DPI_FAC)
|
||||
|
||||
/* panel limits */
|
||||
#define UI_PANEL_MINX 100
|
||||
|
|
|
@ -4831,11 +4831,11 @@ static void ui_draw_clip_tri(uiBlock *block, rcti *rect, uiWidgetType *wt)
|
|||
|
||||
if (block->flag & UI_BLOCK_CLIPTOP) {
|
||||
/* XXX no scaling for UI here yet */
|
||||
UI_draw_icon_tri(BLI_rcti_cent_x(rect), rect->ymax - 8, 't', draw_color);
|
||||
UI_draw_icon_tri(BLI_rcti_cent_x(rect), rect->ymax - 6 * U.dpi_fac, 't', draw_color);
|
||||
}
|
||||
if (block->flag & UI_BLOCK_CLIPBOTTOM) {
|
||||
/* XXX no scaling for UI here yet */
|
||||
UI_draw_icon_tri(BLI_rcti_cent_x(rect), rect->ymin + 10, 'v', draw_color);
|
||||
UI_draw_icon_tri(BLI_rcti_cent_x(rect), rect->ymin + 10 * U.dpi_fac, 'v', draw_color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue