From d62bbf40793234a3cfc3762720f0964f85206169 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Wed, 10 Jun 2020 15:08:23 +0200 Subject: UI: Show library names grayed out and right-aligned in menus Should separate the data-block name better from the library name and improve readability. --- source/blender/blenkernel/BKE_lib_id.h | 6 ++++-- source/blender/blenkernel/intern/lib_id.c | 18 ++++++++++++------ .../editors/interface/interface_region_search.c | 5 +++-- source/blender/editors/interface/interface_templates.c | 4 ++-- source/blender/editors/interface/interface_utils.c | 4 ++-- source/blender/makesrna/intern/rna_ID.c | 4 ++-- 6 files changed, 25 insertions(+), 16 deletions(-) (limited to 'source') diff --git a/source/blender/blenkernel/BKE_lib_id.h b/source/blender/blenkernel/BKE_lib_id.h index 18ca5629d07..7f5a6e3e36a 100644 --- a/source/blender/blenkernel/BKE_lib_id.h +++ b/source/blender/blenkernel/BKE_lib_id.h @@ -250,8 +250,10 @@ void BKE_main_id_repair_duplicate_names_listbase(struct ListBase *lb); #define MAX_ID_FULL_NAME (64 + 64 + 3 + 1) /* 64 is MAX_ID_NAME - 2 */ #define MAX_ID_FULL_NAME_UI (MAX_ID_FULL_NAME + 3) /* Adds 'keycode' two letters at beginning. */ -void BKE_id_full_name_get(char name[MAX_ID_FULL_NAME], const struct ID *id); -void BKE_id_full_name_ui_prefix_get(char name[MAX_ID_FULL_NAME_UI], const struct ID *id); +void BKE_id_full_name_get(char name[MAX_ID_FULL_NAME], const struct ID *id, char separator_str); +void BKE_id_full_name_ui_prefix_get(char name[MAX_ID_FULL_NAME_UI], + const struct ID *id, + char separator_char); char *BKE_id_to_unique_string_key(const struct ID *id); diff --git a/source/blender/blenkernel/intern/lib_id.c b/source/blender/blenkernel/intern/lib_id.c index 19462c62496..734fe9ad9ae 100644 --- a/source/blender/blenkernel/intern/lib_id.c +++ b/source/blender/blenkernel/intern/lib_id.c @@ -2068,9 +2068,11 @@ void BKE_libblock_rename(Main *bmain, ID *id, const char *name) * \note Result is unique to a given ID type in a given Main database. * * \param name: An allocated string of minimal length #MAX_ID_FULL_NAME, - * will be filled with generated string. + * will be filled with generated string. + * \param separator_char: Character to use for separating name and library name. Can be 0 to use + * default (' '). */ -void BKE_id_full_name_get(char name[MAX_ID_FULL_NAME], const ID *id) +void BKE_id_full_name_get(char name[MAX_ID_FULL_NAME], const ID *id, char separator_char) { strcpy(name, id->name + 2); @@ -2078,7 +2080,7 @@ void BKE_id_full_name_get(char name[MAX_ID_FULL_NAME], const ID *id) const size_t idname_len = strlen(id->name + 2); const size_t libname_len = strlen(id->lib->id.name + 2); - name[idname_len] = ' '; + name[idname_len] = separator_char ? separator_char : ' '; name[idname_len + 1] = '['; strcpy(name + idname_len + 2, id->lib->id.name + 2); name[idname_len + 2 + libname_len] = ']'; @@ -2094,15 +2096,19 @@ void BKE_id_full_name_get(char name[MAX_ID_FULL_NAME], const ID *id) * \note Result is unique to a given ID type in a given Main database. * * \param name: An allocated string of minimal length #MAX_ID_FULL_NAME_UI, - * will be filled with generated string. + * will be filled with generated string. + * \param separator_char: Character to use for separating name and library name. Can be 0 to use + * default (' '). */ -void BKE_id_full_name_ui_prefix_get(char name[MAX_ID_FULL_NAME_UI], const ID *id) +void BKE_id_full_name_ui_prefix_get(char name[MAX_ID_FULL_NAME_UI], + const ID *id, + char separator_char) { name[0] = id->lib ? (ID_MISSING(id) ? 'M' : 'L') : ID_IS_OVERRIDE_LIBRARY(id) ? 'O' : ' '; name[1] = (id->flag & LIB_FAKEUSER) ? 'F' : ((id->us == 0) ? '0' : ' '); name[2] = ' '; - BKE_id_full_name_get(name + 3, id); + BKE_id_full_name_get(name + 3, id, separator_char); } /** diff --git a/source/blender/editors/interface/interface_region_search.c b/source/blender/editors/interface/interface_region_search.c index 34bbb644ef7..68be08ef4f8 100644 --- a/source/blender/editors/interface/interface_region_search.c +++ b/source/blender/editors/interface/interface_region_search.c @@ -555,6 +555,7 @@ static void ui_searchbox_region_draw_cb(const bContext *C, ARegion *region) char *name = data->items.names[a]; int icon = data->items.icons[a]; char *name_sep_test = NULL; + const bool use_sep_char = data->use_sep || (state & UI_BUT_HAS_SEP_CHAR); ui_searchbox_butrect(&rect, data, a); @@ -563,7 +564,7 @@ static void ui_searchbox_region_draw_cb(const bContext *C, ARegion *region) !(name_sep_test = strstr(data->items.names[a], data->sep_string))) { /* Simple menu item. */ - ui_draw_menu_item(&data->fstyle, &rect, name, icon, state, data->use_sep, NULL); + ui_draw_menu_item(&data->fstyle, &rect, name, icon, state, use_sep_char, NULL); } else { /* Split menu item, faded text before the separator. */ @@ -590,7 +591,7 @@ static void ui_searchbox_region_draw_cb(const bContext *C, ARegion *region) /* The previous menu item draws the active selection. */ ui_draw_menu_item( - &data->fstyle, &rect, name_sep, icon, state & ~UI_ACTIVE, data->use_sep, NULL); + &data->fstyle, &rect, name_sep, icon, state & ~UI_ACTIVE, use_sep_char, NULL); } } /* indicate more */ diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 6295f51f01e..7d856a51720 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -361,11 +361,11 @@ static bool id_search_add(const bContext *C, * followed by ID_NAME-2 characters from id->name */ char name_ui[MAX_ID_FULL_NAME_UI]; - BKE_id_full_name_ui_prefix_get(name_ui, id); + BKE_id_full_name_ui_prefix_get(name_ui, id, UI_SEP_CHAR); int iconid = ui_id_icon_get(C, id, template_ui->preview); - if (!UI_search_item_add(items, name_ui, id, iconid, 0)) { + if (!UI_search_item_add(items, name_ui, id, iconid, UI_BUT_HAS_SEP_CHAR)) { return false; } } diff --git a/source/blender/editors/interface/interface_utils.c b/source/blender/editors/interface/interface_utils.c index 4013e962ce5..15db947bff6 100644 --- a/source/blender/editors/interface/interface_utils.c +++ b/source/blender/editors/interface/interface_utils.c @@ -441,7 +441,7 @@ void ui_rna_collection_search_update_fn(const struct bContext *C, name = RNA_struct_name_get_alloc(&itemptr, name_buf, sizeof(name_buf), NULL); } else { - BKE_id_full_name_ui_prefix_get(name_buf, itemptr.data); + BKE_id_full_name_ui_prefix_get(name_buf, itemptr.data, UI_SEP_CHAR); BLI_STATIC_ASSERT(sizeof(name_buf) >= MAX_ID_FULL_NAME_UI, "Name string buffer should be big enough to hold full UI ID name"); name = name_buf; @@ -473,7 +473,7 @@ void ui_rna_collection_search_update_fn(const struct bContext *C, /* add search items from temporary list */ for (cis = items_list->first; cis; cis = cis->next) { - if (!UI_search_item_add(items, cis->name, cis->data, cis->iconid, 0)) { + if (!UI_search_item_add(items, cis->name, cis->data, cis->iconid, UI_BUT_HAS_SEP_CHAR)) { break; } } diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c index 56be654639f..e0d862ee92a 100644 --- a/source/blender/makesrna/intern/rna_ID.c +++ b/source/blender/makesrna/intern/rna_ID.c @@ -184,14 +184,14 @@ static int rna_ID_name_editable(PointerRNA *ptr, const char **UNUSED(r_info)) void rna_ID_name_full_get(PointerRNA *ptr, char *value) { ID *id = (ID *)ptr->data; - BKE_id_full_name_get(value, id); + BKE_id_full_name_get(value, id, 0); } int rna_ID_name_full_length(PointerRNA *ptr) { ID *id = (ID *)ptr->data; char name[MAX_ID_FULL_NAME]; - BKE_id_full_name_get(name, id); + BKE_id_full_name_get(name, id, 0); return strlen(name); } -- cgit v1.2.3