fix narrow text entry fields

widget_draw_text was calculating wrong display length when field is too narrow to show entire input string. Gawain assert caught this 11 function calls away!

Thanks to @ianwill for reporting.
This commit is contained in:
2016-10-18 17:34:29 -04:00
parent 117af2356a
commit e9268abf4a

View File

@@ -1461,37 +1461,40 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b
/* for underline drawing */ /* for underline drawing */
float font_xofs, font_yofs; float font_xofs, font_yofs;
UI_fontstyle_draw_ex(fstyle, rect, drawstr + but->ofs, int drawlen = (drawstr_left_len == INT_MAX) ? strlen(drawstr + but->ofs) : (drawstr_left_len - but->ofs);
drawstr_left_len - but->ofs, &font_xofs, &font_yofs);
if (but->menu_key != '\0') { if (drawlen > 0) {
char fixedbuf[128]; UI_fontstyle_draw_ex(fstyle, rect, drawstr + but->ofs, drawlen, &font_xofs, &font_yofs);
const char *str;
BLI_strncpy(fixedbuf, drawstr + but->ofs, min_ii(sizeof(fixedbuf), drawstr_left_len)); if (but->menu_key != '\0') {
char fixedbuf[128];
const char *str;
str = strchr(fixedbuf, but->menu_key - 32); /* upper case */ BLI_strncpy(fixedbuf, drawstr + but->ofs, min_ii(sizeof(fixedbuf), drawlen));
if (str == NULL)
str = strchr(fixedbuf, but->menu_key);
if (str) { str = strchr(fixedbuf, but->menu_key - 32); /* upper case */
int ul_index = -1; if (str == NULL)
float ul_advance; str = strchr(fixedbuf, but->menu_key);
ul_index = (int)(str - fixedbuf); if (str) {
int ul_index = -1;
float ul_advance;
if (fstyle->kerning == 1) { ul_index = (int)(str - fixedbuf);
BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
}
fixedbuf[ul_index] = '\0'; if (fstyle->kerning == 1) {
ul_advance = BLF_width(fstyle->uifont_id, fixedbuf, ul_index); BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
}
BLF_position(fstyle->uifont_id, rect->xmin + font_xofs + ul_advance, rect->ymin + font_yofs, 0.0f); fixedbuf[ul_index] = '\0';
BLF_draw(fstyle->uifont_id, "_", 2); ul_advance = BLF_width(fstyle->uifont_id, fixedbuf, ul_index);
if (fstyle->kerning == 1) { BLF_position(fstyle->uifont_id, rect->xmin + font_xofs + ul_advance, rect->ymin + font_yofs, 0.0f);
BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT); BLF_draw(fstyle->uifont_id, "_", 2);
if (fstyle->kerning == 1) {
BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
}
} }
} }
} }