Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2018-06-14 12:29:44 +0300
committerClément Foucault <foucault.clem@gmail.com>2018-06-14 12:29:44 +0300
commit62f594ca7b88a225984ca2d10bd35809707065f4 (patch)
tree57defd2076e9e6f7667068fd21a8b881c1a712b7 /source/blender/editors/interface/interface.c
parent7449dc8d131561c24bad99a8b057706fb69c3ecb (diff)
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.
Diffstat (limited to 'source/blender/editors/interface/interface.c')
-rw-r--r--source/blender/editors/interface/interface.c29
1 files changed, 26 insertions, 3 deletions
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);