Commit: 543b57fbeb6592421d3f133d4d40cc161a46894c
Author: Campbell Barton
Date:   Sat Feb 22 13:07:02 2014 +1100
https://developer.blender.org/rB543b57fbeb6592421d3f133d4d40cc161a46894c

Fix T38348: Panel remains scrolled when switching tabs

===================================================================

M       source/blender/editors/include/UI_view2d.h
M       source/blender/editors/interface/interface_panel.c
M       source/blender/editors/interface/view2d.c

===================================================================

diff --git a/source/blender/editors/include/UI_view2d.h 
b/source/blender/editors/include/UI_view2d.h
index 3bae255..fe8ddee 100644
--- a/source/blender/editors/include/UI_view2d.h
+++ b/source/blender/editors/include/UI_view2d.h
@@ -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 */
diff --git a/source/blender/editors/interface/interface_panel.c 
b/source/blender/editors/interface/interface_panel.c
index 3a5d1f6..fada118 100644
--- a/source/blender/editors/interface/interface_panel.c
+++ b/source/blender/editors/interface/interface_panel.c
@@ -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);
                                                        }
diff --git a/source/blender/editors/interface/view2d.c 
b/source/blender/editors/interface/view2d.c
index ea350fd..f20a196 100644
--- a/source/blender/editors/interface/view2d.c
+++ b/source/blender/editors/interface/view2d.c
@@ -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

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to