diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-08-06 19:01:12 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-08-06 19:01:29 +0300 |
commit | 7c7af3b7425f0496203d68d9bc42be0603048a9b (patch) | |
tree | e02ee9aae3ab71fa001f3e11b356103a24aa9874 /src | |
parent | f9571a595986fbaaa7e03c8316219a579fb5b914 (diff) |
GmDocument: Full-width images in narrow layout
Diffstat (limited to 'src')
-rw-r--r-- | src/gmdocument.c | 15 | ||||
-rw-r--r-- | src/gmdocument.h | 4 | ||||
-rw-r--r-- | src/ui/documentwidget.c | 7 |
3 files changed, 19 insertions, 7 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 | ||
1546 | void setWidth_GmDocument(iGmDocument *d, int width) { | 1554 | void 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 | ||
1701 | void setSource_GmDocument(iGmDocument *d, const iString *source, int width, | 1710 | void 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 | ||
1719 | void foldPre_GmDocument(iGmDocument *d, uint16_t preId) { | 1728 | void foldPre_GmDocument(iGmDocument *d, uint16_t preId) { |
diff --git a/src/gmdocument.h b/src/gmdocument.h index 9a7a70df..9f8ee2ef 100644 --- a/src/gmdocument.h +++ b/src/gmdocument.h | |||
@@ -174,11 +174,11 @@ enum iGmDocumentUpdate { | |||
174 | void setThemeSeed_GmDocument (iGmDocument *, const iBlock *seed); | 174 | void setThemeSeed_GmDocument (iGmDocument *, const iBlock *seed); |
175 | void setFormat_GmDocument (iGmDocument *, enum iSourceFormat format); | 175 | void setFormat_GmDocument (iGmDocument *, enum iSourceFormat format); |
176 | void setBanner_GmDocument (iGmDocument *, enum iGmDocumentBanner type); | 176 | void setBanner_GmDocument (iGmDocument *, enum iGmDocumentBanner type); |
177 | void setWidth_GmDocument (iGmDocument *, int width); | 177 | void setWidth_GmDocument (iGmDocument *, int width, int outsideMargin); |
178 | void redoLayout_GmDocument (iGmDocument *); | 178 | void redoLayout_GmDocument (iGmDocument *); |
179 | iBool updateOpenURLs_GmDocument(iGmDocument *); | 179 | iBool updateOpenURLs_GmDocument(iGmDocument *); |
180 | void setUrl_GmDocument (iGmDocument *, const iString *url); | 180 | void setUrl_GmDocument (iGmDocument *, const iString *url); |
181 | void setSource_GmDocument (iGmDocument *, const iString *source, int width, | 181 | void setSource_GmDocument (iGmDocument *, const iString *source, int width, int outsideMargin, |
182 | enum iGmDocumentUpdate updateType); | 182 | enum iGmDocumentUpdate updateType); |
183 | void foldPre_GmDocument (iGmDocument *, uint16_t preId); | 183 | void foldPre_GmDocument (iGmDocument *, uint16_t preId); |
184 | 184 | ||
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index e1be27c2..8de1162f 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c | |||
@@ -1054,9 +1054,12 @@ static void documentWasChanged_DocumentWidget_(iDocumentWidget *d) { | |||
1054 | 1054 | ||
1055 | void setSource_DocumentWidget(iDocumentWidget *d, const iString *source) { | 1055 | void setSource_DocumentWidget(iDocumentWidget *d, const iString *source) { |
1056 | setUrl_GmDocument(d->doc, d->mod.url); | 1056 | setUrl_GmDocument(d->doc, d->mod.url); |
1057 | const int docWidth = documentWidth_DocumentWidget_(d); | ||
1058 | const int outsideMargin = (width_Widget(d) - docWidth) / 2; | ||
1057 | setSource_GmDocument(d->doc, | 1059 | setSource_GmDocument(d->doc, |
1058 | source, | 1060 | source, |
1059 | documentWidth_DocumentWidget_(d), | 1061 | docWidth, |
1062 | outsideMargin, | ||
1060 | isFinished_GmRequest(d->request) ? final_GmDocumentUpdate | 1063 | isFinished_GmRequest(d->request) ? final_GmDocumentUpdate |
1061 | : partial_GmDocumentUpdate); | 1064 | : partial_GmDocumentUpdate); |
1062 | documentWasChanged_DocumentWidget_(d); | 1065 | documentWasChanged_DocumentWidget_(d); |
@@ -2249,7 +2252,7 @@ static iBool updateDocumentWidthRetainingScrollPosition_DocumentWidget_(iDocumen | |||
2249 | /* TODO: First *fully* visible run? */ | 2252 | /* TODO: First *fully* visible run? */ |
2250 | voffset = visibleRange_DocumentWidget_(d).start - top_Rect(run->visBounds); | 2253 | voffset = visibleRange_DocumentWidget_(d).start - top_Rect(run->visBounds); |
2251 | } | 2254 | } |
2252 | setWidth_GmDocument(d->doc, newWidth); | 2255 | setWidth_GmDocument(d->doc, newWidth, (width_Widget(d) - newWidth) / 2); |
2253 | documentRunsInvalidated_DocumentWidget_(d); | 2256 | documentRunsInvalidated_DocumentWidget_(d); |
2254 | if (runLoc && !keepCenter) { | 2257 | if (runLoc && !keepCenter) { |
2255 | run = findRunAtLoc_GmDocument(d->doc, runLoc); | 2258 | run = findRunAtLoc_GmDocument(d->doc, runLoc); |