summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-11-23 21:42:32 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-11-23 21:42:32 +0200
commite608b04a9e46e75c8c1179f47d0b65fb2f26c2d9 (patch)
treeee3de6478486e7c18deaa6cf36007334fa0491d0
parentadfd2d702195103e69a3cacdeadb9709ba9be130 (diff)
SidebarWidget: Improved feed entry appearance
-rw-r--r--src/feeds.c8
-rw-r--r--src/ui/scrollwidget.c9
-rw-r--r--src/ui/sidebarwidget.c75
3 files changed, 62 insertions, 30 deletions
diff --git a/src/feeds.c b/src/feeds.c
index 7e54a633..93bec891 100644
--- a/src/feeds.c
+++ b/src/feeds.c
@@ -151,12 +151,10 @@ static void parseResult_FeedJob_(iFeedJob *d) {
151 const iRangecc url = capturedRange_RegExpMatch(&m, 1); 151 const iRangecc url = capturedRange_RegExpMatch(&m, 1);
152 const iRangecc date = capturedRange_RegExpMatch(&m, 2); 152 const iRangecc date = capturedRange_RegExpMatch(&m, 2);
153 const iRangecc title = capturedRange_RegExpMatch(&m, 3); 153 const iRangecc title = capturedRange_RegExpMatch(&m, 3);
154 iFeedEntry *entry = new_FeedEntry(); 154 iFeedEntry * entry = new_FeedEntry();
155 entry->bookmarkId = d->bookmarkId; 155 entry->bookmarkId = d->bookmarkId;
156 setRange_String(&entry->url, url); 156 setRange_String(&entry->url, url);
157 set_String(&entry->url, 157 set_String(&entry->url, absoluteUrl_String(url_GmRequest(d->request), &entry->url));
158 absoluteUrl_String(url_GmRequest(d->request),
159 collect_String(lower_String(&entry->url))));
160 setRange_String(&entry->title, title); 158 setRange_String(&entry->title, title);
161 trimTitle_(&entry->title); 159 trimTitle_(&entry->title);
162 int year, month, day; 160 int year, month, day;
@@ -293,7 +291,7 @@ static void stopWorker_Feeds_(iFeeds *d) {
293 291
294static int cmp_FeedEntryPtr_(const void *a, const void *b) { 292static int cmp_FeedEntryPtr_(const void *a, const void *b) {
295 const iFeedEntry * const *elem[2] = { a, b }; 293 const iFeedEntry * const *elem[2] = { a, b };
296 return cmpStringCase_String(&(*elem[0])->url, &(*elem[1])->url); 294 return cmpString_String(&(*elem[0])->url, &(*elem[1])->url);
297} 295}
298 296
299static void save_Feeds_(iFeeds *d) { 297static void save_Feeds_(iFeeds *d) {
diff --git a/src/ui/scrollwidget.c b/src/ui/scrollwidget.c
index f5340897..649d0575 100644
--- a/src/ui/scrollwidget.c
+++ b/src/ui/scrollwidget.c
@@ -131,14 +131,15 @@ static iBool processEvent_ScrollWidget_(iScrollWidget *d, const SDL_Event *ev) {
131} 131}
132 132
133static void draw_ScrollWidget_(const iScrollWidget *d) { 133static void draw_ScrollWidget_(const iScrollWidget *d) {
134 const iWidget *w = constAs_Widget(d); 134 const iWidget *w = constAs_Widget(d);
135 const iRect bounds = bounds_Widget(w); 135 const iRect bounds = bounds_Widget(w);
136 const iBool isPressed = (flags_Widget(w) & pressed_WidgetFlag) != 0; 136 const iBool isPressed = (flags_Widget(w) & pressed_WidgetFlag) != 0;
137 if (bounds.size.x > 0) { 137 if (bounds.size.x > 0) {
138 iPaint p; 138 iPaint p;
139 init_Paint(&p); 139 init_Paint(&p);
140 drawVLine_Paint(&p, topLeft_Rect(bounds), height_Rect(bounds), uiSeparator_ColorId); 140 drawVLine_Paint(&p, topLeft_Rect(bounds), height_Rect(bounds), uiSeparator_ColorId);
141 const iRect thumbRect = shrunk_Rect(thumbRect_ScrollWidget_(d), init_I2(gap_UI, gap_UI / 2)); 141 const iRect thumbRect = shrunk_Rect(
142 thumbRect_ScrollWidget_(d), init_I2(isPressed ? gap_UI : (gap_UI * 4 / 3), gap_UI / 2));
142 fillRect_Paint(&p, thumbRect, isPressed ? uiBackgroundPressed_ColorId : tmQuote_ColorId); 143 fillRect_Paint(&p, thumbRect, isPressed ? uiBackgroundPressed_ColorId : tmQuote_ColorId);
143 } 144 }
144} 145}
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) {