diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-07-24 11:21:28 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-07-24 11:21:28 +0300 |
commit | 673ef41425fc6f35aa539ff32f40d0ae5b8e63de (patch) | |
tree | 22d4631736d0338876fff24ebdfe78969d1df94f /src/ui/inputwidget.c | |
parent | 25f8c7550569fa82d3496d215ab43825a9b73f36 (diff) |
InputWidget: Focus, cursor and scrolling
Tweak that lets a single-line editor (URL field) keep its first line visible when unfocused.
Diffstat (limited to 'src/ui/inputwidget.c')
-rw-r--r-- | src/ui/inputwidget.c | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c index 93dbfa9d..bdce102a 100644 --- a/src/ui/inputwidget.c +++ b/src/ui/inputwidget.c | |||
@@ -231,7 +231,6 @@ static void restoreBackup_InputWidget_(iInputWidget *d) { | |||
231 | iFile *f = new_File(d->backupPath); | 231 | iFile *f = new_File(d->backupPath); |
232 | if (open_File(f, readOnly_FileMode | text_FileMode)) { | 232 | if (open_File(f, readOnly_FileMode | text_FileMode)) { |
233 | setText_InputWidget(d, collect_String(readString_File(f))); | 233 | setText_InputWidget(d, collect_String(readString_File(f))); |
234 | updateMetrics_InputWidget_(d); | ||
235 | } | 234 | } |
236 | iRelease(f); | 235 | iRelease(f); |
237 | } | 236 | } |
@@ -419,7 +418,7 @@ static const char *sensitive_ = "\u25cf"; | |||
419 | static iWrapText wrap_InputWidget_(const iInputWidget *d, int y) { | 418 | static iWrapText wrap_InputWidget_(const iInputWidget *d, int y) { |
420 | return (iWrapText){ | 419 | return (iWrapText){ |
421 | .text = range_String(&line_InputWidget_(d, y)->text), | 420 | .text = range_String(&line_InputWidget_(d, y)->text), |
422 | .maxWidth = width_Rect(contentBounds_InputWidget_(d)), | 421 | .maxWidth = d->maxLen == 0 ? width_Rect(contentBounds_InputWidget_(d)) : 0, |
423 | .mode = (d->inFlags & isUrl_InputWidgetFlag ? anyCharacter_WrapTextMode | 422 | .mode = (d->inFlags & isUrl_InputWidgetFlag ? anyCharacter_WrapTextMode |
424 | : word_WrapTextMode), | 423 | : word_WrapTextMode), |
425 | .overrideChar = (d->inFlags & isSensitive_InputWidgetFlag ? sensitiveChar_ : 0), | 424 | .overrideChar = (d->inFlags & isSensitive_InputWidgetFlag ? sensitiveChar_ : 0), |
@@ -455,6 +454,10 @@ static void updateVisible_InputWidget_(iInputWidget *d) { | |||
455 | d->visWrapLines.start += delta; | 454 | d->visWrapLines.start += delta; |
456 | d->visWrapLines.end += delta; | 455 | d->visWrapLines.end += delta; |
457 | iAssert(contains_Range(&d->visWrapLines, cursorY)); | 456 | iAssert(contains_Range(&d->visWrapLines, cursorY)); |
457 | if (!isFocused_Widget(d) && d->maxWrapLines == 1) { | ||
458 | d->visWrapLines.start = 0; | ||
459 | d->visWrapLines.end = 1; | ||
460 | } | ||
458 | } | 461 | } |
459 | 462 | ||
460 | static void showCursor_InputWidget_(iInputWidget *d) { | 463 | static void showCursor_InputWidget_(iInputWidget *d) { |
@@ -823,18 +826,19 @@ void setText_InputWidget(iInputWidget *d, const iString *text) { | |||
823 | updateLine_InputWidget_(d, i.value); /* count number of visible lines */ | 826 | updateLine_InputWidget_(d, i.value); /* count number of visible lines */ |
824 | } | 827 | } |
825 | updateLineRangesStartingFrom_InputWidget_(d, 0); | 828 | updateLineRangesStartingFrom_InputWidget_(d, 0); |
826 | if (isFocused_Widget(d)) { | 829 | //if (isFocused_Widget(d)) { |
827 | d->cursor = cursorMax_InputWidget_(d); | 830 | d->cursor = cursorMax_InputWidget_(d); |
828 | } | 831 | // } |
829 | else { | 832 | // else { |
830 | d->cursor.y = iMin(d->cursor.y, (int) size_Array(&d->lines) - 1); | 833 | // d->cursor.y = iMin(d->cursor.y, (int) size_Array(&d->lines) - 1); |
831 | d->cursor.x = iMin(d->cursor.x, size_String(&cursorLine_InputWidget_(d)->text)); | 834 | // d->cursor.x = iMin(d->cursor.x, size_String(&cursorLine_InputWidget_(d)->text)); |
832 | iZap(d->mark); | 835 | iZap(d->mark); |
833 | } | 836 | // } |
834 | if (!isFocused_Widget(d)) { | 837 | if (!isFocused_Widget(d)) { |
835 | d->inFlags |= needUpdateBuffer_InputWidgetFlag; | 838 | d->inFlags |= needUpdateBuffer_InputWidgetFlag; |
836 | } | 839 | } |
837 | updateVisible_InputWidget_(d); | 840 | updateVisible_InputWidget_(d); |
841 | updateMetrics_InputWidget_(d); | ||
838 | refresh_Widget(as_Widget(d)); | 842 | refresh_Widget(as_Widget(d)); |
839 | } | 843 | } |
840 | 844 | ||
@@ -918,6 +922,7 @@ void begin_InputWidget(iInputWidget *d) { | |||
918 | iZap(d->mark); | 922 | iZap(d->mark); |
919 | } | 923 | } |
920 | enableEditorKeysInMenus_(iFalse); | 924 | enableEditorKeysInMenus_(iFalse); |
925 | updateVisible_InputWidget_(d); | ||
921 | } | 926 | } |
922 | 927 | ||
923 | void end_InputWidget(iInputWidget *d, iBool accept) { | 928 | void end_InputWidget(iInputWidget *d, iBool accept) { |
@@ -1249,7 +1254,7 @@ static iInt2 coordCursor_InputWidget_(const iInputWidget *d, iInt2 coord) { | |||
1249 | return cursorMax_InputWidget_(d); | 1254 | return cursorMax_InputWidget_(d); |
1250 | } | 1255 | } |
1251 | iWrapText wrapText = { | 1256 | iWrapText wrapText = { |
1252 | .maxWidth = width_Rect(bounds), | 1257 | .maxWidth = d->maxLen == 0 ? width_Rect(bounds) : 0, |
1253 | .mode = (d->inFlags & isUrl_InputWidgetFlag ? anyCharacter_WrapTextMode : word_WrapTextMode), | 1258 | .mode = (d->inFlags & isUrl_InputWidgetFlag ? anyCharacter_WrapTextMode : word_WrapTextMode), |
1254 | .hitPoint = relCoord, | 1259 | .hitPoint = relCoord, |
1255 | .overrideChar = (d->inFlags & isSensitive_InputWidgetFlag ? sensitiveChar_ : 0), | 1260 | .overrideChar = (d->inFlags & isSensitive_InputWidgetFlag ? sensitiveChar_ : 0), |
@@ -1831,7 +1836,7 @@ static void draw_InputWidget_(const iInputWidget *d) { | |||
1831 | : isFocused /*&& !isEmpty_Array(&d->lines)*/ ? uiInputTextFocused_ColorId | 1836 | : isFocused /*&& !isEmpty_Array(&d->lines)*/ ? uiInputTextFocused_ColorId |
1832 | : uiInputText_ColorId; | 1837 | : uiInputText_ColorId; |
1833 | iWrapText wrapText = { | 1838 | iWrapText wrapText = { |
1834 | .maxWidth = width_Rect(contentBounds), | 1839 | .maxWidth = d->maxLen == 0 ? width_Rect(contentBounds) : 0, |
1835 | .mode = (d->inFlags & isUrl_InputWidgetFlag ? anyCharacter_WrapTextMode | 1840 | .mode = (d->inFlags & isUrl_InputWidgetFlag ? anyCharacter_WrapTextMode |
1836 | : word_WrapTextMode), | 1841 | : word_WrapTextMode), |
1837 | .overrideChar = (d->inFlags & isSensitive_InputWidgetFlag ? sensitiveChar_ : 0), | 1842 | .overrideChar = (d->inFlags & isSensitive_InputWidgetFlag ? sensitiveChar_ : 0), |