summaryrefslogtreecommitdiff
path: root/src/ui/sidebarwidget.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/sidebarwidget.c')
-rw-r--r--src/ui/sidebarwidget.c76
1 files changed, 57 insertions, 19 deletions
diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c
index da76c4d4..b1dfc378 100644
--- a/src/ui/sidebarwidget.c
+++ b/src/ui/sidebarwidget.c
@@ -451,6 +451,10 @@ static const char *tightModeLabels_[max_SidebarMode] = {
451 "\U0001f5b9", 451 "\U0001f5b9",
452}; 452};
453 453
454const char *icon_SidebarMode(enum iSidebarMode mode) {
455 return tightModeLabels_[mode];
456}
457
454void init_SidebarWidget(iSidebarWidget *d, enum iSidebarSide side) { 458void init_SidebarWidget(iSidebarWidget *d, enum iSidebarSide side) {
455 iWidget *w = as_Widget(d); 459 iWidget *w = as_Widget(d);
456 init_Widget(w); 460 init_Widget(w);
@@ -470,28 +474,43 @@ void init_SidebarWidget(iSidebarWidget *d, enum iSidebarSide side) {
470 d->width = 73 * gap_UI; 474 d->width = 73 * gap_UI;
471#endif 475#endif
472 setFlags_Widget(w, fixedWidth_WidgetFlag, iTrue); 476 setFlags_Widget(w, fixedWidth_WidgetFlag, iTrue);
473 d->maxButtonLabelWidth = 0;
474 iWidget *vdiv = makeVDiv_Widget(); 477 iWidget *vdiv = makeVDiv_Widget();
475 addChildFlags_Widget(w, vdiv, resizeToParentWidth_WidgetFlag | resizeToParentHeight_WidgetFlag); 478 addChildFlags_Widget(w, vdiv, resizeToParentWidth_WidgetFlag | resizeToParentHeight_WidgetFlag);
476 iWidget *buttons = new_Widget(); 479 if (deviceType_App() == phone_AppDeviceType && d->side == left_SideBarSide) {
477 for (int i = 0; i < max_SidebarMode; i++) {
478 d->modeButtons[i] = addChildFlags_Widget(
479 buttons,
480 iClob(new_LabelWidget(
481 tightModeLabels_[i],
482 format_CStr("%s.mode arg:%d", cstr_String(id_Widget(w)), i))),
483 frameless_WidgetFlag);
484 d->maxButtonLabelWidth =
485 iMaxi(d->maxButtonLabelWidth,
486 3 * gap_UI + measure_Text(uiLabel_FontId, normalModeLabels_[i]).x);
487 } 480 }
488 addChildFlags_Widget(vdiv, 481 iZap(d->modeButtons);
489 iClob(buttons), 482 /* On a phone, the right sidebar is used exclusively for Identities. */
490 arrangeHorizontal_WidgetFlag | resizeWidthOfChildren_WidgetFlag | 483 const iBool isPhone = deviceType_App() == phone_AppDeviceType;
484 if (!isPhone || d->side == left_SideBarSide) {
485 iWidget *buttons = new_Widget();
486 setId_Widget(buttons, "buttons");
487 for (int i = 0; i < max_SidebarMode; i++) {
488 if (deviceType_App() == phone_AppDeviceType && i == identities_SidebarMode) {
489 continue;
490 }
491 d->modeButtons[i] = addChildFlags_Widget(
492 buttons,
493 iClob(new_LabelWidget(
494 tightModeLabels_[i],
495 format_CStr("%s.mode arg:%d", cstr_String(id_Widget(w)), i))),
496 frameless_WidgetFlag | (isPhone ? noBackground_WidgetFlag : 0));
497 }
498 setButtonFont_SidebarWidget(d, isPhone ? uiLabelLarge_FontId : uiLabel_FontId);
499 addChildFlags_Widget(vdiv,
500 iClob(buttons),
501 arrangeHorizontal_WidgetFlag | resizeWidthOfChildren_WidgetFlag |
491 arrangeHeight_WidgetFlag | resizeToParentWidth_WidgetFlag | 502 arrangeHeight_WidgetFlag | resizeToParentWidth_WidgetFlag |
492 drawBackgroundToHorizontalSafeArea_WidgetFlag); 503 drawBackgroundToHorizontalSafeArea_WidgetFlag);
493 if (deviceType_App() == phone_AppDeviceType) { 504 if (deviceType_App() == phone_AppDeviceType) {
494 setBackgroundColor_Widget(buttons, uiBackground_ColorId); 505 setBackgroundColor_Widget(buttons, uiBackground_ColorId);
506 }
507 }
508 else {
509 iLabelWidget *heading = new_LabelWidget("Identities", NULL);
510 setBackgroundColor_Widget(as_Widget(heading), uiBackgroundUnfocusedSelection_ColorId);
511 setTextColor_LabelWidget(heading, uiIcon_ColorId);
512 setFont_LabelWidget(addChild_Widget(vdiv, iClob(heading)),
513 uiLabelLarge_FontId);
495 } 514 }
496 iWidget *content = new_Widget(); 515 iWidget *content = new_Widget();
497 setFlags_Widget(content, resizeChildren_WidgetFlag, iTrue); 516 setFlags_Widget(content, resizeChildren_WidgetFlag, iTrue);
@@ -502,7 +521,9 @@ void init_SidebarWidget(iSidebarWidget *d, enum iSidebarSide side) {
502 d->blank = new_Widget(); 521 d->blank = new_Widget();
503 addChildFlags_Widget(content, iClob(d->blank), resizeChildren_WidgetFlag); 522 addChildFlags_Widget(content, iClob(d->blank), resizeChildren_WidgetFlag);
504 addChildFlags_Widget(vdiv, iClob(content), expand_WidgetFlag); 523 addChildFlags_Widget(vdiv, iClob(content), expand_WidgetFlag);
505 setMode_SidebarWidget(d, bookmarks_SidebarMode); 524 setMode_SidebarWidget(d,
525 deviceType_App() == phone_AppDeviceType && d->side == right_SideBarSide ?
526 identities_SidebarMode : bookmarks_SidebarMode);
506 d->resizer = 527 d->resizer =
507 addChildFlags_Widget(w, 528 addChildFlags_Widget(w,
508 iClob(new_Widget()), 529 iClob(new_Widget()),
@@ -524,6 +545,18 @@ void deinit_SidebarWidget(iSidebarWidget *d) {
524 deinit_String(&d->cmdPrefix); 545 deinit_String(&d->cmdPrefix);
525} 546}
526 547
548void setButtonFont_SidebarWidget(iSidebarWidget *d, int font) {
549 d->maxButtonLabelWidth = 0;
550 for (int i = 0; i < max_SidebarMode; i++) {
551 if (d->modeButtons[i]) {
552 setFont_LabelWidget(d->modeButtons[i], font);
553 d->maxButtonLabelWidth =
554 iMaxi(d->maxButtonLabelWidth,
555 3 * gap_UI + measure_Text(font, normalModeLabels_[i]).x);
556 }
557 }
558}
559
527static const iGmIdentity *constHoverIdentity_SidebarWidget_(const iSidebarWidget *d) { 560static const iGmIdentity *constHoverIdentity_SidebarWidget_(const iSidebarWidget *d) {
528 if (d->mode == identities_SidebarMode) { 561 if (d->mode == identities_SidebarMode) {
529 const iSidebarItem *hoverItem = constHoverItem_ListWidget(d->list); 562 const iSidebarItem *hoverItem = constHoverItem_ListWidget(d->list);
@@ -591,9 +624,11 @@ static void itemClicked_SidebarWidget_(iSidebarWidget *d, const iSidebarItem *it
591} 624}
592 625
593static void checkModeButtonLayout_SidebarWidget_(iSidebarWidget *d) { 626static void checkModeButtonLayout_SidebarWidget_(iSidebarWidget *d) {
627 if (!d->modeButtons[0]) return;
594 const iBool isTight = 628 const iBool isTight =
595 (width_Rect(bounds_Widget(as_Widget(d->modeButtons[0]))) < d->maxButtonLabelWidth); 629 (width_Rect(bounds_Widget(as_Widget(d->modeButtons[0]))) < d->maxButtonLabelWidth);
596 for (int i = 0; i < max_SidebarMode; i++) { 630 for (int i = 0; i < max_SidebarMode; i++) {
631 if (!d->modeButtons[i]) continue;
597 if (isTight && ~flags_Widget(as_Widget(d->modeButtons[i])) & tight_WidgetFlag) { 632 if (isTight && ~flags_Widget(as_Widget(d->modeButtons[i])) & tight_WidgetFlag) {
598 setFlags_Widget(as_Widget(d->modeButtons[i]), tight_WidgetFlag, iTrue); 633 setFlags_Widget(as_Widget(d->modeButtons[i]), tight_WidgetFlag, iTrue);
599 updateTextCStr_LabelWidget(d->modeButtons[i], tightModeLabels_[i]); 634 updateTextCStr_LabelWidget(d->modeButtons[i], tightModeLabels_[i]);
@@ -662,6 +697,9 @@ static iBool handleSidebarCommand_SidebarWidget_(iSidebarWidget *d, const char *
662 postCommandf_App("%s.toggle", cstr_String(id_Widget(w))); 697 postCommandf_App("%s.toggle", cstr_String(id_Widget(w)));
663 } 698 }
664 scrollOffset_ListWidget(d->list, 0); 699 scrollOffset_ListWidget(d->list, 0);
700 if (wasChanged) {
701 postCommandf_App("%s.mode.changed arg:%d", cstr_String(id_Widget(w)), d->mode);
702 }
665 return iTrue; 703 return iTrue;
666 } 704 }
667 else if (equal_Command(cmd, "toggle")) { 705 else if (equal_Command(cmd, "toggle")) {