diff options
Diffstat (limited to 'src/ui/inputwidget.c')
-rw-r--r-- | src/ui/inputwidget.c | 41 |
1 files changed, 14 insertions, 27 deletions
diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c index 32fb5ccb..b108ee17 100644 --- a/src/ui/inputwidget.c +++ b/src/ui/inputwidget.c | |||
@@ -80,6 +80,7 @@ enum iInputWidgetFlag { | |||
80 | markWords_InputWidgetFlag = iBit(8), | 80 | markWords_InputWidgetFlag = iBit(8), |
81 | needUpdateBuffer_InputWidgetFlag = iBit(9), | 81 | needUpdateBuffer_InputWidgetFlag = iBit(9), |
82 | enterKeyEnabled_InputWidgetFlag = iBit(10), | 82 | enterKeyEnabled_InputWidgetFlag = iBit(10), |
83 | enterKeyInsertsLineFeed_InputWidgetFlag = iBit(11), | ||
83 | }; | 84 | }; |
84 | 85 | ||
85 | /*----------------------------------------------------------------------------------------------*/ | 86 | /*----------------------------------------------------------------------------------------------*/ |
@@ -347,8 +348,11 @@ void init_InputWidget(iInputWidget *d, size_t maxLen) { | |||
347 | d->lastCursor = 0; | 348 | d->lastCursor = 0; |
348 | d->cursorLine = 0; | 349 | d->cursorLine = 0; |
349 | d->lastUpdateWidth = 0; | 350 | d->lastUpdateWidth = 0; |
350 | d->verticalMoveX = -1; /* TODO: Use this. */ | 351 | d->verticalMoveX = -1; /* TODO: Use this. */ |
351 | d->inFlags = eatEscape_InputWidgetFlag | enterKeyEnabled_InputWidgetFlag; | 352 | d->inFlags = eatEscape_InputWidgetFlag | enterKeyEnabled_InputWidgetFlag; |
353 | if (deviceType_App() != desktop_AppDeviceType) { | ||
354 | d->inFlags |= enterKeyInsertsLineFeed_InputWidgetFlag; | ||
355 | } | ||
352 | iZap(d->mark); | 356 | iZap(d->mark); |
353 | setMaxLen_InputWidget(d, maxLen); | 357 | setMaxLen_InputWidget(d, maxLen); |
354 | d->maxLayoutLines = iInvalidSize; | 358 | d->maxLayoutLines = iInvalidSize; |
@@ -464,6 +468,10 @@ void setValidator_InputWidget(iInputWidget *d, iInputWidgetValidatorFunc validat | |||
464 | d->validatorContext = context; | 468 | d->validatorContext = context; |
465 | } | 469 | } |
466 | 470 | ||
471 | void setEnterInsertsLF_InputWidget(iInputWidget *d, iBool enterInsertsLF) { | ||
472 | iChangeFlags(d->inFlags, enterKeyInsertsLineFeed_InputWidgetFlag, enterInsertsLF); | ||
473 | } | ||
474 | |||
467 | void setEnterKeyEnabled_InputWidget(iInputWidget *d, iBool enterKeyEnabled) { | 475 | void setEnterKeyEnabled_InputWidget(iInputWidget *d, iBool enterKeyEnabled) { |
468 | iChangeFlags(d->inFlags, enterKeyEnabled_InputWidgetFlag, enterKeyEnabled); | 476 | iChangeFlags(d->inFlags, enterKeyEnabled_InputWidgetFlag, enterKeyEnabled); |
469 | } | 477 | } |
@@ -714,12 +722,12 @@ iLocalDef iBool isLastLine_InputWidget_(const iInputWidget *d, const iInputLine | |||
714 | } | 722 | } |
715 | 723 | ||
716 | static size_t indexForRelativeX_InputWidget_(const iInputWidget *d, int x, const iInputLine *line) { | 724 | static size_t indexForRelativeX_InputWidget_(const iInputWidget *d, int x, const iInputLine *line) { |
725 | size_t index = line->offset; | ||
717 | if (x <= 0) { | 726 | if (x <= 0) { |
718 | return line->offset; | 727 | return index; |
719 | } | 728 | } |
720 | const char *endPos; | 729 | const char *endPos; |
721 | tryAdvanceNoWrap_Text(d->font, range_String(&line->text), x, &endPos); | 730 | tryAdvanceNoWrap_Text(d->font, range_String(&line->text), x, &endPos); |
722 | size_t index = line->offset; | ||
723 | if (endPos == constEnd_String(&line->text)) { | 731 | if (endPos == constEnd_String(&line->text)) { |
724 | index += line->len; | 732 | index += line->len; |
725 | } | 733 | } |
@@ -1166,7 +1174,7 @@ static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) { | |||
1166 | case SDLK_KP_ENTER: | 1174 | case SDLK_KP_ENTER: |
1167 | if (mods == KMOD_SHIFT || (d->maxLen == 0 && | 1175 | if (mods == KMOD_SHIFT || (d->maxLen == 0 && |
1168 | ~d->inFlags & isUrl_InputWidgetFlag && | 1176 | ~d->inFlags & isUrl_InputWidgetFlag && |
1169 | deviceType_App() != desktop_AppDeviceType)) { | 1177 | d->inFlags & enterKeyInsertsLineFeed_InputWidgetFlag)) { |
1170 | pushUndo_InputWidget_(d); | 1178 | pushUndo_InputWidget_(d); |
1171 | deleteMarked_InputWidget_(d); | 1179 | deleteMarked_InputWidget_(d); |
1172 | insertChar_InputWidget_(d, '\n'); | 1180 | insertChar_InputWidget_(d, '\n'); |
@@ -1357,13 +1365,7 @@ static void draw_InputWidget_(const iInputWidget *d) { | |||
1357 | } | 1365 | } |
1358 | iPaint p; | 1366 | iPaint p; |
1359 | init_Paint(&p); | 1367 | init_Paint(&p); |
1360 | /* `lines` is already up to date and ready for drawing. */ | 1368 | /* `lines` is already up to date and ready for drawing. */ |
1361 | /* TODO: If empty, draw the hint. */ | ||
1362 | // iString *text = visText_InputWidget_(d); | ||
1363 | // if (isWhite_(text) && !isEmpty_String(&d->hint)) { | ||
1364 | // set_String(text, &d->hint); | ||
1365 | // isHint = iTrue; | ||
1366 | // } | ||
1367 | fillRect_Paint( | 1369 | fillRect_Paint( |
1368 | &p, bounds, isFocused ? uiInputBackgroundFocused_ColorId : uiInputBackground_ColorId); | 1370 | &p, bounds, isFocused ? uiInputBackgroundFocused_ColorId : uiInputBackground_ColorId); |
1369 | drawRectThickness_Paint(&p, | 1371 | drawRectThickness_Paint(&p, |
@@ -1374,7 +1376,6 @@ static void draw_InputWidget_(const iInputWidget *d) { | |||
1374 | setClip_Paint(&p, adjusted_Rect(bounds, init_I2(d->leftPadding, 0), | 1376 | setClip_Paint(&p, adjusted_Rect(bounds, init_I2(d->leftPadding, 0), |
1375 | init_I2(-d->rightPadding, w->flags & extraPadding_WidgetFlag ? -gap_UI / 2 : 0))); | 1377 | init_I2(-d->rightPadding, w->flags & extraPadding_WidgetFlag ? -gap_UI / 2 : 0))); |
1376 | const iRect contentBounds = contentBounds_InputWidget_(d); | 1378 | const iRect contentBounds = contentBounds_InputWidget_(d); |
1377 | // const iInt2 textOrigin = textOrigin_InputWidget_(d); //, cstr_String(text)); | ||
1378 | iInt2 drawPos = topLeft_Rect(contentBounds); | 1379 | iInt2 drawPos = topLeft_Rect(contentBounds); |
1379 | const int fg = isHint ? uiAnnotation_ColorId | 1380 | const int fg = isHint ? uiAnnotation_ColorId |
1380 | : isFocused && !isEmpty_Array(&d->text) ? uiInputTextFocused_ColorId | 1381 | : isFocused && !isEmpty_Array(&d->text) ? uiInputTextFocused_ColorId |
@@ -1418,19 +1419,6 @@ static void draw_InputWidget_(const iInputWidget *d) { | |||
1418 | drawPos.y += lineHeight_Text(d->font); | 1419 | drawPos.y += lineHeight_Text(d->font); |
1419 | } | 1420 | } |
1420 | } | 1421 | } |
1421 | // if (d->buffered && !isFocused && !isHint) { | ||
1422 | // /* Most input widgets will use this, since only one is focused at a time. */ | ||
1423 | // draw_TextBuf(d->buffered, textOrigin, white_ColorId); | ||
1424 | // } | ||
1425 | // else { | ||
1426 | // draw_Text(d->font, | ||
1427 | // textOrigin, | ||
1428 | // isHint ? uiAnnotation_ColorId | ||
1429 | // : isFocused && !isEmpty_Array(&d->text) ? uiInputTextFocused_ColorId | ||
1430 | // : uiInputText_ColorId, | ||
1431 | // "%s", | ||
1432 | // cstr_String(text)); | ||
1433 | // } | ||
1434 | unsetClip_Paint(&p); | 1422 | unsetClip_Paint(&p); |
1435 | /* Cursor blinking. */ | 1423 | /* Cursor blinking. */ |
1436 | if (isFocused && d->cursorVis) { | 1424 | if (isFocused && d->cursorVis) { |
@@ -1474,7 +1462,6 @@ static void draw_InputWidget_(const iInputWidget *d) { | |||
1474 | deinit_String(&cur); | 1462 | deinit_String(&cur); |
1475 | } | 1463 | } |
1476 | } | 1464 | } |
1477 | // delete_String(text); | ||
1478 | drawChildren_Widget(w); | 1465 | drawChildren_Widget(w); |
1479 | } | 1466 | } |
1480 | 1467 | ||