[Bf-blender-cvs] [e5e0888] master: UI: allow passing "" for icon only enum buttons and still get an icon

Campbell Barton noreply at git.blender.org
Wed Mar 12 12:56:39 CET 2014


Commit: e5e0888a8f024bdc2d3196055762050195bec7a9
Author: Campbell Barton
Date:   Wed Mar 12 19:24:47 2014 +1100
https://developer.blender.org/rBe5e0888a8f024bdc2d3196055762050195bec7a9

UI: allow passing "" for icon only enum buttons and still get an icon

Enum icon-only buttons were getting their strings set,
then truncated with blenders string shortening methods, then not drawn
because there was no room (since buttons are icon width).

Modify UI code so icon-only buttons don't get names and passing "" to a
button won't have its text set later on.

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

M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface.c
M	source/blender/editors/interface/interface_layout.c
M	source/blender/editors/interface/interface_templates.c
M	source/blender/editors/interface/interface_utils.c
M	source/blender/editors/interface/interface_widgets.c
M	source/blender/editors/screen/area.c

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

diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index d235441..e486ccc8 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -185,8 +185,6 @@ enum {
  *       (except for the 'align' ones)!
  */
 enum {
-	/* draw enum-like up/down arrows for button */
-	UI_BUT_DRAW_ENUM_ARROWS  = (1 << 0),
 	/* Text and icon alignment (by default, they are centered). */
 	UI_BUT_TEXT_LEFT         = (1 << 1),
 	UI_BUT_ICON_LEFT         = (1 << 2),
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 765a73b..b8e0002 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -3164,33 +3164,36 @@ static uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, const char *s
 	}
 
 	/* use rna values if parameters are not specified */
-	if (!str) {
-		if (ELEM3(type, MENU, ROW, LISTROW) && proptype == PROP_ENUM) {
-			/* MENU is handled a little differently here */
-			EnumPropertyItem *item;
-			int value;
-			bool free;
-			int i;
+	if ((proptype == PROP_ENUM) && ELEM3(type, MENU, ROW, LISTROW)) {
+		/* MENU is handled a little differently here */
+		EnumPropertyItem *item;
+		int value;
+		bool free;
+		int i;
 
-			RNA_property_enum_items(block->evil_C, ptr, prop, &item, NULL, &free);
+		RNA_property_enum_items(block->evil_C, ptr, prop, &item, NULL, &free);
 
-			if (type == MENU) {
-				value = RNA_property_enum_get(ptr, prop);
-			}
-			else {
-				value = (int)max;
-			}
+		if (type == MENU) {
+			value = RNA_property_enum_get(ptr, prop);
+		}
+		else {
+			value = (int)max;
+		}
 
-			i = RNA_enum_from_value(item, value);
-			if (i != -1) {
-				str = item[i].name;
-				icon = item[i].icon;
+		i = RNA_enum_from_value(item, value);
+		if (i != -1) {
 
+			if (!str) {
+				str = item[i].name;
 #ifdef WITH_INTERNATIONAL
 				str = CTX_IFACE_(RNA_property_translation_context(prop), str);
 #endif
 			}
-			else {
+
+			icon = item[i].icon;
+		}
+		else {
+			if (!str) {
 				if (type == MENU) {
 					str = "";
 				}
@@ -3198,19 +3201,21 @@ static uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, const char *s
 					str = RNA_property_ui_name(prop);
 				}
 			}
+		}
 
-			if (type == MENU) {
-				func = ui_def_but_rna__menu;
-			}
+		if (type == MENU) {
+			func = ui_def_but_rna__menu;
+		}
 
-			if (free) {
-				MEM_freeN(item);
-			}
+		if (free) {
+			MEM_freeN(item);
 		}
-		else {
+	}
+	else {
+		if (!str) {
 			str = RNA_property_ui_name(prop);
-			icon = RNA_property_ui_icon(prop);
 		}
+		icon = RNA_property_ui_icon(prop);
 	}
 
 	if (!tip && proptype != PROP_ENUM)
diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c
index b5255eb..0ba47eb 100644
--- a/source/blender/editors/interface/interface_layout.c
+++ b/source/blender/editors/interface/interface_layout.c
@@ -1178,12 +1178,18 @@ void uiItemFullR(uiLayout *layout, PointerRNA *ptr, PropertyRNA *prop, int index
 	if (icon == ICON_NONE)
 		icon = RNA_property_ui_icon(prop);
 	
-	if (ELEM4(type, PROP_INT, PROP_FLOAT, PROP_STRING, PROP_POINTER))
+	if (flag & UI_ITEM_R_ICON_ONLY) {
+		/* pass */
+	}
+	else if (ELEM4(type, PROP_INT, PROP_FLOAT, PROP_STRING, PROP_POINTER)) {
 		name = ui_item_name_add_colon(name, namestr);
-	else if (type == PROP_BOOLEAN && is_array && index == RNA_NO_INDEX)
+	}
+	else if (type == PROP_BOOLEAN && is_array && index == RNA_NO_INDEX) {
 		name = ui_item_name_add_colon(name, namestr);
-	else if (type == PROP_ENUM && index != RNA_ENUM_VALUE)
+	}
+	else if (type == PROP_ENUM && index != RNA_ENUM_VALUE) {
 		name = ui_item_name_add_colon(name, namestr);
+	}
 
 	if (layout->root->type == UI_LAYOUT_MENU) {
 		if (type == PROP_BOOLEAN && ((is_array == false) || (index != RNA_NO_INDEX))) {
@@ -1257,6 +1263,12 @@ void uiItemFullR(uiLayout *layout, PointerRNA *ptr, PropertyRNA *prop, int index
 
 	if (no_bg)
 		uiBlockSetEmboss(block, UI_EMBOSS);
+
+	/* ensure text isn't added to icon_only buttons */
+	if (but && icon_only) {
+		BLI_assert(but->str[0] == '\0');
+	}
+
 }
 
 void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index cdaecc6..8ce2a29 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -435,8 +435,6 @@ static void template_ID(bContext *C, uiLayout *layout, TemplateID *template, Str
 		but = uiDefBlockButN(block, id_search_menu, MEM_dupallocN(template), "", 0, 0, UI_UNIT_X * 1.6, UI_UNIT_Y,
 		                     TIP_(template_id_browse_tip(type)));
 
-		uiButSetDrawFlag(but, UI_BUT_DRAW_ENUM_ARROWS);
-
 		if (type) {
 			but->icon = RNA_struct_ui_icon(type);
 			/* default dragging of icon for id browse buttons */
diff --git a/source/blender/editors/interface/interface_utils.c b/source/blender/editors/interface/interface_utils.c
index fc87801..261c666 100644
--- a/source/blender/editors/interface/interface_utils.c
+++ b/source/blender/editors/interface/interface_utils.c
@@ -99,7 +99,7 @@ uiBut *uiDefAutoButR(uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, int ind
 			else if (icon)
 				but = uiDefIconTextButR_prop(block, MENU, 0, icon, NULL, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL);
 			else
-				but = uiDefButR_prop(block, MENU, 0, NULL, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL);
+				but = uiDefButR_prop(block, MENU, 0, name, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL);
 			break;
 		case PROP_STRING:
 			if (icon && name && name[0] == '\0')
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index b4aeef7..91ee357 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -3432,20 +3432,26 @@ void ui_draw_but(const bContext *C, ARegion *ar, uiStyle *style, uiBut *but, rct
 				
 			case MENU:
 			case BLOCK:
-				/* new node-link button, not active yet XXX */
-				if (but->flag & UI_BUT_NODE_LINK)
+				if (but->flag & UI_BUT_NODE_LINK) {
+					/* new node-link button, not active yet XXX */
 					wt = widget_type(UI_WTYPE_MENU_NODE_LINK);
-
-				/* no text, with icon */
-				else if (!but->str[0] && but->icon) {
-					if (but->drawflag & UI_BUT_DRAW_ENUM_ARROWS)
-						wt = widget_type(UI_WTYPE_MENU_RADIO);  /* with arrows */
-					else
-						wt = widget_type(UI_WTYPE_MENU_ICON_RADIO);  /* no arrows */
 				}
-				/* with menu arrows */
-				else
-					wt = widget_type(UI_WTYPE_MENU_RADIO);
+				else {
+					/* with menu arrows */
+
+					/* we could use a flag for this, but for now just check size,
+					 * add updown arrows if there is room. */
+					if ((!but->str[0] && but->icon && (BLI_rcti_size_x(rect) < BLI_rcti_size_y(rect) + 2)) ||
+					    /* disable for brushes also */
+					    (but->flag & UI_ICON_PREVIEW))
+					{
+						/* no arrows */
+						wt = widget_type(UI_WTYPE_MENU_ICON_RADIO);
+					}
+					else {
+						wt = widget_type(UI_WTYPE_MENU_RADIO);
+					}
+				}
 				break;
 				
 			case PULLDOWN:
diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c
index 111e2f9..7037804 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -1535,7 +1535,7 @@ int ED_area_header_switchbutton(const bContext *C, uiBlock *block, int yco)
 
 	RNA_pointer_create(&(scr->id), &RNA_Area, sa, &areaptr);
 
-	uiDefButR(block, MENU, 0, NULL, xco, yco, 1.5 * U.widget_unit, U.widget_unit,
+	uiDefButR(block, MENU, 0, "", xco, yco, 1.5 * U.widget_unit, U.widget_unit,
 	          &areaptr, "type", 0, 0.0f, 0.0f, 0.0f, 0.0f, "");
 
 	return xco + 1.7 * U.widget_unit;




More information about the Bf-blender-cvs mailing list