Fix T63822: Sidebar tabs active area dead-zone #2
authorCampbell Barton <ideasman42@gmail.com>
Wed, 24 Apr 2019 01:37:36 +0000 (11:37 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 24 Apr 2019 02:05:21 +0000 (12:05 +1000)
Take the entire gutter used for panel tabs into account.

Introduced in recent fix for T61554

source/blender/editors/include/ED_screen.h
source/blender/editors/include/UI_interface.h
source/blender/editors/interface/interface_panel.c
source/blender/editors/screen/area_query.c

index 0077114..543b2a5 100644 (file)
@@ -413,6 +413,9 @@ bool ED_region_overlap_isect_xy_with_margin(const ARegion *ar,
                                             const int event_xy[2],
                                             const int margin);
 
+bool ED_region_panel_category_gutter_calc_rect(const ARegion *ar, rcti *r_ar_gutter);
+bool ED_region_panel_category_gutter_isect_xy(const ARegion *ar, const int event_xy[2]);
+
 bool ED_region_contains_xy(const struct ARegion *ar, const int event_xy[2]);
 
 /* interface_region_hud.c */
index 3b77146..d6cfe7a 100644 (file)
@@ -1622,7 +1622,7 @@ void UI_panels_scale(struct ARegion *ar, float new_width);
 void UI_panel_label_offset(struct uiBlock *block, int *r_x, int *r_y);
 int UI_panel_size_y(const struct Panel *pa);
 
-bool UI_panel_category_is_visible(struct ARegion *ar);
+bool UI_panel_category_is_visible(const struct ARegion *ar);
 void UI_panel_category_add(struct ARegion *ar, const char *name);
 struct PanelCategoryDyn *UI_panel_category_find(struct ARegion *ar, const char *idname);
 struct PanelCategoryStack *UI_panel_category_active_find(struct ARegion *ar, const char *idname);
index 7117115..ae28c09 100644 (file)
@@ -1757,7 +1757,7 @@ static void ui_handle_panel_header(
   }
 }
 
-bool UI_panel_category_is_visible(ARegion *ar)
+bool UI_panel_category_is_visible(const ARegion *ar)
 {
   /* more than one */
   return ar->panels_category.first && ar->panels_category.first != ar->panels_category.last;
index 4d33567..420d70e 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "BLI_blenlib.h"
 #include "BLI_utildefines.h"
+#include "BLI_math_base.h"
 
 #include "RNA_types.h"
 
@@ -62,6 +63,35 @@ bool ED_region_overlap_isect_xy(const ARegion *ar, const int event_xy[2])
           ED_region_overlap_isect_y(ar, event_xy[1]));
 }
 
+bool ED_region_panel_category_gutter_calc_rect(const ARegion *ar, rcti *r_ar_gutter)
+{
+  *r_ar_gutter = ar->winrct;
+  if (UI_panel_category_is_visible(ar)) {
+    const int category_tabs_width = round_fl_to_int(UI_view2d_scale_get_x(&ar->v2d) *
+                                                    UI_PANEL_CATEGORY_MARGIN_WIDTH);
+    if (ar->alignment == RGN_ALIGN_LEFT) {
+      r_ar_gutter->xmax = r_ar_gutter->xmin + category_tabs_width;
+    }
+    else if (ar->alignment == RGN_ALIGN_RIGHT) {
+      r_ar_gutter->xmin = r_ar_gutter->xmax - category_tabs_width;
+    }
+    else {
+      BLI_assert(!"Unsupported alignment");
+    }
+    return true;
+  }
+  return false;
+}
+
+bool ED_region_panel_category_gutter_isect_xy(const ARegion *ar, const int event_xy[2])
+{
+  rcti ar_gutter;
+  if (ED_region_panel_category_gutter_calc_rect(ar, &ar_gutter)) {
+    return BLI_rcti_isect_pt_v(&ar_gutter, event_xy);
+  }
+  return false;
+}
+
 bool ED_region_overlap_isect_x_with_margin(const ARegion *ar, const int event_x, const int margin)
 {
   BLI_assert(ar->overlap);
@@ -121,11 +151,15 @@ bool ED_region_contains_xy(const ARegion *ar, const int event_xy[2])
           }
         }
         else if (ELEM(ar->alignment, RGN_ALIGN_LEFT, RGN_ALIGN_RIGHT)) {
-          if (!ED_region_overlap_isect_y_with_margin(ar, event_xy[1], overlap_margin)) {
+          if (ED_region_panel_category_gutter_isect_xy(ar, event_xy)) {
+            /* pass */
+          }
+          else if (!ED_region_overlap_isect_y_with_margin(ar, event_xy[1], overlap_margin)) {
             return false;
           }
         }
         else {
+          /* No panel categories for horizontal regions currently. */
           if (!ED_region_overlap_isect_xy_with_margin(ar, event_xy, overlap_margin)) {
             return false;
           }