Fix T38348: Panel remains scrolled when switching tabs
authorCampbell Barton <ideasman42@gmail.com>
Sat, 22 Feb 2014 02:07:02 +0000 (13:07 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 22 Feb 2014 02:07:02 +0000 (13:07 +1100)
source/blender/editors/include/UI_view2d.h
source/blender/editors/interface/interface_panel.c
source/blender/editors/interface/view2d.c

index 3bae255f297352e9fb6a259ac682842120a3d032..fe8ddee136c5badd6d065505a40942ec00f9b866 100644 (file)
@@ -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 */
index 3a5d1f6fdf370c0755098161aaa504241dc3329c..fada118e037c2d0d16a89be8472e9ac2d2939178 100644 (file)
@@ -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);
                                                        }
index ea350fd08df7222a4c9ec74c773b80e4359af083..f20a196627e54dfcd17908208b380ee140be46fb 100644 (file)
@@ -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