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:
@@ -1142,11 +1142,15 @@ static int ui_textedit_delete_selection(uiBut *but, uiHandleButtonData *data)
|
||||
static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, short x)
|
||||
{
|
||||
uiStyle *style= U.uistyles.first; // XXX pass on as arg
|
||||
uiFontStyle *fstyle = &style->widget;
|
||||
int startx= but->x1;
|
||||
char *origstr;
|
||||
|
||||
uiStyleFontSet(&style->widget);
|
||||
uiStyleFontSet(fstyle);
|
||||
|
||||
if (fstyle->kerning==1) /* for BLF_width */
|
||||
BLF_enable(BLF_KERNING_DEFAULT);
|
||||
|
||||
origstr= MEM_callocN(sizeof(char)*data->maxlen, "ui_textedit origstr");
|
||||
|
||||
BLI_strncpy(origstr, but->drawstr, data->maxlen);
|
||||
@@ -1187,6 +1191,9 @@ static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, sho
|
||||
if(but->pos<0) but->pos= 0;
|
||||
}
|
||||
|
||||
if (fstyle->kerning == 1)
|
||||
BLF_disable(BLF_KERNING_DEFAULT);
|
||||
|
||||
MEM_freeN(origstr);
|
||||
}
|
||||
|
||||
@@ -1518,6 +1525,8 @@ static void ui_textedit_begin(bContext *C, uiBut *but, uiHandleButtonData *data)
|
||||
}
|
||||
|
||||
ui_check_but(but);
|
||||
|
||||
WM_cursor_modal(CTX_wm_window(C), BC_TEXTEDITCURSOR);
|
||||
}
|
||||
|
||||
static void ui_textedit_end(bContext *C, uiBut *but, uiHandleButtonData *data)
|
||||
@@ -1534,6 +1543,8 @@ static void ui_textedit_end(bContext *C, uiBut *but, uiHandleButtonData *data)
|
||||
but->editstr= NULL;
|
||||
but->pos= -1;
|
||||
}
|
||||
|
||||
WM_cursor_restore(CTX_wm_window(C));
|
||||
}
|
||||
|
||||
static void ui_textedit_next_but(uiBlock *block, uiBut *actbut, uiHandleButtonData *data)
|
||||
|
||||
@@ -237,9 +237,19 @@ void uiStyleFontDrawRotated(uiFontStyle *fs, rcti *rect, char *str)
|
||||
int UI_GetStringWidth(char *str)
|
||||
{
|
||||
uiStyle *style= U.uistyles.first;
|
||||
uiFontStyle *fstyle= &style->widget;
|
||||
int width;
|
||||
|
||||
uiStyleFontSet(&style->widget);
|
||||
return BLF_width(str);
|
||||
if (fstyle->kerning==1) /* for BLF_width */
|
||||
BLF_enable(BLF_KERNING_DEFAULT);
|
||||
|
||||
uiStyleFontSet(fstyle);
|
||||
width= BLF_width(str);
|
||||
|
||||
if (fstyle->kerning==1)
|
||||
BLF_disable(BLF_KERNING_DEFAULT);
|
||||
|
||||
return width;
|
||||
}
|
||||
|
||||
/* temporarily, does widget font */
|
||||
|
||||
@@ -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