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
This commit is contained in:
Harley Acheson 2022-11-16 09:51:40 -08:00
parent cce4271b31
commit 99c970a94d
1 changed files with 30 additions and 24 deletions

View File

@ -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;
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;
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;
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;
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;
}
/* 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. */