UI: add function to access the buttons text without it's shortcut

This commit is contained in:
Campbell Barton 2021-08-19 12:49:10 +10:00
parent 7a4ef5256a
commit 594790d8a5
3 changed files with 10 additions and 7 deletions

View File

@ -373,13 +373,7 @@ static void ui_but_user_menu_add(bContext *C, uiBut *but, bUserMenu *um)
BLI_assert(ui_but_is_user_menu_compatible(C, but));
char drawstr[sizeof(but->drawstr)];
STRNCPY(drawstr, but->drawstr);
if (but->flag & UI_BUT_HAS_SEP_CHAR) {
char *sep = strrchr(drawstr, UI_SEP_CHAR);
if (sep) {
*sep = '\0';
}
}
ui_but_drawstr_without_sep_char(but, drawstr, sizeof(drawstr));
MenuType *mt = NULL;
if (but->optype) {

View File

@ -1177,6 +1177,8 @@ uiBut *ui_list_find_mouse_over_ex(const struct ARegion *region,
bool ui_but_contains_password(const uiBut *but) ATTR_WARN_UNUSED_RESULT;
size_t ui_but_drawstr_without_sep_char(const uiBut *but, char *str, size_t str_maxlen)
ATTR_NONNULL(1, 2);
size_t ui_but_drawstr_len_without_sep_char(const uiBut *but);
size_t ui_but_tip_len_only_first_line(const uiBut *but);

View File

@ -23,6 +23,7 @@
#include "BLI_listbase.h"
#include "BLI_math.h"
#include "BLI_rect.h"
#include "BLI_string.h"
#include "BLI_utildefines.h"
#include "DNA_screen_types.h"
@ -553,6 +554,12 @@ size_t ui_but_drawstr_len_without_sep_char(const uiBut *but)
return strlen(but->drawstr);
}
size_t ui_but_drawstr_without_sep_char(const uiBut *but, char *str, size_t str_maxlen)
{
size_t str_len_clip = ui_but_drawstr_len_without_sep_char(but);
return BLI_strncpy_rlen(str, but->drawstr, min_zz(str_len_clip + 1, str_maxlen));
}
size_t ui_but_tip_len_only_first_line(const uiBut *but)
{
if (but->tip == NULL) {