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/labelwidget.c | |
parent | ce7f402193aef282972660c9cd22875409a86964 (diff) |
Mobile: Fixed dialog field misalignments
Diffstat (limited to 'src/ui/labelwidget.c')
-rw-r--r-- | src/ui/labelwidget.c | 45 |
1 files changed, 29 insertions, 16 deletions
diff --git a/src/ui/labelwidget.c b/src/ui/labelwidget.c index 43f88277..16fee26d 100644 --- a/src/ui/labelwidget.c +++ b/src/ui/labelwidget.c | |||
@@ -29,15 +29,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ | |||
29 | #include "util.h" | 29 | #include "util.h" |
30 | #include "keys.h" | 30 | #include "keys.h" |
31 | 31 | ||
32 | iLocalDef iInt2 padding_(int64_t flags) { | ||
33 | #if defined (iPlatformAppleMobile) | ||
34 | return init_I2(flags & tight_WidgetFlag ? 2 * gap_UI : (4 * gap_UI), | ||
35 | (flags & extraPadding_WidgetFlag ? 1.5f : 1) * 3 * gap_UI / 2); | ||
36 | #else | ||
37 | return init_I2(flags & tight_WidgetFlag ? 3 * gap_UI / 2 : (3 * gap_UI), gap_UI); | ||
38 | #endif | ||
39 | } | ||
40 | |||
41 | struct Impl_LabelWidget { | 32 | struct Impl_LabelWidget { |
42 | iWidget widget; | 33 | iWidget widget; |
43 | iString srcLabel; | 34 | iString srcLabel; |
@@ -52,6 +43,24 @@ struct Impl_LabelWidget { | |||
52 | iClick click; | 43 | iClick click; |
53 | }; | 44 | }; |
54 | 45 | ||
46 | static iInt2 padding_LabelWidget_(const iLabelWidget *d, int corner) { | ||
47 | const iWidget *w = constAs_Widget(d); | ||
48 | const int64_t flags = flags_Widget(w); | ||
49 | const iInt2 widgetPad = (corner == 0 ? init_I2(w->padding[0], w->padding[1]) | ||
50 | : corner == 1 ? init_I2(w->padding[2], w->padding[1]) | ||
51 | : corner == 2 ? init_I2(w->padding[2], w->padding[3]) | ||
52 | : init_I2(w->padding[0], w->padding[3])); | ||
53 | #if defined (iPlatformAppleMobile) | ||
54 | return add_I2(widgetPad, | ||
55 | init_I2(flags & tight_WidgetFlag ? 2 * gap_UI : (4 * gap_UI), | ||
56 | (flags & extraPadding_WidgetFlag ? 1.5f : 1) * 3 * gap_UI / 2)); | ||
57 | #else | ||
58 | return add_I2(widgetPad, | ||
59 | init_I2(flags & tight_WidgetFlag ? 3 * gap_UI / 2 : (3 * gap_UI), | ||
60 | gap_UI)); | ||
61 | #endif | ||
62 | } | ||
63 | |||
55 | iDefineObjectConstructionArgs(LabelWidget, | 64 | iDefineObjectConstructionArgs(LabelWidget, |
56 | (const char *label, const char *cmd), | 65 | (const char *label, const char *cmd), |
57 | label, cmd) | 66 | label, cmd) |
@@ -268,7 +277,7 @@ static void draw_LabelWidget_(const iLabelWidget *d) { | |||
268 | d->font, | 277 | d->font, |
269 | (iRect){ | 278 | (iRect){ |
270 | /* The icon position is fine-tuned; c.f. high baseline of Source Sans Pro. */ | 279 | /* The icon position is fine-tuned; c.f. high baseline of Source Sans Pro. */ |
271 | add_I2(add_I2(bounds.pos, padding_(flags)), | 280 | add_I2(add_I2(bounds.pos, padding_LabelWidget_(d, 0)), |
272 | init_I2((flags & extraPadding_WidgetFlag ? -2 : -1.20f) * gap_UI + | 281 | init_I2((flags & extraPadding_WidgetFlag ? -2 : -1.20f) * gap_UI + |
273 | (deviceType_App() == tablet_AppDeviceType ? -gap_UI : 0), | 282 | (deviceType_App() == tablet_AppDeviceType ? -gap_UI : 0), |
274 | -gap_UI / 8)), | 283 | -gap_UI / 8)), |
@@ -288,14 +297,15 @@ static void draw_LabelWidget_(const iLabelWidget *d) { | |||
288 | drawWrapRange_Text(d->font, topLeft_Rect(inner), wrap, fg, range_String(&d->label)); | 297 | drawWrapRange_Text(d->font, topLeft_Rect(inner), wrap, fg, range_String(&d->label)); |
289 | } | 298 | } |
290 | else if (flags & alignLeft_WidgetFlag) { | 299 | else if (flags & alignLeft_WidgetFlag) { |
291 | draw_Text(d->font, add_I2(bounds.pos, addX_I2(padding_(flags), iconPad)), fg, cstr_String(&d->label)); | 300 | draw_Text(d->font, add_I2(bounds.pos, addX_I2(padding_LabelWidget_(d, 0), iconPad)), |
301 | fg, cstr_String(&d->label)); | ||
292 | if ((flags & drawKey_WidgetFlag) && d->key) { | 302 | if ((flags & drawKey_WidgetFlag) && d->key) { |
293 | iString str; | 303 | iString str; |
294 | init_String(&str); | 304 | init_String(&str); |
295 | keyStr_LabelWidget_(d, &str); | 305 | keyStr_LabelWidget_(d, &str); |
296 | drawAlign_Text(uiShortcuts_FontId, | 306 | drawAlign_Text(uiShortcuts_FontId, |
297 | add_I2(topRight_Rect(bounds), | 307 | add_I2(topRight_Rect(bounds), |
298 | addX_I2(negX_I2(padding_(flags)), | 308 | addX_I2(negX_I2(padding_LabelWidget_(d, 1)), |
299 | deviceType_App() == tablet_AppDeviceType ? gap_UI : 0)), | 309 | deviceType_App() == tablet_AppDeviceType ? gap_UI : 0)), |
300 | flags & pressed_WidgetFlag ? fg | 310 | flags & pressed_WidgetFlag ? fg |
301 | : isCaution ? uiTextCaution_ColorId | 311 | : isCaution ? uiTextCaution_ColorId |
@@ -308,14 +318,16 @@ static void draw_LabelWidget_(const iLabelWidget *d) { | |||
308 | else if (flags & alignRight_WidgetFlag) { | 318 | else if (flags & alignRight_WidgetFlag) { |
309 | drawAlign_Text( | 319 | drawAlign_Text( |
310 | d->font, | 320 | d->font, |
311 | add_I2(topRight_Rect(bounds), negX_I2(padding_(flags))), | 321 | add_I2(topRight_Rect(bounds), negX_I2(padding_LabelWidget_(d, 1))), |
312 | fg, | 322 | fg, |
313 | right_Alignment, | 323 | right_Alignment, |
314 | cstr_String(&d->label)); | 324 | cstr_String(&d->label)); |
315 | } | 325 | } |
316 | else { | 326 | else { |
317 | drawCentered_Text(d->font, | 327 | drawCentered_Text(d->font, |
318 | adjusted_Rect(bounds, init_I2(iconPad, 0), zero_I2()), | 328 | adjusted_Rect(bounds, |
329 | add_I2(zero_I2(), init_I2(iconPad, 0)), | ||
330 | neg_I2(zero_I2())), | ||
319 | d->alignVisual, | 331 | d->alignVisual, |
320 | fg, | 332 | fg, |
321 | "%s", | 333 | "%s", |
@@ -327,7 +339,7 @@ static void draw_LabelWidget_(const iLabelWidget *d) { | |||
327 | drawCentered_Text(d->font, | 339 | drawCentered_Text(d->font, |
328 | (iRect){ addX_I2(topRight_Rect(chRect), -iconPad), | 340 | (iRect){ addX_I2(topRight_Rect(chRect), -iconPad), |
329 | init_I2(chSize, height_Rect(chRect)) }, | 341 | init_I2(chSize, height_Rect(chRect)) }, |
330 | iTrue, fg, rightAngle_Icon); | 342 | iTrue, uiSeparator_ColorId, rightAngle_Icon); |
331 | } | 343 | } |
332 | unsetClip_Paint(&p); | 344 | unsetClip_Paint(&p); |
333 | } | 345 | } |
@@ -347,7 +359,8 @@ static void sizeChanged_LabelWidget_(iLabelWidget *d) { | |||
347 | iInt2 defaultSize_LabelWidget(const iLabelWidget *d) { | 359 | iInt2 defaultSize_LabelWidget(const iLabelWidget *d) { |
348 | const iWidget *w = constAs_Widget(d); | 360 | const iWidget *w = constAs_Widget(d); |
349 | const int64_t flags = flags_Widget(w); | 361 | const int64_t flags = flags_Widget(w); |
350 | iInt2 size = add_I2(measure_Text(d->font, cstr_String(&d->label)), muli_I2(padding_(flags), 2)); | 362 | iInt2 size = add_I2(measure_Text(d->font, cstr_String(&d->label)), |
363 | add_I2(padding_LabelWidget_(d, 0), padding_LabelWidget_(d, 2))); | ||
351 | if ((flags & drawKey_WidgetFlag) && d->key) { | 364 | if ((flags & drawKey_WidgetFlag) && d->key) { |
352 | iString str; | 365 | iString str; |
353 | init_String(&str); | 366 | init_String(&str); |