From 1d735299127aaf0474d8fc2a1c5ec4947c1dca9a Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Thu, 4 Mar 2021 09:14:30 +0200 Subject: Changing UI scaling at runtime UI scaling factor is applied when closing the Preferences dialog. IssueID #83 --- src/ui/inputwidget.c | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) (limited to 'src/ui/inputwidget.c') diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c index dd8fa744..4b5cd623 100644 --- a/src/ui/inputwidget.c +++ b/src/ui/inputwidget.c @@ -107,6 +107,24 @@ static void showCursor_InputWidget_(iInputWidget *d) { d->cursorVis = 2; } +static void invalidateBuffered_InputWidget_(iInputWidget *d) { + if (d->buffered) { + delete_TextBuf(d->buffered); + d->buffered = NULL; + } +} + +static void updateMetrics_InputWidget_(iInputWidget *d) { + iWidget *w = as_Widget(d); + /* Caller must arrange the width, but the height is fixed. */ + w->rect.size.y = lineHeight_Text(default_FontId) + 2 * gap_UI; +#if defined (iPlatformAppleMobile) + w->rect.size.y += 2 * gap_UI; +#endif + invalidateBuffered_InputWidget_(d); + arrange_Widget(w); +} + void init_InputWidget(iInputWidget *d, size_t maxLen) { iWidget *w = &d->widget; init_Widget(w); @@ -115,24 +133,20 @@ void init_InputWidget(iInputWidget *d, size_t maxLen) { init_Array(&d->oldText, sizeof(iChar)); init_String(&d->hint); init_Array(&d->undoStack, sizeof(iInputUndo)); - d->font = uiInput_FontId | alwaysVariableFlag_FontId; - d->leftPadding = 0; - d->rightPadding = 0; - d->cursor = 0; - d->lastCursor = 0; - d->inFlags = eatEscape_InputWidgetFlag; + d->font = uiInput_FontId | alwaysVariableFlag_FontId; + d->leftPadding = 0; + d->rightPadding = 0; + d->cursor = 0; + d->lastCursor = 0; + d->inFlags = eatEscape_InputWidgetFlag; iZap(d->mark); setMaxLen_InputWidget(d, maxLen); - /* Caller must arrange the width, but the height is fixed. */ - w->rect.size.y = lineHeight_Text(default_FontId) + 2 * gap_UI; -#if defined (iPlatformAppleMobile) - w->rect.size.y += 2 * gap_UI; -#endif setFlags_Widget(w, fixedHeight_WidgetFlag, iTrue); init_Click(&d->click, d, SDL_BUTTON_LEFT); d->timer = 0; d->cursorVis = 0; d->buffered = NULL; + updateMetrics_InputWidget_(d); } void deinit_InputWidget(iInputWidget *d) { @@ -226,13 +240,6 @@ static iString *visText_InputWidget_(const iInputWidget *d) { return text; } -static void invalidateBuffered_InputWidget_(iInputWidget *d) { - if (d->buffered) { - delete_TextBuf(d->buffered); - d->buffered = NULL; - } -} - static void updateBuffered_InputWidget_(iInputWidget *d) { invalidateBuffered_InputWidget_(d); iString *visText = visText_InputWidget_(d); @@ -600,6 +607,9 @@ static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) { } return iFalse; } + else if (isMetricsChange_UserEvent(ev)) { + updateMetrics_InputWidget_(d); + } else if (isFocused_Widget(d) && isCommand_UserEvent(ev, "copy")) { copy_InputWidget_(d, iFalse); return iTrue; -- cgit v1.2.3