summaryrefslogtreecommitdiff
path: root/src/gmdocument.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-09-22 11:37:15 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-09-22 11:37:15 +0300
commit8700c039dc04b4c9f22584d4e901ed372442b0f4 (patch)
treec89a1c5cda9baa3204b46df0162f5b1ba62add04 /src/gmdocument.c
parentc6182b6b4158a3227546ae55895b72a326db19fb (diff)
DocumentWidget: Drawing side elements
The banner appears on the left, if there is room in the margin. Also added a document timestamp in the bottom to see when the data was received.
Diffstat (limited to 'src/gmdocument.c')
-rw-r--r--src/gmdocument.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/gmdocument.c b/src/gmdocument.c
index 4414b04f..0d104dde 100644
--- a/src/gmdocument.c
+++ b/src/gmdocument.c
@@ -110,6 +110,7 @@ struct Impl_GmDocument {
110 iInt2 size; 110 iInt2 size;
111 iArray layout; /* contents of source, laid out in document space */ 111 iArray layout; /* contents of source, laid out in document space */
112 iPtrArray links; 112 iPtrArray links;
113 iString bannerText;
113 iString title; /* the first top-level title */ 114 iString title; /* the first top-level title */
114 iArray headings; 115 iArray headings;
115 iPtrArray images; /* persistent across layouts, references links by ID */ 116 iPtrArray images; /* persistent across layouts, references links by ID */
@@ -336,6 +337,7 @@ static void doLayout_GmDocument_(iGmDocument *d) {
336 clearLinks_GmDocument_(d); 337 clearLinks_GmDocument_(d);
337 clear_Array(&d->headings); 338 clear_Array(&d->headings);
338 clear_String(&d->title); 339 clear_String(&d->title);
340 clear_String(&d->bannerText);
339 if (d->size.x <= 0 || isEmpty_String(&d->source)) { 341 if (d->size.x <= 0 || isEmpty_String(&d->source)) {
340 return; 342 return;
341 } 343 }
@@ -419,6 +421,7 @@ static void doLayout_GmDocument_(iGmDocument *d) {
419 addSiteBanner = iFalse; 421 addSiteBanner = iFalse;
420 const iRangecc bannerText = urlHost_String(&d->url); 422 const iRangecc bannerText = urlHost_String(&d->url);
421 if (!isEmpty_Range(&bannerText)) { 423 if (!isEmpty_Range(&bannerText)) {
424 setRange_String(&d->bannerText, bannerText);
422 iGmRun banner = { .flags = decoration_GmRunFlag | siteBanner_GmRunFlag }; 425 iGmRun banner = { .flags = decoration_GmRunFlag | siteBanner_GmRunFlag };
423 banner.bounds = zero_Rect(); 426 banner.bounds = zero_Rect();
424 banner.visBounds = init_Rect(0, 0, d->size.x, lineHeight_Text(banner_FontId) * 2); 427 banner.visBounds = init_Rect(0, 0, d->size.x, lineHeight_Text(banner_FontId) * 2);
@@ -618,6 +621,7 @@ void init_GmDocument(iGmDocument *d) {
618 d->size = zero_I2(); 621 d->size = zero_I2();
619 init_Array(&d->layout, sizeof(iGmRun)); 622 init_Array(&d->layout, sizeof(iGmRun));
620 init_PtrArray(&d->links); 623 init_PtrArray(&d->links);
624 init_String(&d->bannerText);
621 init_String(&d->title); 625 init_String(&d->title);
622 init_Array(&d->headings, sizeof(iGmHeading)); 626 init_Array(&d->headings, sizeof(iGmHeading));
623 init_PtrArray(&d->images); 627 init_PtrArray(&d->images);
@@ -626,6 +630,7 @@ void init_GmDocument(iGmDocument *d) {
626} 630}
627 631
628void deinit_GmDocument(iGmDocument *d) { 632void deinit_GmDocument(iGmDocument *d) {
633 deinit_String(&d->bannerText);
629 deinit_String(&d->title); 634 deinit_String(&d->title);
630 clearLinks_GmDocument_(d); 635 clearLinks_GmDocument_(d);
631 deinit_PtrArray(&d->links); 636 deinit_PtrArray(&d->links);
@@ -903,8 +908,12 @@ void setThemeSeed_GmDocument(iGmDocument *d, const iBlock *seed) {
903 setHsl_Color(i, color); 908 setHsl_Color(i, color);
904 } 909 }
905 } 910 }
911 /* Derived colors. */
906 set_Color(tmQuoteIcon_ColorId, 912 set_Color(tmQuoteIcon_ColorId,
907 mix_Color(get_Color(tmQuote_ColorId), get_Color(tmBackground_ColorId), 0.55f)); 913 mix_Color(get_Color(tmQuote_ColorId), get_Color(tmBackground_ColorId), 0.55f));
914 set_Color(tmBannerSideTitle_ColorId,
915 mix_Color(get_Color(tmBannerTitle_ColorId), get_Color(tmBackground_ColorId),
916 theme == colorfulDark_GmDocumentTheme ? 0.55f : 0));
908 /* Special exceptions. */ 917 /* Special exceptions. */
909 if (seed) { 918 if (seed) {
910 if (equal_CStr(cstr_Block(seed), "gemini.circumlunar.space")) { 919 if (equal_CStr(cstr_Block(seed), "gemini.circumlunar.space")) {
@@ -1047,11 +1056,22 @@ iInt2 size_GmDocument(const iGmDocument *d) {
1047} 1056}
1048 1057
1049iBool hasSiteBanner_GmDocument(const iGmDocument *d) { 1058iBool hasSiteBanner_GmDocument(const iGmDocument *d) {
1059 return siteBanner_GmDocument(d) != NULL;
1060}
1061
1062const iGmRun *siteBanner_GmDocument(const iGmDocument *d) {
1050 if (isEmpty_Array(&d->layout)) { 1063 if (isEmpty_Array(&d->layout)) {
1051 return iFalse; 1064 return iFalse;
1052 } 1065 }
1053 const iGmRun *first = constFront_Array(&d->layout); 1066 const iGmRun *first = constFront_Array(&d->layout);
1054 return (first->flags & siteBanner_GmRunFlag) != 0; 1067 if (first->flags & siteBanner_GmRunFlag) {
1068 return first;
1069 }
1070 return NULL;
1071}
1072
1073const iString *bannerText_GmDocument(const iGmDocument *d) {
1074 return &d->bannerText;
1055} 1075}
1056 1076
1057const iArray *headings_GmDocument(const iGmDocument *d) { 1077const iArray *headings_GmDocument(const iGmDocument *d) {