summaryrefslogtreecommitdiff
path: root/src/ui/inputwidget.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/inputwidget.c')
-rw-r--r--src/ui/inputwidget.c38
1 files changed, 27 insertions, 11 deletions
diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c
index 58a47610..76053f8b 100644
--- a/src/ui/inputwidget.c
+++ b/src/ui/inputwidget.c
@@ -201,8 +201,12 @@ void setHint_InputWidget(iInputWidget *d, const char *hintText) {
201} 201}
202 202
203void setContentPadding_InputWidget(iInputWidget *d, int left, int right) { 203void setContentPadding_InputWidget(iInputWidget *d, int left, int right) {
204 d->leftPadding = left; 204 if (left >= 0) {
205 d->rightPadding = right; 205 d->leftPadding = left;
206 }
207 if (right >= 0) {
208 d->rightPadding = right;
209 }
206 refresh_Widget(d); 210 refresh_Widget(d);
207} 211}
208 212
@@ -863,25 +867,37 @@ static void draw_InputWidget_(const iInputWidget *d) {
863 /* Cursor blinking. */ 867 /* Cursor blinking. */
864 if (isFocused && d->cursorVis) { 868 if (isFocused && d->cursorVis) {
865 iString cur; 869 iString cur;
866 if (d->cursor < size_Array(&d->text)) { 870 iInt2 curSize;
867 if (~d->inFlags & isSensitive_InputWidgetFlag) { 871 if (d->mode == overwrite_InputMode) {
868 initUnicodeN_String(&cur, constAt_Array(&d->text, d->cursor), 1); 872 /* Block cursor that overlaps a character. */
873 if (d->cursor < size_Array(&d->text)) {
874 if (~d->inFlags & isSensitive_InputWidgetFlag) {
875 initUnicodeN_String(&cur, constAt_Array(&d->text, d->cursor), 1);
876 }
877 else {
878 initUnicodeN_String(&cur, &sensitiveChar_, 1);
879 }
869 } 880 }
870 else { 881 else {
871 initUnicodeN_String(&cur, &sensitiveChar_, 1); 882 initCStr_String(&cur, " ");
872 } 883 }
884 curSize = addX_I2(advance_Text(d->font, cstr_String(&cur)), iMin(2, gap_UI / 4));
873 } 885 }
874 else { 886 else {
875 initCStr_String(&cur, " "); 887 /* Bar cursor. */
888 curSize = init_I2(gap_UI / 2, lineHeight_Text(d->font));
876 } 889 }
877 /* The `gap_UI` offsets below are a hack. They are used because for some reason the 890 /* The `gap_UI` offsets below are a hack. They are used because for some reason the
878 cursor rect and the glyph inside don't quite position like during `run_Text_()`. */ 891 cursor rect and the glyph inside don't quite position like during `run_Text_()`. */
879 const iInt2 prefixSize = advanceN_Text(d->font, cstr_String(text), d->cursor); 892 const iInt2 prefixSize = advanceN_Text(d->font, cstr_String(text), d->cursor);
880 const iInt2 curPos = addX_I2(textOrigin, prefixSize.x); 893 const iInt2 curPos = addX_I2(textOrigin, prefixSize.x +
881 const iRect curRect = { curPos, addX_I2(advance_Text(d->font, cstr_String(&cur)), iMin(2, gap_UI / 4)) }; 894 (d->mode == insert_InputMode ? -curSize.x / 2 : 0));
895 const iRect curRect = { curPos, curSize };
882 fillRect_Paint(&p, curRect, uiInputCursor_ColorId); 896 fillRect_Paint(&p, curRect, uiInputCursor_ColorId);
883 draw_Text(d->font, addX_I2(curPos, iMin(1, gap_UI / 8)), uiInputCursorText_ColorId, "%s", cstr_String(&cur)); 897 if (d->mode == overwrite_InputMode) {
884 deinit_String(&cur); 898 draw_Text(d->font, addX_I2(curPos, iMin(1, gap_UI / 8)), uiInputCursorText_ColorId, "%s", cstr_String(&cur));
899 deinit_String(&cur);
900 }
885 } 901 }
886 delete_String(text); 902 delete_String(text);
887 drawChildren_Widget(w); 903 drawChildren_Widget(w);