[Bf-blender-cvs] [99c970a94dc] master: UI: Allow Joining of Tiny Screen Areas

Harley Acheson noreply at git.blender.org
Wed Nov 16 18:53:16 CET 2022


Commit: 99c970a94dcfeeab047ae57ba1e4a64032f120f9
Author: Harley Acheson
Date:   Wed Nov 16 09:51:40 2022 -0800
Branches: master
https://developer.blender.org/rB99c970a94dcfeeab047ae57ba1e4a64032f120f9

UI: Allow Joining of Tiny Screen Areas

Allow joining of areas that are below our minimum sizes.

See D16522 for more details.

Differential Revision: https://developer.blender.org/D16522

Reviewed by Campbell Barton

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

M	source/blender/editors/screen/screen_edit.c

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

diff --git a/source/blender/editors/screen/screen_edit.c b/source/blender/editors/screen/screen_edit.c
index b2ec251697e..14ed5987cc7 100644
--- a/source/blender/editors/screen/screen_edit.c
+++ b/source/blender/editors/screen/screen_edit.c
@@ -268,35 +268,35 @@ eScreenDir area_getorientation(ScrArea *sa_a, ScrArea *sa_b)
     return SCREEN_DIR_NONE;
   }
 
-  const vec2s *sa_bl = &sa_a->v1->vec;
-  const vec2s *sa_tl = &sa_a->v2->vec;
-  const vec2s *sa_tr = &sa_a->v3->vec;
-  const vec2s *sa_br = &sa_a->v4->vec;
-
-  const vec2s *sb_bl = &sa_b->v1->vec;
-  const vec2s *sb_tl = &sa_b->v2->vec;
-  const vec2s *sb_tr = &sa_b->v3->vec;
-  const vec2s *sb_br = &sa_b->v4->vec;
-
-  if (sa_bl->x == sb_br->x && sa_tl->x == sb_tr->x) { /* sa_a to right of sa_b = W */
-    if ((MIN2(sa_tl->y, sb_tr->y) - MAX2(sa_bl->y, sb_br->y)) > AREAJOINTOLERANCEY) {
-      return 0;
-    }
+  short left_a = sa_a->v1->vec.x;
+  short right_a = sa_a->v3->vec.x;
+  short top_a = sa_a->v3->vec.y;
+  short bottom_a = sa_a->v1->vec.y;
+
+  short left_b = sa_b->v1->vec.x;
+  short right_b = sa_b->v3->vec.x;
+  short top_b = sa_b->v3->vec.y;
+  short bottom_b = sa_b->v1->vec.y;
+
+  /* How much these areas share a common edge. */
+  short overlapx = MIN2(right_a, right_b) - MAX2(left_a, left_b);
+  short overlapy = MIN2(top_a, top_b) - MAX2(bottom_a, bottom_b);
+
+  /* Minimum overlap required. */
+  const short minx = MIN3(AREAJOINTOLERANCEX, right_a - left_a, right_b - left_b);
+  const short miny = MIN3(AREAJOINTOLERANCEY, top_a - bottom_a, top_b - bottom_b);
+
+  if (top_a == bottom_b && overlapx >= minx) {
+    return 1; /* sa_a to bottom of sa_b = N */
   }
-  else if (sa_tl->y == sb_bl->y && sa_tr->y == sb_br->y) { /* sa_a to bottom of sa_b = N */
-    if ((MIN2(sa_tr->x, sb_br->x) - MAX2(sa_tl->x, sb_bl->x)) > AREAJOINTOLERANCEX) {
-      return 1;
-    }
+  if (bottom_a == top_b && overlapx >= minx) {
+    return 3; /* sa_a on top of sa_b = S */
   }
-  else if (sa_tr->x == sb_tl->x && sa_br->x == sb_bl->x) { /* sa_a to left of sa_b = E */
-    if ((MIN2(sa_tr->y, sb_tl->y) - MAX2(sa_br->y, sb_bl->y)) > AREAJOINTOLERANCEY) {
-      return 2;
-    }
+  if (left_a == right_b && overlapy >= miny) {
+    return 0; /* sa_a to right of sa_b = W */
   }
-  else if (sa_bl->y == sb_tl->y && sa_br->y == sb_tr->y) { /* sa_a on top of sa_b = S */
-    if ((MIN2(sa_br->x, sb_tr->x) - MAX2(sa_bl->x, sb_tl->x)) > AREAJOINTOLERANCEX) {
-      return 3;
-    }
+  if (right_a == left_b && overlapy >= miny) {
+    return 2; /* sa_a to left of sa_b = E */
   }
 
   return -1;
@@ -382,6 +382,9 @@ static bool screen_areas_can_align(bScreen *screen, ScrArea *sa1, ScrArea *sa2,
     const short xmin = MIN2(sa1->v1->vec.x, sa2->v1->vec.x);
     const short xmax = MAX2(sa1->v3->vec.x, sa2->v3->vec.x);
     LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
+      if (area == sa1 || area == sa2) {
+        continue;
+      }
       if (area->v3->vec.x - area->v1->vec.x < tolerance &&
           (area->v1->vec.x == xmin || area->v3->vec.x == xmax)) {
         /* There is a narrow vertical area sharing an edge of the combined bounds. */
@@ -393,6 +396,9 @@ static bool screen_areas_can_align(bScreen *screen, ScrArea *sa1, ScrArea *sa2,
     const short ymin = MIN2(sa1->v1->vec.y, sa2->v1->vec.y);
     const short ymax = MAX2(sa1->v3->vec.y, sa2->v3->vec.y);
     LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
+      if (area == sa1 || area == sa2) {
+        continue;
+      }
       if (area->v3->vec.y - area->v1->vec.y < tolerance &&
           (area->v1->vec.y == ymin || area->v3->vec.y == ymax)) {
         /* There is a narrow horizontal area sharing an edge of the combined bounds. */



More information about the Bf-blender-cvs mailing list