diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-05-03 03:18:00 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-05-03 03:18:00 +0400 |
commit | 0111f3505f0263a35a4196535db26365651d30e7 (patch) | |
tree | 5863bf815dbf7e77d194b85a1dbb61ebf1962850 /source/blender | |
parent | 8d16869d833ea2a2bd548c8f7b767dae582c78f2 (diff) |
UI: more changes for large textfields
- no longer set 'but->drawstr' when editing buttons.
- clip text and set cursor based on the 'editstr'.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/interface/interface.c | 2 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_handlers.c | 2 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_widgets.c | 63 |
3 files changed, 35 insertions, 32 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 3da6b5d8e23..19d4e32152f 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -2697,7 +2697,7 @@ void ui_check_but(uiBut *but) /* if we are doing text editing, this will override the drawstr */ if (but->editstr) - BLI_strncpy(but->drawstr, but->editstr, UI_MAX_DRAW_STR); + but->drawstr[0] = '\0'; /* text clipping moved to widget drawing code itself */ } diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 642ac0c1f97..2da04ed56f3 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -2004,7 +2004,7 @@ static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, con origstr = MEM_mallocN(sizeof(char) * data->maxlen, "ui_textedit origstr"); - BLI_strncpy(origstr, but->drawstr, data->maxlen); + BLI_strncpy(origstr, but->editstr, data->maxlen); if (ELEM3(but->type, TEX, SEARCH_MENU, SEARCH_MENU_UNLINK)) { if (but->flag & UI_HAS_ICON) { diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index c207812a633..b25aac785a7 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -920,18 +920,18 @@ static void widget_draw_icon(const uiBut *but, BIFIconID icon, float alpha, cons glDisable(GL_BLEND); } -static void ui_text_clip_give_prev_off(uiBut *but) +static void ui_text_clip_give_prev_off(uiBut *but, const char *str) { - const char *prev_utf8 = BLI_str_find_prev_char_utf8(but->drawstr, but->drawstr + but->ofs); - int bytes = but->drawstr + but->ofs - prev_utf8; + const char *prev_utf8 = BLI_str_find_prev_char_utf8(str, str + but->ofs); + int bytes = str + but->ofs - prev_utf8; but->ofs -= bytes; } -static void ui_text_clip_give_next_off(uiBut *but) +static void ui_text_clip_give_next_off(uiBut *but, const char *str) { - const char *next_utf8 = BLI_str_find_next_char_utf8(but->drawstr + but->ofs, NULL); - int bytes = next_utf8 - (but->drawstr + but->ofs); + const char *next_utf8 = BLI_str_find_next_char_utf8(str + but->ofs, NULL); + int bytes = next_utf8 - (str + but->ofs); but->ofs += bytes; } @@ -1091,36 +1091,39 @@ static void ui_text_clip_cursor(uiFontStyle *fstyle, uiBut *but, const rcti *rec if (but->ofs > but->pos) but->ofs = but->pos; - if (BLF_width(fstyle->uifont_id, but->drawstr, sizeof(but->drawstr)) <= okwidth) + if (BLF_width(fstyle->uifont_id, but->editstr, INT_MAX) <= okwidth) but->ofs = 0; - but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs, sizeof(but->drawstr) - but->ofs); + but->strwidth = BLF_width(fstyle->uifont_id, but->editstr + but->ofs, INT_MAX); - while (but->strwidth > okwidth) { - float width; + if (but->strwidth > okwidth) { + int len = strlen(but->editstr); - /* string position of cursor */ - width = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs, but->pos - but->ofs); + while (but->strwidth > okwidth) { + float width; - /* 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)); - if (bytes < 0) - bytes = 1; - but->drawstr[len - bytes] = 0; - } + /* string position of cursor */ + width = BLF_width(fstyle->uifont_id, but->editstr + but->ofs, (but->pos - 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, but->editstr); + } + else { + int bytes; + /* shift string to the left */ + if (width < 20 && but->ofs > 0) + ui_text_clip_give_prev_off(but, but->editstr); + bytes = BLI_str_utf8_size(BLI_str_find_prev_char_utf8(but->editstr, but->editstr + len)); + if (bytes == -1) + bytes = 1; + len -= bytes; + } - but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs, sizeof(but->drawstr) - but->ofs); + but->strwidth = BLF_width(fstyle->uifont_id, but->editstr + but->ofs, len - but->ofs); - if (but->strwidth < 10) break; + if (but->strwidth < 10) break; + } } if (fstyle->kerning == 1) { @@ -1182,7 +1185,7 @@ static void ui_text_clip_right_label(uiFontStyle *fstyle, uiBut *but, const rcti /* after the leading text is gone, chop off the : and following space, with ofs */ while ((but->strwidth > okwidth) && (but->ofs < 2)) { - ui_text_clip_give_next_off(but); + ui_text_clip_give_next_off(but, but->drawstr); but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs, sizeof(but->drawstr) - but->ofs); if (but->strwidth < 10) break; } |