Bug fix #33887
Ancient issue: on much zoomed in UIs, text selecting or cursor placement in Text-input buttons was off.
This commit is contained in:
@@ -1438,7 +1438,8 @@ static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, sho
|
|||||||
if (but->type == NUM || but->type == NUMSLI)
|
if (but->type == NUM || but->type == NUMSLI)
|
||||||
startx += (int)(0.5f * (BLI_rctf_size_y(&but->rect)));
|
startx += (int)(0.5f * (BLI_rctf_size_y(&but->rect)));
|
||||||
else if (ELEM3(but->type, TEX, SEARCH_MENU, SEARCH_MENU_UNLINK)) {
|
else if (ELEM3(but->type, TEX, SEARCH_MENU, SEARCH_MENU_UNLINK)) {
|
||||||
startx += 5;
|
/* text draws with offset 0.40, but this extra .05 makes clicks inbetween characters feel nicer */
|
||||||
|
startx += (0.45f * U.widget_unit);
|
||||||
if (but->flag & UI_HAS_ICON)
|
if (but->flag & UI_HAS_ICON)
|
||||||
startx += UI_DPI_ICON_SIZE;
|
startx += UI_DPI_ICON_SIZE;
|
||||||
}
|
}
|
||||||
@@ -1463,21 +1464,18 @@ static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, sho
|
|||||||
but->ofs = i;
|
but->ofs = i;
|
||||||
but->pos = but->ofs;
|
but->pos = but->ofs;
|
||||||
}
|
}
|
||||||
/* mouse inside the widget */
|
/* mouse inside the widget, mouse coords mapped in widget space */
|
||||||
else if (x >= startx) {
|
else if (x >= startx) {
|
||||||
int pos_i;
|
int pos_i;
|
||||||
|
|
||||||
/* keep track of previous distance from the cursor to the char */
|
/* keep track of previous distance from the cursor to the char */
|
||||||
float cdist, cdist_prev = 0.0f;
|
float cdist, cdist_prev = 0.0f;
|
||||||
short pos_prev;
|
short pos_prev;
|
||||||
|
|
||||||
const float aspect_sqrt = sqrtf(but->block->aspect);
|
|
||||||
|
|
||||||
but->pos = pos_prev = strlen(origstr) - but->ofs;
|
but->pos = pos_prev = strlen(origstr) - but->ofs;
|
||||||
|
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
/* XXX does not take zoom level into account */
|
cdist = startx + BLF_width(fstyle->uifont_id, origstr + but->ofs);
|
||||||
cdist = startx + aspect_sqrt * BLF_width(fstyle->uifont_id, origstr + but->ofs);
|
|
||||||
|
|
||||||
/* check if position is found */
|
/* check if position is found */
|
||||||
if (cdist < x) {
|
if (cdist < x) {
|
||||||
|
Reference in New Issue
Block a user