Fix [#21694] text input box last character not editable
Font kerning needs to be set in order to get accurate results out of BLF_width(). Would be nice if this was more automatic, I've added it to a few other places that seem like they need this though it's a little unclear due to the globals etc. Also some other minor tweaks when editing text fields.
This commit is contained in:
@@ -811,6 +811,9 @@ static void ui_text_leftclip(uiFontStyle *fstyle, uiBut *but, rcti *rect)
|
||||
|
||||
/* need to set this first */
|
||||
uiStyleFontSet(fstyle);
|
||||
|
||||
if (fstyle->kerning==1) /* for BLF_width */
|
||||
BLF_enable(BLF_KERNING_DEFAULT);
|
||||
|
||||
but->strwidth= BLF_width(but->drawstr);
|
||||
but->ofs= 0;
|
||||
@@ -837,6 +840,9 @@ static void ui_text_leftclip(uiFontStyle *fstyle, uiBut *but, rcti *rect)
|
||||
|
||||
if(but->strwidth < 10) break;
|
||||
}
|
||||
|
||||
if (fstyle->kerning==1)
|
||||
BLF_disable(BLF_KERNING_DEFAULT);
|
||||
}
|
||||
|
||||
static void ui_text_label_rightclip(uiFontStyle *fstyle, uiBut *but, rcti *rect)
|
||||
@@ -849,6 +855,9 @@ static void ui_text_label_rightclip(uiFontStyle *fstyle, uiBut *but, rcti *rect)
|
||||
/* need to set this first */
|
||||
uiStyleFontSet(fstyle);
|
||||
|
||||
if (fstyle->kerning==1) /* for BLF_width */
|
||||
BLF_enable(BLF_KERNING_DEFAULT);
|
||||
|
||||
but->strwidth= BLF_width(but->drawstr);
|
||||
but->ofs= 0;
|
||||
|
||||
@@ -890,6 +899,8 @@ static void ui_text_label_rightclip(uiFontStyle *fstyle, uiBut *but, rcti *rect)
|
||||
if(but->strwidth < 10) break;
|
||||
}
|
||||
|
||||
if (fstyle->kerning==1)
|
||||
BLF_disable(BLF_KERNING_DEFAULT);
|
||||
}
|
||||
|
||||
|
||||
@@ -904,7 +915,10 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b
|
||||
fstyle->align= UI_STYLE_TEXT_LEFT;
|
||||
else
|
||||
fstyle->align= UI_STYLE_TEXT_CENTER;
|
||||
|
||||
|
||||
if (fstyle->kerning==1) /* for BLF_width */
|
||||
BLF_enable(BLF_KERNING_DEFAULT);
|
||||
|
||||
/* text button selection and cursor */
|
||||
if(but->editstr && but->pos != -1) {
|
||||
short t=0, pos=0, ch;
|
||||
@@ -945,16 +959,20 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b
|
||||
ch= but->drawstr[pos];
|
||||
but->drawstr[pos]= 0;
|
||||
|
||||
t= BLF_width(but->drawstr+but->ofs);
|
||||
t= BLF_width(but->drawstr+but->ofs) / but->aspect;
|
||||
|
||||
but->drawstr[pos]= ch;
|
||||
}
|
||||
|
||||
glColor3ub(255,0,0);
|
||||
glColor3f(0.20, 0.6, 0.9);
|
||||
glRects(rect->xmin+t, rect->ymin+2, rect->xmin+t+2, rect->ymax-2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (fstyle->kerning == 1)
|
||||
BLF_disable(BLF_KERNING_DEFAULT);
|
||||
|
||||
// ui_rasterpos_safe(x, y, but->aspect);
|
||||
// if(but->type==IDPOIN) transopts= 0; // no translation, of course!
|
||||
// else transopts= ui_translate_buttons();
|
||||
|
||||
Reference in New Issue
Block a user