Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTon Roosendaal <ton@blender.org>2011-01-20 21:34:48 +0300
committerTon Roosendaal <ton@blender.org>2011-01-20 21:34:48 +0300
commitf407f38204f9d41e437a06dd4d280649eadc350e (patch)
tree58b618fdc7c1f7b8c239e11d2e338df1de0b281b /source/blender/editors/interface
parent2e8c93b663549d606425b3f20d87989c3439a381 (diff)
Bugfix #25656
Fixed one of oldest annoyances in Blender: the text input button! It always behaved stupid when you had clipped text in a button. Now while using arrows the cursor will move as expected, and only internally shift contents when cursor reaches edge of button.
Diffstat (limited to 'source/blender/editors/interface')
-rw-r--r--source/blender/editors/interface/interface.c1
-rw-r--r--source/blender/editors/interface/interface_widgets.c48
2 files changed, 32 insertions, 17 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 7a83ff0156a..43919617047 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -523,6 +523,7 @@ static int ui_but_update_from_old_block(const bContext *C, uiBlock *block, uiBut
#endif
but->active= oldbut->active;
but->pos= oldbut->pos;
+ but->ofs= oldbut->ofs;
but->editstr= oldbut->editstr;
but->editval= oldbut->editval;
but->editvec= oldbut->editvec;
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index 09d388c3052..4224b0b080f 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -871,28 +871,42 @@ static void ui_text_leftclip(uiFontStyle *fstyle, uiBut *but, rcti *rect)
if (fstyle->kerning==1) /* for BLF_width */
BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
- but->strwidth= BLF_width(fstyle->uifont_id, but->drawstr);
- but->ofs= 0;
+ /* if text editing we define ofs dynamically */
+ if(but->editstr && but->pos >= 0) {
+ if(but->ofs > but->pos)
+ but->ofs= but->pos;
+ }
+ else but->ofs= 0;
- while(but->strwidth > okwidth ) {
-
- but->ofs++;
- but->strwidth= BLF_width(fstyle->uifont_id, but->drawstr+but->ofs);
+ but->strwidth= BLF_width(fstyle->uifont_id, but->drawstr + but->ofs);
+
+ while(but->strwidth > okwidth) {
- /* textbut exception */
- if(but->editstr && but->pos != -1) {
- int pos= but->pos+1;
+ /* textbut exception, clip right when... */
+ if(but->editstr && but->pos >= 0) {
+ float width;
+ char buf[256];
- if(pos-1 < but->ofs) {
- pos= but->ofs-pos+1;
- but->ofs -= pos;
- if(but->ofs<0) {
- but->ofs= 0;
- pos--;
- }
- but->drawstr[ strlen(but->drawstr)-pos ]= 0;
+ /* copy draw string */
+ BLI_strncpy(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)
+ but->ofs++;
+ else {
+ /* shift string to the left */
+ if(width < 20 && but->ofs > 0)
+ but->ofs--;
+ but->drawstr[ strlen(but->drawstr)-1 ]= 0;
}
}
+ else
+ but->ofs++;
+
+ but->strwidth= BLF_width(fstyle->uifont_id, but->drawstr+but->ofs);
if(but->strwidth < 10) break;
}