[Bf-blender-cvs] [09e5aa5] master: Fix T39234: popup menus behave poorly when they have not enough width for all their columns.

Bastien Montagne noreply at git.blender.org
Tue Apr 15 16:56:41 CEST 2014


Commit: 09e5aa5156486585b3d23f52f927db744fb9a055
Author: Bastien Montagne
Date:   Tue Apr 15 16:49:49 2014 +0200
https://developer.blender.org/rB09e5aa5156486585b3d23f52f927db744fb9a055

Fix T39234: popup menus behave poorly when they have not enough width for all their columns.

Issue fixed by:
* Not having constant width for all columns, but adapt each to its content's width;
* Adapting undo's menu height to undo list length (so that we never have more than three columns).

It is still possible to get issues in extreme cases (small screen, high DPI size,
long op names everywhere...), but this should now be rare corner cases.

Also fixes a minor glitch with undo menu (first column had one item less than the others...).

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

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

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

diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 7e6e00b..5622288 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -207,43 +207,41 @@ void ui_block_translate(uiBlock *block, int x, int y)
 static void ui_text_bounds_block(uiBlock *block, float offset)
 {
 	uiStyle *style = UI_GetStyle();
-	uiBut *bt;
-	int i = 0, j, x1addval = offset, nextcol;
-	int lastcol = 0, col = 0;
-	
+	uiBut *bt, *init_col_bt, *col_bt;
+	int i = 0, j, x1addval = offset;
+
 	uiStyleFontSet(&style->widget);
-	
-	for (bt = block->buttons.first; bt; bt = bt->next) {
+
+	for (init_col_bt = bt = block->buttons.first; bt; bt = bt->next) {
 		if (!ELEM(bt->type, SEPR, SEPRLINE)) {
 			j = BLF_width(style->widget.uifont_id, bt->drawstr, sizeof(bt->drawstr));
 
-			if (j > i) i = j;
+			if (j > i)
+				i = j;
 		}
 
-		if (bt->next && bt->rect.xmin < bt->next->rect.xmin)
-			lastcol++;
-	}
+		if (bt->next && bt->rect.xmin < bt->next->rect.xmin) {
+			/* End of this column, and it’s not the last one. */
+			for (col_bt = init_col_bt; col_bt->prev != bt; col_bt = col_bt->next) {
+				col_bt->rect.xmin = x1addval;
+				col_bt->rect.xmax = x1addval + i + block->bounds;
 
-	/* cope with multi collumns */
-	bt = block->buttons.first;
-	while (bt) {
-		nextcol = (bt->next && bt->rect.xmin < bt->next->rect.xmin);
-		
-		bt->rect.xmin = x1addval;
-		bt->rect.xmax = bt->rect.xmin + i + block->bounds;
-		
-		if (col == lastcol) {
-			bt->rect.xmax = max_ff(bt->rect.xmax, offset + block->minbounds);
-		}
+				ui_check_but(col_bt);  /* clips text again */
+			}
 
-		ui_check_but(bt);  /* clips text again */
-		
-		if (nextcol) {
+			/* And we prepare next column. */
 			x1addval += i + block->bounds;
-			col++;
+			i = 0;
+			init_col_bt = col_bt;
 		}
-		
-		bt = bt->next;
+	}
+
+	/* Last column. */
+	for (col_bt = init_col_bt; col_bt; col_bt = col_bt->next) {
+		col_bt->rect.xmin = x1addval;
+		col_bt->rect.xmax = max_ff(x1addval + i + block->bounds, offset + block->minbounds);
+
+		ui_check_but(col_bt);  /* clips text again */
 	}
 }
 
diff --git a/source/blender/editors/util/undo.c b/source/blender/editors/util/undo.c
index 434f1e3..733b45f 100644
--- a/source/blender/editors/util/undo.c
+++ b/source/blender/editors/util/undo.c
@@ -533,14 +533,20 @@ static int undo_history_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSE
 			uiLayout *layout = uiPupMenuLayout(pup);
 			uiLayout *split = uiLayoutSplit(layout, 0.0f, false);
 			uiLayout *column = NULL;
+			const int col_size = 20 + totitem / 12;
 			int i, c;
+			bool add_col = true;
 			
-			for (c = 0, i = totitem - 1; i >= 0; i--, c++) {
-				if ( (c % 20) == 0)
+			for (c = 0, i = totitem; i--;) {
+				if (add_col && !(c % col_size)) {
 					column = uiLayoutColumn(split, false);
-				if (item[i].identifier)
+					add_col = false;
+				}
+				if (item[i].identifier) {
 					uiItemIntO(column, item[i].name, item[i].icon, op->type->idname, "item", item[i].value);
-				
+					++c;
+					add_col = true;
+				}
 			}
 			
 			MEM_freeN(item);




More information about the Bf-blender-cvs mailing list