diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2022-01-02 15:21:47 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2022-01-02 15:21:47 +0200 |
commit | 6ec19264f26d79009d582bd35d82e108632a326e (patch) | |
tree | d1fc55c9945c6b9f99ac030ef32f28ea17b1e7ff | |
parent | 45f08515cbe6741ccb31add70575a3207e2c3e83 (diff) |
Mobile: Tweaking URL input widget padding
Portrait phone URL input field has some special padding rules. This should be done elsewhere (updateMetrics_Root?), but InputWidget does not check the Widget paddings currently.
-rw-r--r-- | src/ui/inputwidget.c | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c index 5d74f855..7ceb59c1 100644 --- a/src/ui/inputwidget.c +++ b/src/ui/inputwidget.c | |||
@@ -59,7 +59,6 @@ static const int unlimitedWidth_InputWidget_ = 1000000; /* TODO: WrapText di | |||
59 | static const iChar sensitiveChar_ = 0x25cf; /* black circle */ | 59 | static const iChar sensitiveChar_ = 0x25cf; /* black circle */ |
60 | static const char * sensitive_ = "\u25cf"; | 60 | static const char * sensitive_ = "\u25cf"; |
61 | 61 | ||
62 | #define extraPaddingHeight_ ((isPortraitPhone_App() ? 3.0f : 1.25f) * gap_UI) /* phone: proper tap target */ | ||
63 | #define minWidth_InputWidget_ (3 * gap_UI) | 62 | #define minWidth_InputWidget_ (3 * gap_UI) |
64 | 63 | ||
65 | static void enableEditorKeysInMenus_(iBool enable) { | 64 | static void enableEditorKeysInMenus_(iBool enable) { |
@@ -266,6 +265,15 @@ struct Impl_InputWidget { | |||
266 | 265 | ||
267 | iDefineObjectConstructionArgs(InputWidget, (size_t maxLen), maxLen) | 266 | iDefineObjectConstructionArgs(InputWidget, (size_t maxLen), maxLen) |
268 | 267 | ||
268 | static int extraPaddingHeight_InputWidget_(const iInputWidget *d) { | ||
269 | if (isPortraitPhone_App() && !cmp_String(id_Widget(&d->widget), "url")) { | ||
270 | /* Special case: the URL input field gets taller in portrait phone mode to make | ||
271 | the tap target more generous. */ | ||
272 | return 2.5f * gap_UI; | ||
273 | } | ||
274 | return 1.25f * gap_UI; | ||
275 | } | ||
276 | |||
269 | static void restoreBackup_InputWidget_(iInputWidget *d) { | 277 | static void restoreBackup_InputWidget_(iInputWidget *d) { |
270 | if (!d->backupPath) return; | 278 | if (!d->backupPath) return; |
271 | iFile *f = new_File(d->backupPath); | 279 | iFile *f = new_File(d->backupPath); |
@@ -370,7 +378,15 @@ static iRect contentBounds_InputWidget_(const iInputWidget *d) { | |||
370 | shrink_Rect(&bounds, init_I2(gap_UI * (flags_Widget(w) & tight_WidgetFlag ? 1 : 2), 0)); | 378 | shrink_Rect(&bounds, init_I2(gap_UI * (flags_Widget(w) & tight_WidgetFlag ? 1 : 2), 0)); |
371 | bounds.pos.y += padding_().y / 2; | 379 | bounds.pos.y += padding_().y / 2; |
372 | if (flags_Widget(w) & extraPadding_WidgetFlag) { | 380 | if (flags_Widget(w) & extraPadding_WidgetFlag) { |
373 | bounds.pos.y += extraPaddingHeight_ / 2; | 381 | if (d->sysCtrl && !cmp_String(id_Widget(w), "url")) { |
382 | /* TODO: This is super hacky: the native UI control would be offset incorrectly. | ||
383 | These paddings/offsets are getting a bit ridiculous, should rethink the whole thing. | ||
384 | Use the Widget paddings! */ | ||
385 | bounds.pos.y += 1.25f * gap_UI / 2; | ||
386 | } | ||
387 | else { | ||
388 | bounds.pos.y += extraPaddingHeight_InputWidget_(d) / 2; | ||
389 | } | ||
374 | } | 390 | } |
375 | return bounds; | 391 | return bounds; |
376 | } | 392 | } |
@@ -627,7 +643,7 @@ static void updateSizeForFixedLength_InputWidget_(iInputWidget *d) { | |||
627 | /* Set a fixed size based on maximum possible width of the text. */ | 643 | /* Set a fixed size based on maximum possible width of the text. */ |
628 | iBlock *content = new_Block(d->maxLen); | 644 | iBlock *content = new_Block(d->maxLen); |
629 | fill_Block(content, 'M'); | 645 | fill_Block(content, 'M'); |
630 | int extraHeight = (flags_Widget(as_Widget(d)) & extraPadding_WidgetFlag ? extraPaddingHeight_ : 0); | 646 | int extraHeight = (flags_Widget(as_Widget(d)) & extraPadding_WidgetFlag ? extraPaddingHeight_InputWidget_(d) : 0); |
631 | setFixedSize_Widget( | 647 | setFixedSize_Widget( |
632 | as_Widget(d), | 648 | as_Widget(d), |
633 | add_I2(measure_Text(d->font, cstr_Block(content)).bounds.size, | 649 | add_I2(measure_Text(d->font, cstr_Block(content)).bounds.size, |
@@ -774,7 +790,7 @@ static void updateMetrics_InputWidget_(iInputWidget *d) { | |||
774 | const int oldHeight = height_Rect(w->rect); | 790 | const int oldHeight = height_Rect(w->rect); |
775 | w->rect.size.y = contentHeight_InputWidget_(d) + 3.0f * padding_().y; /* TODO: Why 3x? */ | 791 | w->rect.size.y = contentHeight_InputWidget_(d) + 3.0f * padding_().y; /* TODO: Why 3x? */ |
776 | if (flags_Widget(w) & extraPadding_WidgetFlag) { | 792 | if (flags_Widget(w) & extraPadding_WidgetFlag) { |
777 | w->rect.size.y += extraPaddingHeight_; | 793 | w->rect.size.y += extraPaddingHeight_InputWidget_(d); |
778 | } | 794 | } |
779 | invalidateBuffered_InputWidget_(d); | 795 | invalidateBuffered_InputWidget_(d); |
780 | if (height_Rect(w->rect) != oldHeight) { | 796 | if (height_Rect(w->rect) != oldHeight) { |
@@ -1679,7 +1695,7 @@ static iRect bounds_InputWidget_(const iInputWidget *d) { | |||
1679 | /* There may be more visible lines than fits in the widget bounds. */ | 1695 | /* There may be more visible lines than fits in the widget bounds. */ |
1680 | bounds.size.y = contentHeight_InputWidget_(d) + 3 * padding_().y; | 1696 | bounds.size.y = contentHeight_InputWidget_(d) + 3 * padding_().y; |
1681 | if (w->flags & extraPadding_WidgetFlag) { | 1697 | if (w->flags & extraPadding_WidgetFlag) { |
1682 | bounds.size.y += extraPaddingHeight_; | 1698 | bounds.size.y += extraPaddingHeight_InputWidget_(d); |
1683 | } | 1699 | } |
1684 | return bounds; | 1700 | return bounds; |
1685 | } | 1701 | } |