Fix T38809: regression, text cursor offset in number buttons

Use the same offset for all edit-buttons now.
This commit is contained in:
2014-02-25 10:28:41 +11:00
parent e643d2c211
commit d0ec83c1a2
3 changed files with 36 additions and 15 deletions

View File

@@ -1795,6 +1795,21 @@ int ui_get_but_string_max_length(uiBut *but)
return UI_MAX_DRAW_STR;
}
uiBut *ui_get_but_drag_multi_edit(uiBut *but)
{
uiBut *but_iter;
BLI_assert(but->flag & UI_BUT_DRAG_MULTI);
for (but_iter = but->block->buttons.first; but_iter; but_iter = but_iter->next) {
if (but_iter->editstr) {
break;
}
}
return but_iter;
}
static double ui_get_but_scale_unit(uiBut *but, double value)
{
UnitSettings *unit = but->block->unit;

View File

@@ -394,6 +394,7 @@ extern void ui_convert_to_unit_alt_name(uiBut *but, char *str, size_t maxlen) AT
extern bool ui_set_but_string(struct bContext *C, uiBut *but, const char *str) ATTR_NONNULL();
extern bool ui_set_but_string_eval_num(struct bContext *C, uiBut *but, const char *str, double *value) ATTR_NONNULL();
extern int ui_get_but_string_max_length(uiBut *but);
extern uiBut *ui_get_but_drag_multi_edit(uiBut *but);
extern void ui_set_but_default(struct bContext *C, const bool all, const bool use_afterfunc);

View File

@@ -1190,7 +1190,6 @@ static void ui_text_clip_right_label(uiFontStyle *fstyle, uiBut *but, const rcti
BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
}
static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *but, rcti *rect)
{
int drawstr_left_len = UI_MAX_DRAW_STR;
@@ -1214,13 +1213,10 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b
/* Special case: when we're entering text for multiple buttons,
* don't draw the text for any of the multi-editing buttons */
if (UNLIKELY(but->flag & UI_BUT_DRAG_MULTI)) {
uiBut *but_iter;
for (but_iter = but->block->buttons.first; but_iter; but_iter = but_iter->next) {
if (but_iter->editstr) {
drawstr = but_iter->editstr;
fstyle->align = UI_STYLE_TEXT_LEFT;
break;
}
uiBut *but_edit = ui_get_but_drag_multi_edit(but);
if (but_edit) {
drawstr = but_edit->editstr;
fstyle->align = UI_STYLE_TEXT_LEFT;
}
}
@@ -2417,9 +2413,11 @@ static void widget_numbut_draw(uiWidgetColors *wcol, rcti *rect, int state, int
widgetbase_draw(&wtb, wcol);
/* text space */
rect->xmin += textofs;
rect->xmax -= textofs;
if (!(state & UI_TEXTINPUT)) {
/* text space */
rect->xmin += textofs;
rect->xmax -= textofs;
}
}
static void widget_numbut(uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign)
@@ -2735,8 +2733,10 @@ static void widget_numslider(uiBut *but, uiWidgetColors *wcol, rcti *rect, int s
widgetbase_draw(&wtb, wcol);
/* add space at either side of the button so text aligns with numbuttons (which have arrow icons) */
rect->xmax -= toffs;
rect->xmin += toffs;
if (!(state & UI_TEXTINPUT)) {
rect->xmax -= toffs;
rect->xmin += toffs;
}
}
@@ -3539,8 +3539,13 @@ void ui_draw_but(const bContext *C, ARegion *ar, uiStyle *style, uiBut *but, rct
roundboxalign = widget_roundbox_set(but, rect);
state = but->flag;
if (but->editstr) state |= UI_TEXTINPUT;
if ((but->editstr) ||
(UNLIKELY(but->flag & UI_BUT_DRAG_MULTI) && ui_get_but_drag_multi_edit(but)))
{
state |= UI_TEXTINPUT;
}
if (state & (UI_BUT_DISABLED | UI_BUT_INACTIVE))
if (but->dt != UI_EMBOSSP)
disabled = true;