summaryrefslogtreecommitdiff
path: root/src/gmdocument.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-08-06 19:01:12 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-08-06 19:01:29 +0300
commit7c7af3b7425f0496203d68d9bc42be0603048a9b (patch)
treee02ee9aae3ab71fa001f3e11b356103a24aa9874 /src/gmdocument.c
parentf9571a595986fbaaa7e03c8316219a579fb5b914 (diff)
GmDocument: Full-width images in narrow layout
Diffstat (limited to 'src/gmdocument.c')
-rw-r--r--src/gmdocument.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/gmdocument.c b/src/gmdocument.c
index b9832f38..6ed628de 100644
--- a/src/gmdocument.c
+++ b/src/gmdocument.c
@@ -82,6 +82,7 @@ struct Impl_GmDocument {
82 iString url; /* for resolving relative links */ 82 iString url; /* for resolving relative links */
83 iString localHost; 83 iString localHost;
84 iInt2 size; 84 iInt2 size;
85 int outsideMargin;
85 iArray layout; /* contents of source, laid out in document space */ 86 iArray layout; /* contents of source, laid out in document space */
86 iPtrArray links; 87 iPtrArray links;
87 enum iGmDocumentBanner bannerType; 88 enum iGmDocumentBanner bannerType;
@@ -896,6 +897,12 @@ static void doLayout_GmDocument_(iGmDocument *d) {
896 pos.y += margin; 897 pos.y += margin;
897 run.bounds.pos = pos; 898 run.bounds.pos = pos;
898 run.bounds.size.x = d->size.x; 899 run.bounds.size.x = d->size.x;
900 /* Extend the image to full width, including outside margin, if the viewport
901 is narrow enough. */
902 if (d->outsideMargin < 5 * gap_UI) {
903 run.bounds.size.x += d->outsideMargin * 2;
904 run.bounds.pos.x -= d->outsideMargin;
905 }
899 const float aspect = (float) imgSize.y / (float) imgSize.x; 906 const float aspect = (float) imgSize.y / (float) imgSize.x;
900 run.bounds.size.y = d->size.x * aspect; 907 run.bounds.size.y = d->size.x * aspect;
901 run.visBounds = run.bounds; 908 run.visBounds = run.bounds;
@@ -990,6 +997,7 @@ void init_GmDocument(iGmDocument *d) {
990 init_String(&d->url); 997 init_String(&d->url);
991 init_String(&d->localHost); 998 init_String(&d->localHost);
992 d->bannerType = siteDomain_GmDocumentBanner; 999 d->bannerType = siteDomain_GmDocumentBanner;
1000 d->outsideMargin = 0;
993 d->size = zero_I2(); 1001 d->size = zero_I2();
994 init_Array(&d->layout, sizeof(iGmRun)); 1002 init_Array(&d->layout, sizeof(iGmRun));
995 init_PtrArray(&d->links); 1003 init_PtrArray(&d->links);
@@ -1543,8 +1551,9 @@ void setBanner_GmDocument(iGmDocument *d, enum iGmDocumentBanner type) {
1543 d->bannerType = type; 1551 d->bannerType = type;
1544} 1552}
1545 1553
1546void setWidth_GmDocument(iGmDocument *d, int width) { 1554void setWidth_GmDocument(iGmDocument *d, int width, int outsideMargin) {
1547 d->size.x = width; 1555 d->size.x = width;
1556 d->outsideMargin = outsideMargin; /* distance to edge of the viewport */
1548 doLayout_GmDocument_(d); /* TODO: just flag need-layout and do it later */ 1557 doLayout_GmDocument_(d); /* TODO: just flag need-layout and do it later */
1549} 1558}
1550 1559
@@ -1698,7 +1707,7 @@ void setUrl_GmDocument(iGmDocument *d, const iString *url) {
1698 updateIconBasedOnUrl_GmDocument_(d); 1707 updateIconBasedOnUrl_GmDocument_(d);
1699} 1708}
1700 1709
1701void setSource_GmDocument(iGmDocument *d, const iString *source, int width, 1710void setSource_GmDocument(iGmDocument *d, const iString *source, int width, int outsideMargin,
1702 enum iGmDocumentUpdate updateType) { 1711 enum iGmDocumentUpdate updateType) {
1703// printf("[GmDocument] source update (%zu bytes), width:%d, final:%d\n", 1712// printf("[GmDocument] source update (%zu bytes), width:%d, final:%d\n",
1704// size_String(source), width, updateType == final_GmDocumentUpdate); 1713// size_String(source), width, updateType == final_GmDocumentUpdate);
@@ -1713,7 +1722,7 @@ void setSource_GmDocument(iGmDocument *d, const iString *source, int width,
1713 if (isNormalized_GmDocument_(d)) { 1722 if (isNormalized_GmDocument_(d)) {
1714 normalize_GmDocument(d); 1723 normalize_GmDocument(d);
1715 } 1724 }
1716 setWidth_GmDocument(d, width); /* re-do layout */ 1725 setWidth_GmDocument(d, width, outsideMargin); /* re-do layout */
1717} 1726}
1718 1727
1719void foldPre_GmDocument(iGmDocument *d, uint16_t preId) { 1728void foldPre_GmDocument(iGmDocument *d, uint16_t preId) {