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:
authorCampbell Barton <ideasman42@gmail.com>2014-03-12 12:24:47 +0400
committerCampbell Barton <ideasman42@gmail.com>2014-03-12 15:56:10 +0400
commite5e0888a8f024bdc2d3196055762050195bec7a9 (patch)
tree24d5ca5a43fa3e5de2b669c6cc183f72c4d40cd5 /source/blender/editors/interface
parenta7faad9aa11c5a8cab4497b7eb8345ce05a09814 (diff)
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.
Diffstat (limited to 'source/blender/editors/interface')
-rw-r--r--source/blender/editors/interface/interface.c59
-rw-r--r--source/blender/editors/interface/interface_layout.c18
-rw-r--r--source/blender/editors/interface/interface_templates.c2
-rw-r--r--source/blender/editors/interface/interface_utils.c2
-rw-r--r--source/blender/editors/interface/interface_widgets.c30
5 files changed, 66 insertions, 45 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 765a73b7a3b..b8e00022a61 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 b5255eb0516..0ba47eb534c 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 cdaecc62f0f..8ce2a290446 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 fc87801d6a3..261c666c33f 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 b4aeef7b01b..91ee357ea4f 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: