diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-07-23 10:35:13 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-07-23 10:35:13 +0300 |
commit | 7831640317ed9def394a1cbe3692ad83c37cff4d (patch) | |
tree | 2156ebd277a76218ce598634fc52036765291713 | |
parent | 7f54c3fb6caa0bc109ed47be4bc91039a00bed80 (diff) |
InputWidget: Fixes to updating widget height
-rw-r--r-- | src/ui/inputwidget.c | 62 | ||||
-rw-r--r-- | src/ui/uploadwidget.c | 2 |
2 files changed, 37 insertions, 27 deletions
diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c index cb6d35a4..444f849d 100644 --- a/src/ui/inputwidget.c +++ b/src/ui/inputwidget.c | |||
@@ -224,11 +224,14 @@ struct Impl_InputWidget { | |||
224 | 224 | ||
225 | iDefineObjectConstructionArgs(InputWidget, (size_t maxLen), maxLen) | 225 | iDefineObjectConstructionArgs(InputWidget, (size_t maxLen), maxLen) |
226 | 226 | ||
227 | static void updateMetrics_InputWidget_(iInputWidget *); | ||
228 | |||
227 | static void restoreBackup_InputWidget_(iInputWidget *d) { | 229 | static void restoreBackup_InputWidget_(iInputWidget *d) { |
228 | if (!d->backupPath) return; | 230 | if (!d->backupPath) return; |
229 | iFile *f = new_File(d->backupPath); | 231 | iFile *f = new_File(d->backupPath); |
230 | if (open_File(f, readOnly_FileMode | text_FileMode)) { | 232 | if (open_File(f, readOnly_FileMode | text_FileMode)) { |
231 | setText_InputWidget(d, collect_String(readString_File(f))); | 233 | setText_InputWidget(d, collect_String(readString_File(f))); |
234 | updateMetrics_InputWidget_(d); | ||
232 | } | 235 | } |
233 | iRelease(f); | 236 | iRelease(f); |
234 | } | 237 | } |
@@ -674,11 +677,29 @@ static void updateLine_InputWidget_(iInputWidget *d, iInputLine *line) { | |||
674 | line->wrapLines.end = line->wrapLines.start + height_Rect(tm.bounds) / lineHeight_Text(d->font); | 677 | line->wrapLines.end = line->wrapLines.start + height_Rect(tm.bounds) / lineHeight_Text(d->font); |
675 | } | 678 | } |
676 | 679 | ||
680 | static void updateLineRangesStartingFrom_InputWidget_(iInputWidget *d, int y) { | ||
681 | iInputLine *line = at_Array(&d->lines, y); | ||
682 | line->range.end = line->range.start + size_String(&line->text); | ||
683 | for (size_t i = y + 1; i < size_Array(&d->lines); i++) { | ||
684 | iInputLine *next = at_Array(&d->lines, i); | ||
685 | next->range.start = line->range.end; | ||
686 | next->range.end = next->range.start + size_String(&next->text); | ||
687 | /* Update wrap line range as well. */ | ||
688 | next->wrapLines = (iRangei){ | ||
689 | line->wrapLines.end, | ||
690 | line->wrapLines.end + numWrapLines_InputLine_(next) | ||
691 | }; | ||
692 | line = next; | ||
693 | } | ||
694 | } | ||
695 | |||
677 | static void updateAllLinesAndResizeHeight_InputWidget_(iInputWidget *d) { | 696 | static void updateAllLinesAndResizeHeight_InputWidget_(iInputWidget *d) { |
678 | const int oldWraps = numWrapLines_InputWidget_(d); | 697 | const int oldWraps = numWrapLines_InputWidget_(d); |
679 | iForEach(Array, i, &d->lines) { | 698 | iForEach(Array, i, &d->lines) { |
680 | updateLine_InputWidget_(d, i.value); /* count number of visible lines */ | 699 | updateLine_InputWidget_(d, i.value); /* count number of visible lines */ |
681 | } | 700 | } |
701 | updateLineRangesStartingFrom_InputWidget_(d, 0); | ||
702 | updateVisible_InputWidget_(d); | ||
682 | if (oldWraps != numWrapLines_InputWidget_(d)) { | 703 | if (oldWraps != numWrapLines_InputWidget_(d)) { |
683 | // d->click.minHeight = contentHeight_InputWidget_(d, iFalse); | 704 | // d->click.minHeight = contentHeight_InputWidget_(d, iFalse); |
684 | updateMetrics_InputWidget_(d); | 705 | updateMetrics_InputWidget_(d); |
@@ -960,6 +981,7 @@ void setText_InputWidget(iInputWidget *d, const iString *text) { | |||
960 | iForEach(Array, i, &d->lines) { | 981 | iForEach(Array, i, &d->lines) { |
961 | updateLine_InputWidget_(d, i.value); /* count number of visible lines */ | 982 | updateLine_InputWidget_(d, i.value); /* count number of visible lines */ |
962 | } | 983 | } |
984 | updateLineRangesStartingFrom_InputWidget_(d, 0); | ||
963 | if (isFocused_Widget(d)) { | 985 | if (isFocused_Widget(d)) { |
964 | d->cursor = cursorMax_InputWidget_(d); | 986 | d->cursor = cursorMax_InputWidget_(d); |
965 | } | 987 | } |
@@ -972,6 +994,7 @@ void setText_InputWidget(iInputWidget *d, const iString *text) { | |||
972 | d->inFlags |= needUpdateBuffer_InputWidgetFlag; | 994 | d->inFlags |= needUpdateBuffer_InputWidgetFlag; |
973 | } | 995 | } |
974 | // updateLinesAndResize_InputWidget_(d); | 996 | // updateLinesAndResize_InputWidget_(d); |
997 | // updateAllLinesAndResizeHeight_InputWidget_(d); | ||
975 | updateVisible_InputWidget_(d); | 998 | updateVisible_InputWidget_(d); |
976 | refresh_Widget(as_Widget(d)); | 999 | refresh_Widget(as_Widget(d)); |
977 | } | 1000 | } |
@@ -1096,22 +1119,6 @@ void end_InputWidget(iInputWidget *d, iBool accept) { | |||
1096 | accept ? 1 : 0); | 1119 | accept ? 1 : 0); |
1097 | } | 1120 | } |
1098 | 1121 | ||
1099 | static void updateLineRangesStartingFrom_InputWidget_(iInputWidget *d, int y) { | ||
1100 | iInputLine *line = at_Array(&d->lines, y); | ||
1101 | line->range.end = line->range.start + size_String(&line->text); | ||
1102 | for (size_t i = y + 1; i < size_Array(&d->lines); i++) { | ||
1103 | iInputLine *next = at_Array(&d->lines, i); | ||
1104 | next->range.start = line->range.end; | ||
1105 | next->range.end = next->range.start + size_String(&next->text); | ||
1106 | /* Update wrap line range as well. */ | ||
1107 | next->wrapLines = (iRangei){ | ||
1108 | line->wrapLines.end, | ||
1109 | line->wrapLines.end + numWrapLines_InputLine_(next) | ||
1110 | }; | ||
1111 | line = next; | ||
1112 | } | ||
1113 | } | ||
1114 | |||
1115 | static void textOfLinesWasChanged_InputWidget_(iInputWidget *d, iRangei lineRange) { | 1122 | static void textOfLinesWasChanged_InputWidget_(iInputWidget *d, iRangei lineRange) { |
1116 | for (int i = lineRange.start; i < lineRange.end; i++) { | 1123 | for (int i = lineRange.start; i < lineRange.end; i++) { |
1117 | updateLine_InputWidget_(d, at_Array(&d->lines, i)); | 1124 | updateLine_InputWidget_(d, at_Array(&d->lines, i)); |
@@ -1601,6 +1608,19 @@ static iBool isArrowUpDownConsumed_InputWidget_(const iInputWidget *d) { | |||
1601 | 1608 | ||
1602 | static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) { | 1609 | static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) { |
1603 | iWidget *w = as_Widget(d); | 1610 | iWidget *w = as_Widget(d); |
1611 | /* Resize according to width immediately. */ | ||
1612 | if (d->lastUpdateWidth != w->rect.size.x) { | ||
1613 | d->inFlags |= needUpdateBuffer_InputWidgetFlag; | ||
1614 | #if 0 | ||
1615 | if (d->inFlags & isUrl_InputWidgetFlag) { | ||
1616 | /* Restore/omit the default scheme if necessary. */ | ||
1617 | setText_InputWidget(d, text_InputWidget(d)); | ||
1618 | } | ||
1619 | #endif | ||
1620 | // updateLinesAndResize_InputWidget_(d); | ||
1621 | updateAllLinesAndResizeHeight_InputWidget_(d); | ||
1622 | d->lastUpdateWidth = w->rect.size.x; | ||
1623 | } | ||
1604 | if (isCommand_Widget(w, ev, "focus.gained")) { | 1624 | if (isCommand_Widget(w, ev, "focus.gained")) { |
1605 | begin_InputWidget(d); | 1625 | begin_InputWidget(d); |
1606 | return iFalse; | 1626 | return iFalse; |
@@ -1660,16 +1680,6 @@ static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) { | |||
1660 | updateMetrics_InputWidget_(d); | 1680 | updateMetrics_InputWidget_(d); |
1661 | // updateLinesAndResize_InputWidget_(d); | 1681 | // updateLinesAndResize_InputWidget_(d); |
1662 | } | 1682 | } |
1663 | else if (isResize_UserEvent(ev) || d->lastUpdateWidth != w->rect.size.x) { | ||
1664 | d->inFlags |= needUpdateBuffer_InputWidgetFlag; | ||
1665 | #if 0 | ||
1666 | if (d->inFlags & isUrl_InputWidgetFlag) { | ||
1667 | /* Restore/omit the default scheme if necessary. */ | ||
1668 | setText_InputWidget(d, text_InputWidget(d)); | ||
1669 | } | ||
1670 | #endif | ||
1671 | // updateLinesAndResize_InputWidget_(d); | ||
1672 | } | ||
1673 | else if (isFocused_Widget(d) && isCommand_UserEvent(ev, "copy")) { | 1683 | else if (isFocused_Widget(d) && isCommand_UserEvent(ev, "copy")) { |
1674 | copy_InputWidget_(d, iFalse); | 1684 | copy_InputWidget_(d, iFalse); |
1675 | return iTrue; | 1685 | return iTrue; |
diff --git a/src/ui/uploadwidget.c b/src/ui/uploadwidget.c index 361f59f9..b9118ca2 100644 --- a/src/ui/uploadwidget.c +++ b/src/ui/uploadwidget.c | |||
@@ -93,7 +93,6 @@ void init_UploadWidget(iUploadWidget *d) { | |||
93 | setFlags_Widget(page, arrangeSize_WidgetFlag, iTrue); | 93 | setFlags_Widget(page, arrangeSize_WidgetFlag, iTrue); |
94 | d->input = new_InputWidget(0); | 94 | d->input = new_InputWidget(0); |
95 | setId_Widget(as_Widget(d->input), "upload.text"); | 95 | setId_Widget(as_Widget(d->input), "upload.text"); |
96 | setBackupFileName_InputWidget(d->input, "uploadbackup.txt"); | ||
97 | setFont_InputWidget(d->input, monospace_FontId); | 96 | setFont_InputWidget(d->input, monospace_FontId); |
98 | setLineLimits_InputWidget(d->input, 7, 20); | 97 | setLineLimits_InputWidget(d->input, 7, 20); |
99 | setHint_InputWidget(d->input, "${hint.upload.text}"); | 98 | setHint_InputWidget(d->input, "${hint.upload.text}"); |
@@ -141,6 +140,7 @@ void init_UploadWidget(iUploadWidget *d) { | |||
141 | } | 140 | } |
142 | resizeToLargestPage_Widget(tabs); | 141 | resizeToLargestPage_Widget(tabs); |
143 | setFocus_Widget(as_Widget(d->input)); | 142 | setFocus_Widget(as_Widget(d->input)); |
143 | setBackupFileName_InputWidget(d->input, "uploadbackup.txt"); | ||
144 | } | 144 | } |
145 | 145 | ||
146 | void deinit_UploadWidget(iUploadWidget *d) { | 146 | void deinit_UploadWidget(iUploadWidget *d) { |