use define for text offset & seletion.

and no need to calloc memory for string selection.
This commit is contained in:
Campbell Barton
2013-01-17 18:59:19 +00:00
parent a896366ca9
commit 2b80a7d5da
3 changed files with 15 additions and 11 deletions

View File

@@ -1416,11 +1416,11 @@ static int ui_textedit_delete_selection(uiBut *but, uiHandleButtonData *data)
} }
/* note, but->block->aspect is used here, when drawing button style is getting scaled too */ /* note, but->block->aspect is used here, when drawing button style is getting scaled too */
static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, short x) static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, const float x)
{ {
uiStyle *style = UI_GetStyle(); // XXX pass on as arg uiStyle *style = UI_GetStyle(); // XXX pass on as arg
uiFontStyle *fstyle = &style->widget; uiFontStyle *fstyle = &style->widget;
int startx = but->rect.xmin; float startx = but->rect.xmin;
char *origstr, password_str[UI_MAX_DRAW_STR]; char *origstr, password_str[UI_MAX_DRAW_STR];
uiStyleFontSet(fstyle); uiStyleFontSet(fstyle);
@@ -1430,19 +1430,21 @@ static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, sho
ui_button_text_password_hide(password_str, but, FALSE); ui_button_text_password_hide(password_str, but, FALSE);
origstr = MEM_callocN(sizeof(char) * data->maxlen, "ui_textedit origstr"); origstr = MEM_mallocN(sizeof(char) * data->maxlen, "ui_textedit origstr");
BLI_strncpy(origstr, but->drawstr, data->maxlen); BLI_strncpy(origstr, but->drawstr, data->maxlen);
/* XXX solve generic */ /* XXX solve generic, see: #widget_draw_text_icon */
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)) {
/* text draws with offset 0.40, but this extra .05 makes clicks inbetween characters feel nicer */ if (but->flag & UI_HAS_ICON) {
startx += (0.45f * U.widget_unit);
if (but->flag & UI_HAS_ICON)
startx += UI_DPI_ICON_SIZE; startx += UI_DPI_ICON_SIZE;
} }
/* but this extra .05 makes clicks inbetween characters feel nicer */
startx += ((UI_TEXT_MARGIN_X + 0.05f) * U.widget_unit);
}
/* mouse dragged outside the widget to the left */ /* mouse dragged outside the widget to the left */
if (x < startx && but->ofs > 0) { if (x < startx && but->ofs > 0) {
@@ -1511,7 +1513,7 @@ static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, sho
MEM_freeN(origstr); MEM_freeN(origstr);
} }
static void ui_textedit_set_cursor_select(uiBut *but, uiHandleButtonData *data, short x) static void ui_textedit_set_cursor_select(uiBut *but, uiHandleButtonData *data, const float x)
{ {
if (x > data->selstartx) data->selextend = EXTEND_RIGHT; if (x > data->selstartx) data->selextend = EXTEND_RIGHT;
else if (x < data->selstartx) data->selextend = EXTEND_LEFT; else if (x < data->selstartx) data->selextend = EXTEND_LEFT;

View File

@@ -537,6 +537,8 @@ extern unsigned char checker_stipple_sml[32 * 32 / 8];
#define UI_TRANSP_DARK 100 #define UI_TRANSP_DARK 100
#define UI_TRANSP_LIGHT 160 #define UI_TRANSP_LIGHT 160
#define UI_TEXT_MARGIN_X 0.4f
/* interface_style.c */ /* interface_style.c */
void uiStyleInit(void); void uiStyleInit(void);

View File

@@ -1325,11 +1325,11 @@ static void widget_draw_text_icon(uiFontStyle *fstyle, uiWidgetColors *wcol, uiB
rect->xmin += (int)(0.8f * BLI_rcti_size_y(rect)); rect->xmin += (int)(0.8f * BLI_rcti_size_y(rect));
if (but->editstr || (but->flag & UI_TEXT_LEFT)) { if (but->editstr || (but->flag & UI_TEXT_LEFT)) {
rect->xmin += (0.4f * U.widget_unit) / but->block->aspect; rect->xmin += (UI_TEXT_MARGIN_X * U.widget_unit) / but->block->aspect;
} }
} }
else if ((but->flag & UI_TEXT_LEFT)) { else if ((but->flag & UI_TEXT_LEFT)) {
rect->xmin += (0.4f * U.widget_unit) / but->block->aspect; rect->xmin += (UI_TEXT_MARGIN_X * U.widget_unit) / but->block->aspect;
} }
/* unlink icon for this button type */ /* unlink icon for this button type */