[Bf-blender-cvs] [822c67364e8] master: UI: Fix odd behavior in region sizing, simplify code

George Vogiatzis noreply at git.blender.org
Wed Apr 3 15:02:37 CEST 2019


Commit: 822c67364e85f1092c25cdd5ab9d68c515deb09d
Author: George Vogiatzis
Date:   Wed Apr 3 14:53:57 2019 +0200
Branches: master
https://developer.blender.org/rB822c67364e85f1092c25cdd5ab9d68c515deb09d

UI: Fix odd behavior in region sizing, simplify code

* When resizing sidebars, don't collapse when the region becomes too big but
  instead clamp the region size to the available space.
* Fix clicking the tab to expand sidebars no working if the sidebar is too
  wide to fit. Instead make it less wide so it does fit.
* Fix incorrect limit on tool properties region height, for example in the
  file browser.

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

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

M	source/blender/editors/screen/area.c
M	source/blender/editors/screen/screen_ops.c
M	source/blender/makesdna/DNA_screen_types.h

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

diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c
index 411826d79c1..e599f3b7ed3 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -985,17 +985,7 @@ static void region_azones_add(const bScreen *screen, ScrArea *sa, ARegion *ar, c
 	const bool is_fullscreen = screen->state == SCREENFULL;
 
 	/* edge code (t b l r) is along which area edge azone will be drawn */
-
-	if (ar->regiontype == RGN_TYPE_HEADER && ar->winy + 6 > sa->winy) {
-		/* The logic for this is: when the header takes up the full area,
-		 * disallow hiding it to view the main window.
-		 *
-		 * Without this, you can drag down the file selectors header and hide it
-		 * by accident very easily (highly annoying!), the value 6 is arbitrary
-		 * but accounts for small common rounding problems when scaling the UI,
-		 * must be minimum '4' */
-	}
-	else if (alignment == RGN_ALIGN_TOP)
+	if (alignment == RGN_ALIGN_TOP)
 		region_azone_edge_initialize(sa, ar, AE_BOTTOM_TO_TOPLEFT, is_fullscreen);
 	else if (alignment == RGN_ALIGN_BOTTOM)
 		region_azone_edge_initialize(sa, ar, AE_TOP_TO_BOTTOMRIGHT, is_fullscreen);
diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c
index 4ce21013924..06eadedd7b6 100644
--- a/source/blender/editors/screen/screen_ops.c
+++ b/source/blender/editors/screen/screen_ops.c
@@ -2278,48 +2278,56 @@ typedef struct RegionMoveData {
 
 } RegionMoveData;
 
-
 static int area_max_regionsize(ScrArea *sa, ARegion *scalear, AZEdge edge)
 {
 	ARegion *ar;
 	int dist;
 
-	if (edge == AE_RIGHT_TO_TOPLEFT || edge == AE_LEFT_TO_TOPRIGHT) {
-		dist = BLI_rcti_size_x(&sa->totrct);
-	}
-	else {  /* AE_BOTTOM_TO_TOPLEFT, AE_TOP_TO_BOTTOMRIGHT */
-		dist = BLI_rcti_size_y(&sa->totrct);
-	}
+	/* regions in regions. */
+	if (scalear->alignment & RGN_SPLIT_PREV) {
+		const int align = scalear->alignment & RGN_ALIGN_ENUM_MASK;
 
-	/* subtractwidth of regions on opposite side
-	 * prevents dragging regions into other opposite regions */
-	for (ar = sa->regionbase.first; ar; ar = ar->next) {
-		if (ar == scalear)
-			continue;
+		if (ELEM(align, RGN_ALIGN_TOP, RGN_ALIGN_BOTTOM)) {
+			ar = scalear->prev;
+			dist = ar->winy + scalear->winy - U.pixelsize;
+		}
+		else if (ELEM(align, RGN_ALIGN_LEFT, RGN_ALIGN_RIGHT)) {
+			ar = scalear->prev;
+			dist = ar->winx + scalear->winx - U.pixelsize;
+		}
+	}
+	else {
+		if (edge == AE_RIGHT_TO_TOPLEFT || edge == AE_LEFT_TO_TOPRIGHT) {
+			dist = BLI_rcti_size_x(&sa->totrct);
+		}
+		else {  /* AE_BOTTOM_TO_TOPLEFT, AE_TOP_TO_BOTTOMRIGHT */
+			dist = BLI_rcti_size_y(&sa->totrct);
+		}
 
-		if (scalear->alignment == RGN_ALIGN_TOP && ar->alignment == RGN_ALIGN_BOTTOM)
-			dist -= ar->winy;
-		else if (scalear->alignment == RGN_ALIGN_BOTTOM && ar->alignment == RGN_ALIGN_TOP)
-			dist -= ar->winy;
-		else if (scalear->alignment == RGN_ALIGN_LEFT && ar->alignment == RGN_ALIGN_RIGHT)
-			dist -= ar->winx;
-		else if (scalear->alignment == RGN_ALIGN_RIGHT && ar->alignment == RGN_ALIGN_LEFT)
-			dist -= ar->winx;
+		/* subtractwidth of regions on opposite side
+		 * prevents dragging regions into other opposite regions */
+		for (ar = sa->regionbase.first; ar; ar = ar->next) {
+			if (ar == scalear)
+				continue;
 
-		/* case of regions in regions, like operator properties panel */
-		/* these can sit on top of other regions such as headers, so account for this */
-		else if (edge == AE_BOTTOM_TO_TOPLEFT && scalear->alignment & RGN_ALIGN_TOP &&
-		         ar->alignment == RGN_ALIGN_TOP && ar->regiontype == RGN_TYPE_HEADER)
-		{
-			dist -= ar->winy;
-		}
-		else if (edge == AE_TOP_TO_BOTTOMRIGHT && scalear->alignment & RGN_ALIGN_BOTTOM &&
-		         ar->alignment == RGN_ALIGN_BOTTOM && ar->regiontype == RGN_TYPE_HEADER)
-		{
-			dist -= ar->winy;
+			if (scalear->alignment == RGN_ALIGN_LEFT && ar->alignment == RGN_ALIGN_RIGHT) {
+				dist -= ar->winx;
+			}
+			else if (scalear->alignment == RGN_ALIGN_RIGHT && ar->alignment == RGN_ALIGN_LEFT) {
+				dist -= ar->winx;
+			}
+			else if (scalear->alignment == RGN_ALIGN_TOP &&
+			         (ar->alignment == RGN_ALIGN_BOTTOM || ar->regiontype == RGN_TYPE_HEADER)) {
+				dist -= ar->winy;
+			}
+			else if (scalear->alignment == RGN_ALIGN_BOTTOM &&
+			         (ar->alignment == RGN_ALIGN_TOP || ar->regiontype == RGN_TYPE_HEADER)) {
+				dist -= ar->winy;
+			}
 		}
 	}
 
+	dist /= UI_DPI_FAC;
 	return dist;
 }
 
@@ -2337,7 +2345,6 @@ static int region_scale_invoke(bContext *C, wmOperator *op, const wmEvent *event
 
 	if (az->ar) {
 		RegionMoveData *rmd = MEM_callocN(sizeof(RegionMoveData), "RegionMoveData");
-		int maxsize;
 
 		op->customdata = rmd;
 
@@ -2363,13 +2370,7 @@ static int region_scale_invoke(bContext *C, wmOperator *op, const wmEvent *event
 			rmd->origval = rmd->ar->sizey;
 		}
 
-		/* limit headers to standard height for now */
-		if (rmd->ar->regiontype == RGN_TYPE_HEADER)
-			maxsize = ED_area_headersize();
-		else
-			maxsize = 1000;
-
-		CLAMP(rmd->maxsize, 0, maxsize);
+		CLAMP(rmd->maxsize, 0, 1000);
 
 		/* add temp handler */
 		WM_event_add_modal_handler(C, op);
@@ -2380,24 +2381,6 @@ static int region_scale_invoke(bContext *C, wmOperator *op, const wmEvent *event
 	return OPERATOR_FINISHED;
 }
 
-static int region_scale_get_maxsize(RegionMoveData *rmd)
-{
-	int maxsize = 0;
-
-	if (rmd->edge == AE_LEFT_TO_TOPRIGHT || rmd->edge == AE_RIGHT_TO_TOPLEFT) {
-		return  (int) ( (rmd->sa->winx / UI_DPI_FAC) - UI_UNIT_X);
-	}
-
-	if (rmd->ar->regiontype == RGN_TYPE_TOOL_PROPS) {
-		/* this calculation seems overly verbose
-		 * can someone explain why this method is necessary? - campbell */
-		const bool top_header = ED_area_header_alignment(rmd->sa) == RGN_ALIGN_TOP;
-		maxsize = rmd->maxsize - ((top_header) ? UI_UNIT_Y * 2 : UI_UNIT_Y) - (UI_UNIT_Y / 4);
-	}
-
-	return maxsize;
-}
-
 static void region_scale_validate_size(RegionMoveData *rmd)
 {
 	if ((rmd->ar->flag & RGN_FLAG_HIDDEN) == 0) {
@@ -2409,7 +2392,7 @@ static void region_scale_validate_size(RegionMoveData *rmd)
 		else
 			size = &rmd->ar->sizey;
 
-		maxsize = region_scale_get_maxsize(rmd);
+		maxsize = rmd->maxsize - (UI_UNIT_Y / UI_DPI_FAC);
 
 		if (*size > maxsize && maxsize > 0)
 			*size = maxsize;
@@ -2469,7 +2452,6 @@ static int region_scale_modal(bContext *C, wmOperator *op, const wmEvent *event)
 				}
 			}
 			else {
-				int maxsize = region_scale_get_maxsize(rmd);
 				delta = event->y - rmd->origy;
 				if (rmd->edge == AE_BOTTOM_TO_TOPLEFT) delta = -delta;
 
@@ -2494,9 +2476,6 @@ static int region_scale_modal(bContext *C, wmOperator *op, const wmEvent *event)
 					if (!(rmd->ar->flag & RGN_FLAG_HIDDEN))
 						region_scale_toggle_hidden(C, rmd);
 				}
-				else if (maxsize > 0 && (rmd->ar->sizey > maxsize)) {
-					rmd->ar->sizey = maxsize;
-				}
 				else if (rmd->ar->flag & RGN_FLAG_HIDDEN) {
 					region_scale_toggle_hidden(C, rmd);
 				}
diff --git a/source/blender/makesdna/DNA_screen_types.h b/source/blender/makesdna/DNA_screen_types.h
index 41999a95cf8..fb111fad335 100644
--- a/source/blender/makesdna/DNA_screen_types.h
+++ b/source/blender/makesdna/DNA_screen_types.h
@@ -609,6 +609,7 @@ enum {
 #define RGN_ALIGN_VSPLIT	6
 #define RGN_ALIGN_FLOAT		7
 #define RGN_ALIGN_QSPLIT	8
+#define RGN_ALIGN_ENUM_MASK 0x0F
 
 #define RGN_SPLIT_PREV		32



More information about the Bf-blender-cvs mailing list