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.c75
1 files changed, 54 insertions, 21 deletions
diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c
index 3cde7c3f..e38499bc 100644
--- a/src/ui/sidebarwidget.c
+++ b/src/ui/sidebarwidget.c
@@ -114,6 +114,8 @@ static void updateItems_SidebarWidget_(iSidebarWidget *d) {
114 switch (d->mode) { 114 switch (d->mode) {
115 case feeds_SidebarMode: { 115 case feeds_SidebarMode: {
116 iDate on; 116 iDate on;
117 initCurrent_Date(&on);
118 const int thisYear = on.year;
117 iZap(on); 119 iZap(on);
118 iConstForEach(PtrArray, i, listEntries_Feeds()) { 120 iConstForEach(PtrArray, i, listEntries_Feeds()) {
119 const iFeedEntry *entry = i.ptr; 121 const iFeedEntry *entry = i.ptr;
@@ -125,7 +127,7 @@ static void updateItems_SidebarWidget_(iSidebarWidget *d) {
125 on = entryDate; 127 on = entryDate;
126 iSidebarItem *sep = new_SidebarItem(); 128 iSidebarItem *sep = new_SidebarItem();
127 sep->listItem.isSeparator = iTrue; 129 sep->listItem.isSeparator = iTrue;
128 iString *text = format_Date(&on, "%Y %b %d"); 130 iString *text = format_Date(&on, on.year == thisYear ? "%b %d" : "%Y %b %d");
129 set_String(&sep->meta, text); 131 set_String(&sep->meta, text);
130 delete_String(text); 132 delete_String(text);
131 addItem_ListWidget(d->list, sep); 133 addItem_ListWidget(d->list, sep);
@@ -142,7 +144,11 @@ static void updateItems_SidebarWidget_(iSidebarWidget *d) {
142 set_String(&item->label, &entry->title); 144 set_String(&item->label, &entry->title);
143 const iBookmark *bm = get_Bookmarks(bookmarks_App(), entry->bookmarkId); 145 const iBookmark *bm = get_Bookmarks(bookmarks_App(), entry->bookmarkId);
144 if (bm) { 146 if (bm) {
145 set_String(&item->meta, &bm->title); 147// appendCStr_String(&item->meta, uiTextCaution_ColorEscape);
148// appendChar_String(&item->meta, bm->icon);
149// appendChar_String(&item->meta, ' ');
150// appendCStr_String(&item->meta, uiText_ColorEscape);
151 append_String(&item->meta, &bm->title);
146 } 152 }
147 addItem_ListWidget(d->list, item); 153 addItem_ListWidget(d->list, item);
148 iRelease(item); 154 iRelease(item);
@@ -199,7 +205,7 @@ static void updateItems_SidebarWidget_(iSidebarWidget *d) {
199 iSidebarItem *sep = new_SidebarItem(); 205 iSidebarItem *sep = new_SidebarItem();
200 sep->listItem.isSeparator = iTrue; 206 sep->listItem.isSeparator = iTrue;
201 const iString *text = collect_String(format_Date( 207 const iString *text = collect_String(format_Date(
202 &date, date.year != thisYear ? "%b %d %Y" : "%b %d")); 208 &date, date.year != thisYear ? "%Y %b %d" : "%b %d"));
203 set_String(&sep->meta, text); 209 set_String(&sep->meta, text);
204 const int yOffset = itemHeight_ListWidget(d->list) * 2 / 3; 210 const int yOffset = itemHeight_ListWidget(d->list) * 2 / 3;
205 sep->id = yOffset; 211 sep->id = yOffset;
@@ -879,32 +885,59 @@ static void draw_SidebarItem_(const iSidebarItem *d, iPaint *p, iRect itemRect,
879 uiLabelLarge_FontId, 885 uiLabelLarge_FontId,
880 add_I2(pos, 886 add_I2(pos,
881 init_I2(3 * gap_UI, 887 init_I2(3 * gap_UI,
882 itemHeight - lineHeight_Text(uiLabelLarge_FontId) - 2 * gap_UI)), 888 itemHeight - lineHeight_Text(uiLabelLarge_FontId) - 1 * gap_UI)),
883 uiIcon_ColorId, 889 uiIcon_ColorId,
884 range_String(&d->meta)); 890 range_String(&d->meta));
885 } 891 }
886 else { 892 else {
893 const iBool isUnread = (d->icon != 0);
887 const int h1 = lineHeight_Text(uiLabel_FontId); 894 const int h1 = lineHeight_Text(uiLabel_FontId);
888 const int h2 = lineHeight_Text(uiContent_FontId); 895 const int h2 = lineHeight_Text(uiContent_FontId);
889 const iRect iconArea = { addY_I2(pos, h1), init_I2(7 * gap_UI, itemHeight - h1) }; 896 const int iconPad = 4 * gap_UI;
890 if (d->icon) { 897 const iRect iconArea = { addY_I2(pos, 0), init_I2(iconPad, itemHeight) };
898 if (isUnread) {
899 /*
891 iString str; 900 iString str;
892 initUnicodeN_String(&str, &d->icon, 1); 901 initUnicodeN_String(&str, &d->icon, 1);
893 drawCentered_Text(uiContent_FontId, iconArea, iFalse, iconColor, "%s", cstr_String(&str)); 902 drawCentered_Text(
894 deinit_String(&str); 903 uiContent_FontId, iconArea, iFalse, iconColor, "%s", cstr_String(&str));
895 } 904 deinit_String(&str);*/
896 pos = add_I2(pos, init_I2(7 * gap_UI, (itemHeight - h1 - h2) / 2)); 905 fillRect_Paint(
897 draw_Text(uiLabel_FontId, 906 p,
898 pos, 907 (iRect){ topLeft_Rect(iconArea), init_I2(gap_UI, height_Rect(iconArea)) },
899 isPressing ? fg : uiHeading_ColorId, 908 iconColor);
900 "%s", 909 }
901 cstr_String(&d->meta)); 910 /* Select the layout based on how the title fits. */
902 pos.y += h1; 911 iInt2 titleSize = advanceRange_Text(uiContent_FontId, range_String(&d->label));
903 draw_Text(uiContent_FontId, 912 const iInt2 metaSize = advanceRange_Text(uiLabel_FontId, range_String(&d->meta));
904 pos, 913 pos.x += iconPad;
905 isPressing ? fg : uiTextStrong_ColorId, 914 const int avail = width_Rect(itemRect) - iconPad - 3 * gap_UI;
906 "%s", 915 const int labelFg = isPressing ? fg : (isUnread ? uiTextStrong_ColorId : uiText_ColorId);
907 cstr_String(&d->label)); 916 if (titleSize.x > avail && metaSize.x < avail * 0.75f) {
917 /* Must wrap the title. */
918 pos.y += (itemHeight - h2 - h2) / 2;
919 draw_Text(
920 uiLabel_FontId, addY_I2(pos, h2 - h1 - gap_UI / 8), fg, "%s \u2014 ", cstr_String(&d->meta));
921 int skip = metaSize.x + advance_Text(uiLabel_FontId, " \u2014 ").x;
922 iInt2 cur = addX_I2(pos, skip);
923 const char *endPos;
924 tryAdvance_Text(
925 uiContent_FontId, range_String(&d->label), avail - skip, &endPos);
926 drawRange_Text(uiContent_FontId,
927 cur,
928 labelFg,
929 (iRangecc){ constBegin_String(&d->label), endPos });
930 if (endPos < constEnd_String(&d->label)) {
931 drawRange_Text(uiContent_FontId,
932 addY_I2(pos, h2), labelFg,
933 (iRangecc){ endPos, constEnd_String(&d->label) });
934 }
935 }
936 else {
937 pos.y += (itemHeight - h1 - h2) / 2;
938 drawRange_Text(uiLabel_FontId, pos, fg, range_String(&d->meta));
939 drawRange_Text(uiContent_FontId, addY_I2(pos, h1), labelFg, range_String(&d->label));
940 }
908 } 941 }
909 } 942 }
910 else if (sidebar->mode == bookmarks_SidebarMode) { 943 else if (sidebar->mode == bookmarks_SidebarMode) {