Fix T38348: Panel remains scrolled when switching tabs

This commit is contained in:
Campbell Barton 2014-02-22 13:07:02 +11:00
parent b7fa08f88a
commit 543b57fbeb
3 changed files with 38 additions and 0 deletions

@ -205,6 +205,8 @@ void UI_view2d_getscale_inverse(struct View2D *v2d, float *x, float *y);
void UI_view2d_getcenter(struct View2D *v2d, float *x, float *y);
void UI_view2d_setcenter(struct View2D *v2d, float x, float y);
void UI_view2d_offset(struct View2D *v2d, float xfac, float yfac);
short UI_view2d_mouse_in_scrollers(const struct bContext *C, struct View2D *v2d, int x, int y);
/* cached text drawing in v2d, to allow pixel-aligned draw as post process */

@ -61,6 +61,7 @@
#include "ED_screen.h"
#include "UI_view2d.h"
#include "UI_interface.h"
#include "UI_interface_icons.h"
#include "UI_resources.h"
@ -1638,6 +1639,10 @@ int ui_handler_panel_region(bContext *C, const wmEvent *event, ARegion *ar)
if (pc_dyn) {
UI_panel_category_active_set(ar, pc_dyn->idname);
ED_region_tag_redraw(ar);
/* reset scroll to the top [#38348] */
UI_view2d_offset(&ar->v2d, -1.0f, 1.0f);
retval = WM_UI_HANDLER_BREAK;
}
}
@ -1652,6 +1657,8 @@ int ui_handler_panel_region(bContext *C, const wmEvent *event, ARegion *ar)
if (LIKELY(pc_dyn)) {
pc_dyn = (event->type == WHEELDOWNMOUSE) ? pc_dyn->next : pc_dyn->prev;
if (pc_dyn) {
/* intentionally don't reset scroll in this case,
* this allows for quick browsing between tabs */
UI_panel_category_active_set(ar, pc_dyn->idname);
ED_region_tag_redraw(ar);
}

@ -2114,6 +2114,35 @@ void UI_view2d_setcenter(struct View2D *v2d, float x, float y)
UI_view2d_curRect_validate(v2d);
}
/**
* Simple pan function
* (0.0, 0.0) bottom left
* (0.5, 0.5) center
* (1.0, 1.0) top right.
*/
void UI_view2d_offset(struct View2D *v2d, float xfac, float yfac)
{
if (xfac != -1.0f) {
const float xsize = BLI_rctf_size_x(&v2d->cur);
const float xmin = v2d->tot.xmin;
const float xmax = v2d->tot.xmax - xsize;
v2d->cur.xmin = (xmin * (1.0f - xfac)) + (xmax * xfac);
v2d->cur.xmax = v2d->cur.xmin + xsize;
}
if (yfac != -1.0f) {
const float ysize = BLI_rctf_size_y(&v2d->cur);
const float ymin = v2d->tot.ymin;
const float ymax = v2d->tot.ymax - ysize;
v2d->cur.ymin = (ymin * (1.0f - yfac)) + (ymax * yfac);
v2d->cur.ymax = v2d->cur.ymin + ysize;
}
UI_view2d_curRect_validate(v2d);
}
/* Check if mouse is within scrollers
* - Returns appropriate code for match
* 'h' = in horizontal scroller