diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-04-09 11:19:50 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-04-09 11:19:50 +0300 |
commit | 1496aeacf167dd647fdd30a6d2687ebcb4b126b1 (patch) | |
tree | 3e7166425da72a533eaf888a5aa9eb6462328141 /src/ui/inputwidget.c | |
parent | ce7f402193aef282972660c9cd22875409a86964 (diff) |
Mobile: Fixed dialog field misalignments
Diffstat (limited to 'src/ui/inputwidget.c')
-rw-r--r-- | src/ui/inputwidget.c | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c index 74376a18..df5eb0df 100644 --- a/src/ui/inputwidget.c +++ b/src/ui/inputwidget.c | |||
@@ -119,13 +119,29 @@ static void invalidateBuffered_InputWidget_(iInputWidget *d) { | |||
119 | } | 119 | } |
120 | } | 120 | } |
121 | 121 | ||
122 | static void updateSizeForFixedLength_InputWidget_(iInputWidget *d) { | ||
123 | if (d->maxLen) { | ||
124 | /* Set a fixed size based on maximum possible width of the text. */ | ||
125 | iBlock *content = new_Block(d->maxLen); | ||
126 | fill_Block(content, 'M'); | ||
127 | int extraHeight = (flags_Widget(as_Widget(d)) & extraPadding_WidgetFlag ? 2 * gap_UI : 0); | ||
128 | setFixedSize_Widget( | ||
129 | as_Widget(d), | ||
130 | add_I2(measure_Text(d->font, cstr_Block(content)), | ||
131 | init_I2(6 * gap_UI + d->leftPadding + d->rightPadding, | ||
132 | 2 * gap_UI + extraHeight))); | ||
133 | delete_Block(content); | ||
134 | } | ||
135 | } | ||
136 | |||
122 | static void updateMetrics_InputWidget_(iInputWidget *d) { | 137 | static void updateMetrics_InputWidget_(iInputWidget *d) { |
123 | iWidget *w = as_Widget(d); | 138 | iWidget *w = as_Widget(d); |
139 | updateSizeForFixedLength_InputWidget_(d); | ||
124 | /* Caller must arrange the width, but the height is fixed. */ | 140 | /* Caller must arrange the width, but the height is fixed. */ |
125 | w->rect.size.y = lineHeight_Text(d->font) * 1.3f; | 141 | w->rect.size.y = lineHeight_Text(d->font) * 1.3f; |
126 | #if defined (iPlatformMobile) | 142 | if (flags_Widget(w) & extraPadding_WidgetFlag) { |
127 | w->rect.size.y += 2 * gap_UI; | 143 | w->rect.size.y += 2 * gap_UI; |
128 | #endif | 144 | } |
129 | invalidateBuffered_InputWidget_(d); | 145 | invalidateBuffered_InputWidget_(d); |
130 | if (parent_Widget(w)) { | 146 | if (parent_Widget(w)) { |
131 | arrange_Widget(w); | 147 | arrange_Widget(w); |
@@ -136,6 +152,9 @@ void init_InputWidget(iInputWidget *d, size_t maxLen) { | |||
136 | iWidget *w = &d->widget; | 152 | iWidget *w = &d->widget; |
137 | init_Widget(w); | 153 | init_Widget(w); |
138 | setFlags_Widget(w, focusable_WidgetFlag | hover_WidgetFlag | touchDrag_WidgetFlag, iTrue); | 154 | setFlags_Widget(w, focusable_WidgetFlag | hover_WidgetFlag | touchDrag_WidgetFlag, iTrue); |
155 | #if defined (iPlatformMobile) | ||
156 | setFlags_Widget(w, extraPadding_WidgetFlag, iTrue); | ||
157 | #endif | ||
139 | init_Array(&d->text, sizeof(iChar)); | 158 | init_Array(&d->text, sizeof(iChar)); |
140 | init_Array(&d->oldText, sizeof(iChar)); | 159 | init_Array(&d->oldText, sizeof(iChar)); |
141 | init_String(&d->hint); | 160 | init_String(&d->hint); |
@@ -244,15 +263,7 @@ iInputWidgetContentPadding contentPadding_InputWidget(const iInputWidget *d) { | |||
244 | void setMaxLen_InputWidget(iInputWidget *d, size_t maxLen) { | 263 | void setMaxLen_InputWidget(iInputWidget *d, size_t maxLen) { |
245 | d->maxLen = maxLen; | 264 | d->maxLen = maxLen; |
246 | d->mode = (maxLen == 0 ? insert_InputMode : overwrite_InputMode); | 265 | d->mode = (maxLen == 0 ? insert_InputMode : overwrite_InputMode); |
247 | if (maxLen) { | 266 | updateSizeForFixedLength_InputWidget_(d); |
248 | /* Set a fixed size. */ | ||
249 | iBlock *content = new_Block(maxLen); | ||
250 | fill_Block(content, 'M'); | ||
251 | setFixedSize_Widget( | ||
252 | as_Widget(d), | ||
253 | add_I2(measure_Text(d->font, cstr_Block(content)), init_I2(6 * gap_UI, 2 * gap_UI))); | ||
254 | delete_Block(content); | ||
255 | } | ||
256 | } | 267 | } |
257 | 268 | ||
258 | void setHint_InputWidget(iInputWidget *d, const char *hintText) { | 269 | void setHint_InputWidget(iInputWidget *d, const char *hintText) { |
@@ -269,6 +280,7 @@ void setContentPadding_InputWidget(iInputWidget *d, int left, int right) { | |||
269 | if (right >= 0) { | 280 | if (right >= 0) { |
270 | d->rightPadding = right; | 281 | d->rightPadding = right; |
271 | } | 282 | } |
283 | updateSizeForFixedLength_InputWidget_(d); | ||
272 | refresh_Widget(d); | 284 | refresh_Widget(d); |
273 | } | 285 | } |
274 | 286 | ||