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.c36
1 files changed, 29 insertions, 7 deletions
diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c
index 4d3818bd..dd7b977e 100644
--- a/src/ui/sidebarwidget.c
+++ b/src/ui/sidebarwidget.c
@@ -414,8 +414,10 @@ static void updateItems_SidebarWidget_(iSidebarWidget *d) {
414} 414}
415 415
416static void updateItemHeight_SidebarWidget_(iSidebarWidget *d) { 416static void updateItemHeight_SidebarWidget_(iSidebarWidget *d) {
417 const float heights[max_SidebarMode] = { 1.333f, 2.333f, 1.333f, 3.5f, 1.2f }; 417 if (d->list) {
418 setItemHeight_ListWidget(d->list, heights[d->mode] * lineHeight_Text(d->itemFonts[0])); 418 const float heights[max_SidebarMode] = { 1.333f, 2.333f, 1.333f, 3.5f, 1.2f };
419 setItemHeight_ListWidget(d->list, heights[d->mode] * lineHeight_Text(d->itemFonts[0]));
420 }
419} 421}
420 422
421iBool setMode_SidebarWidget(iSidebarWidget *d, enum iSidebarMode mode) { 423iBool setMode_SidebarWidget(iSidebarWidget *d, enum iSidebarMode mode) {
@@ -466,6 +468,22 @@ const char *icon_SidebarMode(enum iSidebarMode mode) {
466 return tightModeLabels_[mode]; 468 return tightModeLabels_[mode];
467} 469}
468 470
471static void updateMetrics_SidebarWidget_(iSidebarWidget *d) {
472 if (d->resizer) {
473 d->resizer->rect.size.x = gap_UI;
474 }
475 d->maxButtonLabelWidth = 0;
476 for (int i = 0; i < max_SidebarMode; i++) {
477 if (d->modeButtons[i]) {
478 d->maxButtonLabelWidth = iMaxi(
479 d->maxButtonLabelWidth,
480 3 * gap_UI +
481 measure_Text(font_LabelWidget(d->modeButtons[i]), normalModeLabels_[i]).x);
482 }
483 }
484 updateItemHeight_SidebarWidget_(d);
485}
486
469void init_SidebarWidget(iSidebarWidget *d, enum iSidebarSide side) { 487void init_SidebarWidget(iSidebarWidget *d, enum iSidebarSide side) {
470 iWidget *w = as_Widget(d); 488 iWidget *w = as_Widget(d);
471 init_Widget(w); 489 init_Widget(w);
@@ -493,6 +511,8 @@ void init_SidebarWidget(iSidebarWidget *d, enum iSidebarSide side) {
493 iWidget *vdiv = makeVDiv_Widget(); 511 iWidget *vdiv = makeVDiv_Widget();
494 addChildFlags_Widget(w, vdiv, resizeToParentWidth_WidgetFlag | resizeToParentHeight_WidgetFlag); 512 addChildFlags_Widget(w, vdiv, resizeToParentWidth_WidgetFlag | resizeToParentHeight_WidgetFlag);
495 iZap(d->modeButtons); 513 iZap(d->modeButtons);
514 d->resizer = NULL;
515 d->list = NULL;
496 /* On a phone, the right sidebar is used exclusively for Identities. */ 516 /* On a phone, the right sidebar is used exclusively for Identities. */
497 const iBool isPhone = deviceType_App() == phone_AppDeviceType; 517 const iBool isPhone = deviceType_App() == phone_AppDeviceType;
498 if (!isPhone || d->side == left_SideBarSide) { 518 if (!isPhone || d->side == left_SideBarSide) {
@@ -550,10 +570,10 @@ void init_SidebarWidget(iSidebarWidget *d, enum iSidebarSide side) {
550 setFlags_Widget(d->resizer, hidden_WidgetFlag | disabled_WidgetFlag, iTrue); 570 setFlags_Widget(d->resizer, hidden_WidgetFlag | disabled_WidgetFlag, iTrue);
551 } 571 }
552 setId_Widget(d->resizer, side == left_SideBarSide ? "sidebar.grab" : "sidebar2.grab"); 572 setId_Widget(d->resizer, side == left_SideBarSide ? "sidebar.grab" : "sidebar2.grab");
553 d->resizer->rect.size.x = gap_UI;
554 setBackgroundColor_Widget(d->resizer, none_ColorId); 573 setBackgroundColor_Widget(d->resizer, none_ColorId);
555 d->menu = NULL; 574 d->menu = NULL;
556 addAction_Widget(w, SDLK_r, KMOD_PRIMARY | KMOD_SHIFT, "feeds.refresh"); 575 addAction_Widget(w, SDLK_r, KMOD_PRIMARY | KMOD_SHIFT, "feeds.refresh");
576 updateMetrics_SidebarWidget_(d);
557} 577}
558 578
559void deinit_SidebarWidget(iSidebarWidget *d) { 579void deinit_SidebarWidget(iSidebarWidget *d) {
@@ -561,15 +581,12 @@ void deinit_SidebarWidget(iSidebarWidget *d) {
561} 581}
562 582
563void setButtonFont_SidebarWidget(iSidebarWidget *d, int font) { 583void setButtonFont_SidebarWidget(iSidebarWidget *d, int font) {
564 d->maxButtonLabelWidth = 0;
565 for (int i = 0; i < max_SidebarMode; i++) { 584 for (int i = 0; i < max_SidebarMode; i++) {
566 if (d->modeButtons[i]) { 585 if (d->modeButtons[i]) {
567 setFont_LabelWidget(d->modeButtons[i], font); 586 setFont_LabelWidget(d->modeButtons[i], font);
568 d->maxButtonLabelWidth =
569 iMaxi(d->maxButtonLabelWidth,
570 3 * gap_UI + measure_Text(font, normalModeLabels_[i]).x);
571 } 587 }
572 } 588 }
589 updateMetrics_SidebarWidget_(d);
573} 590}
574 591
575static const iGmIdentity *constHoverIdentity_SidebarWidget_(const iSidebarWidget *d) { 592static const iGmIdentity *constHoverIdentity_SidebarWidget_(const iSidebarWidget *d) {
@@ -759,6 +776,11 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev)
759 if (isResize_UserEvent(ev)) { 776 if (isResize_UserEvent(ev)) {
760 checkModeButtonLayout_SidebarWidget_(d); 777 checkModeButtonLayout_SidebarWidget_(d);
761 } 778 }
779 else if (isMetricsChange_UserEvent(ev)) {
780 updateMetrics_SidebarWidget_(d);
781 arrange_Widget(w);
782 checkModeButtonLayout_SidebarWidget_(d);
783 }
762 else if (ev->type == SDL_USEREVENT && ev->user.code == command_UserEventCode) { 784 else if (ev->type == SDL_USEREVENT && ev->user.code == command_UserEventCode) {
763 const char *cmd = command_UserEvent(ev); 785 const char *cmd = command_UserEvent(ev);
764 if (equal_Command(cmd, "tabs.changed") || equal_Command(cmd, "document.changed")) { 786 if (equal_Command(cmd, "tabs.changed") || equal_Command(cmd, "document.changed")) {