summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-09-05 07:02:33 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-09-05 07:02:33 +0300
commitaa50c1e0028c6cb08524dcdfb7188906c817e46f (patch)
tree1f5d91bef261612680d589e0481dad99ef189619 /src/ui
parentde53b815e09a1004b8fb70706199fb840f53514a (diff)
Option to force break very long lines
Even preformatted lines may need to be wrapped so the content remains visible, since there is no horizontal scrolling. However, this is off by default so ASCII art isn't broken in narrow windows.
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/documentwidget.c23
-rw-r--r--src/ui/window.c2
2 files changed, 19 insertions, 6 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index 437e9468..2ccdc416 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -296,6 +296,15 @@ static iRect documentBounds_DocumentWidget_(const iDocumentWidget *d) {
296 return rect; 296 return rect;
297} 297}
298 298
299static int forceBreakWidth_DocumentWidget_(const iDocumentWidget *d) {
300 if (isLineWrapForced_App()) {
301 const iRect bounds = bounds_Widget(constAs_Widget(d));
302 const iRect docBounds = documentBounds_DocumentWidget_(d);
303 return right_Rect(bounds) - left_Rect(docBounds) - gap_UI * d->pageMargin;
304 }
305 return 0;
306}
307
299iLocalDef int documentToWindowY_DocumentWidget_(const iDocumentWidget *d, int docY) { 308iLocalDef int documentToWindowY_DocumentWidget_(const iDocumentWidget *d, int docY) {
300 return docY - d->scrollY + documentBounds_DocumentWidget_(d).pos.y; 309 return docY - d->scrollY + documentBounds_DocumentWidget_(d).pos.y;
301} 310}
@@ -488,7 +497,8 @@ static void invalidate_DocumentWidget_(iDocumentWidget *d) {
488 497
489static void setSource_DocumentWidget_(iDocumentWidget *d, const iString *source) { 498static void setSource_DocumentWidget_(iDocumentWidget *d, const iString *source) {
490 setUrl_GmDocument(d->doc, d->mod.url); 499 setUrl_GmDocument(d->doc, d->mod.url);
491 setSource_GmDocument(d->doc, source, documentWidth_DocumentWidget_(d)); 500 setSource_GmDocument(
501 d->doc, source, documentWidth_DocumentWidget_(d), forceBreakWidth_DocumentWidget_(d));
492 d->foundMark = iNullRange; 502 d->foundMark = iNullRange;
493 d->selectMark = iNullRange; 503 d->selectMark = iNullRange;
494 d->hoverLink = NULL; 504 d->hoverLink = NULL;
@@ -1021,8 +1031,10 @@ static void allocVisBuffer_DocumentWidget_(const iDocumentWidget *d) {
1021} 1031}
1022 1032
1023void updateSize_DocumentWidget(iDocumentWidget *d) { 1033void updateSize_DocumentWidget(iDocumentWidget *d) {
1024 setWidth_GmDocument(d->doc, documentWidth_DocumentWidget_(d)); 1034 setWidth_GmDocument(
1035 d->doc, documentWidth_DocumentWidget_(d), forceBreakWidth_DocumentWidget_(d));
1025 updateVisible_DocumentWidget_(d); 1036 updateVisible_DocumentWidget_(d);
1037 invalidate_DocumentWidget_(d);
1026} 1038}
1027 1039
1028static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) { 1040static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) {
@@ -1030,9 +1042,9 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)
1030 if (equal_Command(cmd, "window.resized") || equal_Command(cmd, "font.changed")) { 1042 if (equal_Command(cmd, "window.resized") || equal_Command(cmd, "font.changed")) {
1031 const iGmRun *mid = middleRun_DocumentWidget_(d); 1043 const iGmRun *mid = middleRun_DocumentWidget_(d);
1032 const char *midLoc = (mid ? mid->text.start : NULL); 1044 const char *midLoc = (mid ? mid->text.start : NULL);
1033 setWidth_GmDocument(d->doc, documentWidth_DocumentWidget_(d)); 1045 setWidth_GmDocument(
1046 d->doc, documentWidth_DocumentWidget_(d), forceBreakWidth_DocumentWidget_(d));
1034 scroll_DocumentWidget_(d, 0); 1047 scroll_DocumentWidget_(d, 0);
1035 updateVisible_DocumentWidget_(d);
1036 if (midLoc) { 1048 if (midLoc) {
1037 mid = findRunAtLoc_GmDocument(d->doc, midLoc); 1049 mid = findRunAtLoc_GmDocument(d->doc, midLoc);
1038 if (mid) { 1050 if (mid) {
@@ -1055,8 +1067,7 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)
1055 /* Set palette for our document. */ 1067 /* Set palette for our document. */
1056 updateTheme_DocumentWidget_(d); 1068 updateTheme_DocumentWidget_(d);
1057 updateTrust_DocumentWidget_(d, NULL); 1069 updateTrust_DocumentWidget_(d, NULL);
1058 setWidth_GmDocument(d->doc, documentWidth_DocumentWidget_(d)); 1070 updateSize_DocumentWidget(d);
1059 updateVisible_DocumentWidget_(d);
1060 } 1071 }
1061 updateWindowTitle_DocumentWidget_(d); 1072 updateWindowTitle_DocumentWidget_(d);
1062 allocVisBuffer_DocumentWidget_(d); 1073 allocVisBuffer_DocumentWidget_(d);
diff --git a/src/ui/window.c b/src/ui/window.c
index b7b4a8fd..66f1c513 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -141,6 +141,8 @@ static const iMenuItem viewMenuItems[] = {
141 { "Zoom In", SDLK_EQUALS, KMOD_PRIMARY, "zoom.delta arg:10" }, 141 { "Zoom In", SDLK_EQUALS, KMOD_PRIMARY, "zoom.delta arg:10" },
142 { "Zoom Out", SDLK_MINUS, KMOD_PRIMARY, "zoom.delta arg:-10" }, 142 { "Zoom Out", SDLK_MINUS, KMOD_PRIMARY, "zoom.delta arg:-10" },
143 { "Reset Zoom", SDLK_0, KMOD_PRIMARY, "zoom.set arg:100" }, 143 { "Reset Zoom", SDLK_0, KMOD_PRIMARY, "zoom.set arg:100" },
144 { "---", 0, 0, NULL },
145 { "Wrap Preformatted", 0, 0, "forcewrap.toggle" }
144}; 146};
145 147
146static const iMenuItem helpMenuItems[] = { 148static const iMenuItem helpMenuItems[] = {