From de1f84783be75261d5a1e17859f3c902d0b5ba1b Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Fri, 28 Sep 2012 11:28:23 +0000 Subject: Fix #32673: long strings were wrongly clipped when modifying It was a regression in svn revision 50676 -- button's string width should be calculated taking button offset into account. However, check for button offset should check string width without offset taken into account. --- .../blender/editors/interface/interface_widgets.c | 64 +++++++++++----------- 1 file changed, 32 insertions(+), 32 deletions(-) (limited to 'source/blender/editors/interface/interface_widgets.c') diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index f3539af821e..87a7d1957c5 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -1014,42 +1014,42 @@ static void ui_text_clip_cursor(uiFontStyle *fstyle, uiBut *but, rcti *rect) if (fstyle->kerning == 1) /* for BLF_width */ BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT); - if ((but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr)) <= okwidth) { + /* define ofs dynamically */ + if (but->ofs > but->pos) + but->ofs = but->pos; + + if (BLF_width(fstyle->uifont_id, but->drawstr) <= okwidth) but->ofs = 0; - } - else { - /* define ofs dynamically */ - if (but->ofs > but->pos) - but->ofs = but->pos; - - while (but->strwidth > okwidth) { - float width; - char buf[UI_MAX_DRAW_STR]; - - /* copy draw string */ - BLI_strncpy_utf8(buf, but->drawstr, sizeof(buf)); - /* string position of cursor */ - buf[but->pos] = 0; - width = BLF_width(fstyle->uifont_id, buf + but->ofs); - - /* if cursor is at 20 pixels of right side button we clip left */ - if (width > okwidth - 20) { - ui_text_clip_give_next_off(but); - } - else { - int len, bytes; - /* shift string to the left */ - if (width < 20 && but->ofs > 0) - ui_text_clip_give_prev_off(but); - len = strlen(but->drawstr); - bytes = BLI_str_utf8_size(BLI_str_find_prev_char_utf8(but->drawstr, but->drawstr + len)); - but->drawstr[len - bytes] = 0; - } - but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs); + but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs); - if (but->strwidth < 10) break; + while (but->strwidth > okwidth) { + float width; + char buf[UI_MAX_DRAW_STR]; + + /* copy draw string */ + BLI_strncpy_utf8(buf, but->drawstr, sizeof(buf)); + /* string position of cursor */ + buf[but->pos] = 0; + width = BLF_width(fstyle->uifont_id, buf + but->ofs); + + /* if cursor is at 20 pixels of right side button we clip left */ + if (width > okwidth - 20) { + ui_text_clip_give_next_off(but); + } + else { + int len, bytes; + /* shift string to the left */ + if (width < 20 && but->ofs > 0) + ui_text_clip_give_prev_off(but); + len = strlen(but->drawstr); + bytes = BLI_str_utf8_size(BLI_str_find_prev_char_utf8(but->drawstr, but->drawstr + len)); + but->drawstr[len - bytes] = 0; } + + but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs); + + if (but->strwidth < 10) break; } if (fstyle->kerning == 1) { -- cgit v1.2.3