summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-12-15 12:48:06 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-12-15 12:48:06 +0200
commitbc3d069519b3cfd832a6a6499f2f4b2ef4a70329 (patch)
tree0b6bc9120ffc32e33c4eb5a651a60397237cbac5 /src
parent2619a97a74eb1b758263b7eca6e3968e9b05888b (diff)
InputWidget: Dealing with very narrow width
The input widget is not usable if the width is too narrow.
Diffstat (limited to 'src')
-rw-r--r--src/ui/inputwidget.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c
index c60cd99e..8d58eac9 100644
--- a/src/ui/inputwidget.c
+++ b/src/ui/inputwidget.c
@@ -374,6 +374,8 @@ static iRect contentBounds_InputWidget_(const iInputWidget *d) {
374 return bounds; 374 return bounds;
375} 375}
376 376
377#define minWidth_InputWidget_ (3 * gap_UI)
378
377static iWrapText wrap_InputWidget_(const iInputWidget *d, int y) { 379static iWrapText wrap_InputWidget_(const iInputWidget *d, int y) {
378#if LAGRANGE_USE_SYSTEM_TEXT_INPUT 380#if LAGRANGE_USE_SYSTEM_TEXT_INPUT
379 iUnused(y); /* full text is wrapped always */ 381 iUnused(y); /* full text is wrapped always */
@@ -383,7 +385,8 @@ static iWrapText wrap_InputWidget_(const iInputWidget *d, int y) {
383#endif 385#endif
384 return (iWrapText){ 386 return (iWrapText){
385 .text = text, 387 .text = text,
386 .maxWidth = d->maxLen == 0 ? width_Rect(contentBounds_InputWidget_(d)) 388 .maxWidth = d->maxLen == 0 ? iMaxi(minWidth_InputWidget_,
389 width_Rect(contentBounds_InputWidget_(d)))
387 : unlimitedWidth_InputWidget_, 390 : unlimitedWidth_InputWidget_,
388 .mode = 391 .mode =
389 (d->inFlags & isUrl_InputWidgetFlag ? anyCharacter_WrapTextMode : word_WrapTextMode), 392 (d->inFlags & isUrl_InputWidgetFlag ? anyCharacter_WrapTextMode : word_WrapTextMode),
@@ -647,7 +650,7 @@ static size_t length_InputWidget_(const iInputWidget *d) {
647static void updateLine_InputWidget_(iInputWidget *d, iInputLine *line) { 650static void updateLine_InputWidget_(iInputWidget *d, iInputLine *line) {
648 iAssert(endsWith_String(&line->text, "\n") || isLastLine_InputWidget_(d, line)); 651 iAssert(endsWith_String(&line->text, "\n") || isLastLine_InputWidget_(d, line));
649 iWrapText wrapText = wrap_InputWidget_(d, indexOf_Array(&d->lines, line)); 652 iWrapText wrapText = wrap_InputWidget_(d, indexOf_Array(&d->lines, line));
650 if (wrapText.maxWidth <= 0) { 653 if (wrapText.maxWidth <= minWidth_InputWidget_) {
651 line->wrapLines.end = line->wrapLines.start + 1; 654 line->wrapLines.end = line->wrapLines.start + 1;
652 return; 655 return;
653 } 656 }
@@ -1524,7 +1527,7 @@ static iInt2 coordCursor_InputWidget_(const iInputWidget *d, iInt2 coord) {
1524// return cursorMax_InputWidget_(d); 1527// return cursorMax_InputWidget_(d);
1525// } 1528// }
1526 iWrapText wrapText = { 1529 iWrapText wrapText = {
1527 .maxWidth = d->maxLen == 0 ? width_Rect(bounds) : unlimitedWidth_InputWidget_, 1530 .maxWidth = d->maxLen == 0 ? iMaxi(minWidth_InputWidget_, width_Rect(bounds)) : unlimitedWidth_InputWidget_,
1528 .mode = (d->inFlags & isUrl_InputWidgetFlag ? anyCharacter_WrapTextMode : word_WrapTextMode), 1531 .mode = (d->inFlags & isUrl_InputWidgetFlag ? anyCharacter_WrapTextMode : word_WrapTextMode),
1529 .hitPoint = relCoord, 1532 .hitPoint = relCoord,
1530 .overrideChar = (d->inFlags & isSensitive_InputWidgetFlag ? sensitiveChar_ : 0), 1533 .overrideChar = (d->inFlags & isSensitive_InputWidgetFlag ? sensitiveChar_ : 0),
@@ -2108,6 +2111,10 @@ static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) {
2108 /* Resize according to width immediately. */ 2111 /* Resize according to width immediately. */
2109 if (d->lastUpdateWidth != w->rect.size.x) { 2112 if (d->lastUpdateWidth != w->rect.size.x) {
2110 d->inFlags |= needUpdateBuffer_InputWidgetFlag; 2113 d->inFlags |= needUpdateBuffer_InputWidgetFlag;
2114 if (contentBounds_InputWidget_(d).size.x < minWidth_InputWidget_) {
2115 setFocus_Widget(NULL);
2116 return iFalse;
2117 }
2111 if (d->inFlags & isUrl_InputWidgetFlag) { 2118 if (d->inFlags & isUrl_InputWidgetFlag) {
2112 /* Restore/omit the default scheme if necessary. */ 2119 /* Restore/omit the default scheme if necessary. */
2113 setText_InputWidget(d, text_InputWidget(d)); 2120 setText_InputWidget(d, text_InputWidget(d));
@@ -2127,7 +2134,12 @@ static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) {
2127 } 2134 }
2128#endif 2135#endif
2129 if (isCommand_Widget(w, ev, "focus.gained")) { 2136 if (isCommand_Widget(w, ev, "focus.gained")) {
2130 begin_InputWidget(d); 2137 if (contentBounds_InputWidget_(d).size.x < minWidth_InputWidget_) {
2138 setFocus_Widget(NULL);
2139 }
2140 else {
2141 begin_InputWidget(d);
2142 }
2131 return iFalse; 2143 return iFalse;
2132 } 2144 }
2133 else if (isCommand_UserEvent(ev, "keyroot.changed")) { 2145 else if (isCommand_UserEvent(ev, "keyroot.changed")) {