diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-02-10 10:59:19 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-02-10 10:59:19 +0200 |
commit | 15aa8e1f486e4e1d48adbfc0f0f5922bd478db29 (patch) | |
tree | 00e6f6b1140bb033aca1bd46b069f4857b069422 /src | |
parent | 310a805956ffb04ebd01ce59cbb4e7179c503fed (diff) |
Window: Keep scroll position when resizing vertically
IssueID #138
Diffstat (limited to 'src')
-rw-r--r-- | src/ui/documentwidget.c | 23 | ||||
-rw-r--r-- | src/ui/window.c | 10 | ||||
-rw-r--r-- | src/ui/window.h | 1 |
3 files changed, 25 insertions, 9 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index 4063503f..b9aa551f 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c | |||
@@ -1533,18 +1533,25 @@ static const int homeRowKeys_[] = { | |||
1533 | static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) { | 1533 | static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) { |
1534 | iWidget *w = as_Widget(d); | 1534 | iWidget *w = as_Widget(d); |
1535 | if (equal_Command(cmd, "window.resized") || equal_Command(cmd, "font.changed")) { | 1535 | if (equal_Command(cmd, "window.resized") || equal_Command(cmd, "font.changed")) { |
1536 | const iGmRun *mid = middleRun_DocumentWidget_(d); | 1536 | const iBool isHorizontalOnly = |
1537 | const char *midLoc = (mid ? mid->text.start : NULL); | 1537 | argLabel_Command(cmd, "horiz") != 0 && !argLabel_Command(cmd, "vert"); |
1538 | /* Alt/Option key may be involved in window size changes. */ | 1538 | /* Alt/Option key may be involved in window size changes. */ |
1539 | iChangeFlags(d->flags, showLinkNumbers_DocumentWidgetFlag, iFalse); | 1539 | iChangeFlags(d->flags, showLinkNumbers_DocumentWidgetFlag, iFalse); |
1540 | setWidth_GmDocument(d->doc, documentWidth_DocumentWidget_(d)); | 1540 | if (isHorizontalOnly) { |
1541 | scroll_DocumentWidget_(d, 0); | 1541 | const iGmRun *mid = middleRun_DocumentWidget_(d); |
1542 | if (midLoc) { | 1542 | const char *midLoc = (mid ? mid->text.start : NULL); |
1543 | mid = findRunAtLoc_GmDocument(d->doc, midLoc); | 1543 | setWidth_GmDocument(d->doc, documentWidth_DocumentWidget_(d)); |
1544 | if (mid) { | 1544 | scroll_DocumentWidget_(d, 0); |
1545 | scrollTo_DocumentWidget_(d, mid_Rect(mid->bounds).y, iTrue); | 1545 | if (midLoc) { |
1546 | mid = findRunAtLoc_GmDocument(d->doc, midLoc); | ||
1547 | if (mid) { | ||
1548 | scrollTo_DocumentWidget_(d, mid_Rect(mid->bounds).y, iTrue); | ||
1549 | } | ||
1546 | } | 1550 | } |
1547 | } | 1551 | } |
1552 | else { | ||
1553 | scroll_DocumentWidget_(d, 0); /* prevent overscroll */ | ||
1554 | } | ||
1548 | updateSideIconBuf_DocumentWidget_(d); | 1555 | updateSideIconBuf_DocumentWidget_(d); |
1549 | updateOutline_DocumentWidget_(d); | 1556 | updateOutline_DocumentWidget_(d); |
1550 | invalidate_DocumentWidget_(d); | 1557 | invalidate_DocumentWidget_(d); |
diff --git a/src/ui/window.c b/src/ui/window.c index 5c7fcaab..f9e58acb 100644 --- a/src/ui/window.c +++ b/src/ui/window.c | |||
@@ -667,9 +667,16 @@ static void updateRootSize_Window_(iWindow *d, iBool notifyAlways) { | |||
667 | const iInt2 oldSize = *size; | 667 | const iInt2 oldSize = *size; |
668 | SDL_GetRendererOutputSize(d->render, &size->x, &size->y); | 668 | SDL_GetRendererOutputSize(d->render, &size->x, &size->y); |
669 | if (notifyAlways || !isEqual_I2(oldSize, *size)) { | 669 | if (notifyAlways || !isEqual_I2(oldSize, *size)) { |
670 | const iBool isHoriz = (d->lastNotifiedSize.x != size->x); | ||
671 | const iBool isVert = (d->lastNotifiedSize.y != size->y); | ||
670 | arrange_Widget(d->root); | 672 | arrange_Widget(d->root); |
671 | postCommandf_App("window.resized width:%d height:%d", size->x, size->y); | 673 | postCommandf_App("window.resized width:%d height:%d horiz:%d vert:%d", |
674 | size->x, | ||
675 | size->y, | ||
676 | isHoriz, | ||
677 | isVert); | ||
672 | postRefresh_App(); | 678 | postRefresh_App(); |
679 | d->lastNotifiedSize = *size; | ||
673 | } | 680 | } |
674 | } | 681 | } |
675 | 682 | ||
@@ -719,6 +726,7 @@ void init_Window(iWindow *d, iRect rect) { | |||
719 | iZap(d->cursors); | 726 | iZap(d->cursors); |
720 | d->initialPos = rect.pos; | 727 | d->initialPos = rect.pos; |
721 | d->lastRect = rect; | 728 | d->lastRect = rect; |
729 | d->lastNotifiedSize = zero_I2(); | ||
722 | d->pendingCursor = NULL; | 730 | d->pendingCursor = NULL; |
723 | d->isDrawFrozen = iTrue; | 731 | d->isDrawFrozen = iTrue; |
724 | d->isMouseInside = iTrue; | 732 | d->isMouseInside = iTrue; |
diff --git a/src/ui/window.h b/src/ui/window.h index 8cadad1b..9e3f16bc 100644 --- a/src/ui/window.h +++ b/src/ui/window.h | |||
@@ -36,6 +36,7 @@ struct Impl_Window { | |||
36 | SDL_Window * win; | 36 | SDL_Window * win; |
37 | iInt2 initialPos; | 37 | iInt2 initialPos; |
38 | iRect lastRect; /* updated when window is moved/resized */ | 38 | iRect lastRect; /* updated when window is moved/resized */ |
39 | iInt2 lastNotifiedSize; /* keep track of horizontal/vertical notifications */ | ||
39 | iBool isDrawFrozen; /* avoids premature draws while restoring window state */ | 40 | iBool isDrawFrozen; /* avoids premature draws while restoring window state */ |
40 | iBool isMouseInside; | 41 | iBool isMouseInside; |
41 | uint32_t focusGainedAt; | 42 | uint32_t focusGainedAt; |