[Bf-blender-cvs] [62f594ca7b8] blender2.8: UI: Make spacers align blocks on area divisions

Clément Foucault noreply at git.blender.org
Thu Jun 14 11:29:51 CEST 2018


Commit: 62f594ca7b88a225984ca2d10bd35809707065f4
Author: Clément Foucault
Date:   Thu Jun 14 11:29:44 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB62f594ca7b88a225984ca2d10bd35809707065f4

UI: Make spacers align blocks on area divisions

This solves the problem of blocks jumping around when changing modes and
center them to the area (in case of only 2 spacers).
Which is (in my own opinion) more aestetically pleasing.

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

M	source/blender/editors/interface/interface.c

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

diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 3b281315e38..b592a75c0d3 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -250,12 +250,35 @@ static void ui_update_flexible_spacing(const ARegion *region, uiBlock *block)
 		return;
 	}
 
-	const float spacing = ((region_width - buttons_width) / (float)sepr_flex_len);
-	float offset = 0;
+	/* We could get rid of this loop if we agree on a max number of spacer */
+	int *spacers_pos = alloca(sizeof(*spacers_pos) * (size_t)sepr_flex_len);
+	int i = 0;
+	for (uiBut *but = block->buttons.first; but; but = but->next) {
+		if (but->type == UI_BTYPE_SEPR_SPACER) {
+			ui_but_to_pixelrect(&rect, region, block, but);
+			spacers_pos[i] = rect.xmax + UI_HEADER_OFFSET;
+			i++;
+		}
+	}
+
+	const float segment_width = region_width / (float)sepr_flex_len;
+	float offset = 0, remaining_space = region_width - buttons_width;
+	i = 0;
 	for (uiBut *but = block->buttons.first; but; but = but->next) {
 		BLI_rctf_translate(&but->rect, offset, 0);
 		if (but->type == UI_BTYPE_SEPR_SPACER) {
-			offset += spacing;
+			/* How much the next block overlap with the current segment */
+			int overlap = (i == sepr_flex_len - 1) ? buttons_width - spacers_pos[i]
+			                                       : (spacers_pos[i+1] - spacers_pos[i]) / 2;
+			int segment_end = segment_width * (i+1);
+			int spacer_end = segment_end - overlap;
+			int spacer_sta = spacers_pos[i] + offset;
+			if (spacer_end > spacer_sta) {
+				float step = min_ff(remaining_space, spacer_end - spacer_sta);
+				remaining_space -= step;
+				offset += step;
+			}
+			i++;
 		}
 	}
 	ui_block_bounds_calc(block);



More information about the Bf-blender-cvs mailing list