diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-03-04 22:24:26 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-03-04 22:24:43 +0200 |
commit | 35f60fa0da324ee79923d8a730cf4f10dbb6ccdb (patch) | |
tree | 3de80c1a65333a62e3cebedce339a9386f4ce8dc /src/ui/util.c | |
parent | 900b449a5dbe8cbf08c7ad54662b1c3067093356 (diff) |
LabelWidget: Added an optional icon
Label icons are intended for context menus.
Diffstat (limited to 'src/ui/util.c')
-rw-r--r-- | src/ui/util.c | 46 |
1 files changed, 33 insertions, 13 deletions
diff --git a/src/ui/util.c b/src/ui/util.c index 055191c7..a36eb1a7 100644 --- a/src/ui/util.c +++ b/src/ui/util.c | |||
@@ -458,13 +458,17 @@ iWidget *makeMenu_Widget(iWidget *parent, const iMenuItem *items, size_t n) { | |||
458 | setFrameColor_Widget(menu, uiSeparator_ColorId); | 458 | setFrameColor_Widget(menu, uiSeparator_ColorId); |
459 | setBackgroundColor_Widget(menu, uiBackground_ColorId); | 459 | setBackgroundColor_Widget(menu, uiBackground_ColorId); |
460 | if (deviceType_App() != desktop_AppDeviceType) { | 460 | if (deviceType_App() != desktop_AppDeviceType) { |
461 | setPadding1_Widget(menu, gap_UI); | 461 | setPadding1_Widget(menu, 2 * gap_UI); |
462 | } | 462 | } |
463 | setFlags_Widget(menu, | 463 | setFlags_Widget(menu, |
464 | keepOnTop_WidgetFlag | collapse_WidgetFlag | hidden_WidgetFlag | | 464 | keepOnTop_WidgetFlag | collapse_WidgetFlag | hidden_WidgetFlag | |
465 | arrangeVertical_WidgetFlag | arrangeSize_WidgetFlag | | 465 | arrangeVertical_WidgetFlag | arrangeSize_WidgetFlag | |
466 | resizeChildrenToWidestChild_WidgetFlag | overflowScrollable_WidgetFlag, | 466 | resizeChildrenToWidestChild_WidgetFlag | overflowScrollable_WidgetFlag, |
467 | iTrue); | 467 | iTrue); |
468 | const iBool isPortraitPhone = (deviceType_App() == phone_AppDeviceType && isPortrait_App()); | ||
469 | int64_t itemFlags = (deviceType_App() != desktop_AppDeviceType ? 0 : 0) | | ||
470 | (isPortraitPhone ? extraPadding_WidgetFlag : 0); | ||
471 | iBool haveIcons = iFalse; | ||
468 | for (size_t i = 0; i < n; ++i) { | 472 | for (size_t i = 0; i < n; ++i) { |
469 | const iMenuItem *item = &items[i]; | 473 | const iMenuItem *item = &items[i]; |
470 | if (equal_CStr(item->label, "---")) { | 474 | if (equal_CStr(item->label, "---")) { |
@@ -474,22 +478,27 @@ iWidget *makeMenu_Widget(iWidget *parent, const iMenuItem *items, size_t n) { | |||
474 | iLabelWidget *label = addChildFlags_Widget( | 478 | iLabelWidget *label = addChildFlags_Widget( |
475 | menu, | 479 | menu, |
476 | iClob(newKeyMods_LabelWidget(item->label, item->key, item->kmods, item->command)), | 480 | iClob(newKeyMods_LabelWidget(item->label, item->key, item->kmods, item->command)), |
477 | frameless_WidgetFlag | alignLeft_WidgetFlag | drawKey_WidgetFlag); | 481 | frameless_WidgetFlag | alignLeft_WidgetFlag | drawKey_WidgetFlag | itemFlags); |
482 | haveIcons |= checkIcon_LabelWidget(label); | ||
478 | updateSize_LabelWidget(label); /* drawKey was set */ | 483 | updateSize_LabelWidget(label); /* drawKey was set */ |
479 | const iBool isCaution = startsWith_CStr(item->label, uiTextCaution_ColorEscape); | ||
480 | if (deviceType_App() == tablet_AppDeviceType) { | ||
481 | setFont_LabelWidget(label, isCaution ? uiContentBold_FontId : uiContent_FontId); | ||
482 | } | ||
483 | else if (deviceType_App() == desktop_AppDeviceType) { | ||
484 | setFont_LabelWidget(label, isCaution ? uiLabelBold_FontId : uiLabel_FontId); | ||
485 | } | ||
486 | } | 484 | } |
487 | } | 485 | } |
488 | if (deviceType_App() == phone_AppDeviceType) { | 486 | if (deviceType_App() == phone_AppDeviceType) { |
489 | addChild_Widget(menu, iClob(makeMenuSeparator_())); | 487 | addChild_Widget(menu, iClob(makeMenuSeparator_())); |
490 | setFont_LabelWidget(addChildFlags_Widget(menu, iClob(new_LabelWidget("Cancel", "cancel")), | 488 | addChildFlags_Widget(menu, |
491 | frameless_WidgetFlag | alignLeft_WidgetFlag), | 489 | iClob(new_LabelWidget("Cancel", "cancel")), |
492 | defaultBig_FontId); | 490 | itemFlags | frameless_WidgetFlag | alignLeft_WidgetFlag); |
491 | } | ||
492 | if (haveIcons) { | ||
493 | /* All items must have icons if at least one of them has. */ | ||
494 | iForEach(ObjectList, i, children_Widget(menu)) { | ||
495 | if (isInstance_Object(i.object, &Class_LabelWidget)) { | ||
496 | iLabelWidget *label = i.object; | ||
497 | if (icon_LabelWidget(label) == 0) { | ||
498 | setIcon_LabelWidget(label, ' '); | ||
499 | } | ||
500 | } | ||
501 | } | ||
493 | } | 502 | } |
494 | addChild_Widget(parent, iClob(menu)); | 503 | addChild_Widget(parent, iClob(menu)); |
495 | setCommandHandler_Widget(menu, menuHandler_); | 504 | setCommandHandler_Widget(menu, menuHandler_); |
@@ -512,10 +521,21 @@ void openMenu_Widget(iWidget *d, iInt2 coord) { | |||
512 | setFlags_Widget(d, arrangeWidth_WidgetFlag | resizeChildrenToWidestChild_WidgetFlag, iFalse); | 521 | setFlags_Widget(d, arrangeWidth_WidgetFlag | resizeChildrenToWidestChild_WidgetFlag, iFalse); |
513 | setFlags_Widget(d, resizeWidthOfChildren_WidgetFlag, iTrue); | 522 | setFlags_Widget(d, resizeWidthOfChildren_WidgetFlag, iTrue); |
514 | d->rect.size.x = rootSize_Window(get_Window()).x; | 523 | d->rect.size.x = rootSize_Window(get_Window()).x; |
524 | } | ||
525 | /* Update item fonts. */ { | ||
515 | iForEach(ObjectList, i, children_Widget(d)) { | 526 | iForEach(ObjectList, i, children_Widget(d)) { |
516 | if (isInstance_Object(i.object, &Class_LabelWidget)) { | 527 | if (isInstance_Object(i.object, &Class_LabelWidget)) { |
517 | iLabelWidget *label = i.object; | 528 | iLabelWidget *label = i.object; |
518 | setFont_LabelWidget(label, defaultBig_FontId); | 529 | const iBool isCaution = startsWith_String(text_LabelWidget(label), uiTextCaution_ColorEscape); |
530 | if (deviceType_App() == desktop_AppDeviceType) { | ||
531 | setFont_LabelWidget(label, isCaution ? uiLabelBold_FontId : uiLabel_FontId); | ||
532 | } | ||
533 | else if (isPortraitPhone) { | ||
534 | setFont_LabelWidget(label, isCaution ? defaultBigBold_FontId : defaultBig_FontId); | ||
535 | } | ||
536 | else { | ||
537 | setFont_LabelWidget(label, isCaution ? uiContentBold_FontId : uiContent_FontId); | ||
538 | } | ||
519 | } | 539 | } |
520 | } | 540 | } |
521 | } | 541 | } |