summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2023-12-10 15:09:02 +0300
committerGeorge Hazan <george.hazan@gmail.com>2023-12-10 15:09:02 +0300
commit76646f7a6d85fd5cdef2a610e0711bf4a9d8fdf3 (patch)
tree7e3b49e49b7d0de106ab529667f2b14f44c7334e /plugins
parent83d43c21087fbfc022528aeafbbd079dd8a6deb8 (diff)
fixes #3996 (NewStory: scrollbar is broken again)
Diffstat (limited to 'plugins')
-rw-r--r--plugins/NewStory/src/history_control.cpp29
-rw-r--r--plugins/NewStory/src/history_control.h1
2 files changed, 23 insertions, 7 deletions
diff --git a/plugins/NewStory/src/history_control.cpp b/plugins/NewStory/src/history_control.cpp
index 1471992670..7ec860c3c8 100644
--- a/plugins/NewStory/src/history_control.cpp
+++ b/plugins/NewStory/src/history_control.cpp
@@ -524,6 +524,17 @@ bool NewstoryListData::HasSelection() const
return false;
}
+void NewstoryListData::HitTotal(int y)
+{
+ int i = 0;
+ while (i < totalCount && y > 0)
+ y -= GetItemHeight(i++);
+
+ scrollTopItem = i;
+ scrollTopPixel = y;
+ FixScrollPosition();
+}
+
ItemData* NewstoryListData::LoadItem(int idx)
{
if (totalCount == 0)
@@ -616,13 +627,20 @@ void NewstoryListData::RecalcScrollBar()
if (totalCount == 0)
return;
+ int yTotal = 0, yTop = 0;
+ for (int i = 0; i < totalCount; i++) {
+ if (i == scrollTopItem)
+ yTop = yTotal - scrollTopPixel;
+ yTotal += GetItemHeight(i);
+ }
+
SCROLLINFO si = {};
si.cbSize = sizeof(si);
si.fMask = SIF_ALL;
si.nMin = 0;
- si.nMax = totalCount-1;
- si.nPage = (totalCount <= 10) ? totalCount - 1 : 10;
- si.nPos = scrollTopItem;
+ si.nMax = yTotal;
+ si.nPage = cachedWindowHeight;
+ si.nPos = yTop;
if (si.nPos != cachedScrollbarPos || si.nMax != cachedScrollbarMax) {
cachedScrollbarPos = si.nPos;
@@ -1323,10 +1341,7 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
si.cbSize = sizeof(si);
si.fMask = SIF_ALL;
GetScrollInfo(hwnd, SB_VERT, &si);
-
- data->scrollTopItem = si.nTrackPos;
- data->scrollTopPixel = 0;
- data->FixScrollPosition();
+ data->HitTotal(si.nTrackPos);
break;
default:
diff --git a/plugins/NewStory/src/history_control.h b/plugins/NewStory/src/history_control.h
index 4dddd88e21..d726b32ea7 100644
--- a/plugins/NewStory/src/history_control.h
+++ b/plugins/NewStory/src/history_control.h
@@ -62,6 +62,7 @@ struct NewstoryListData : public MZeroedObject
int GetItemFromPixel(int yPos);
int GetItemHeight(int index);
bool HasSelection() const;
+ void HitTotal(int y);
void LineUp();
void LineDown();
ItemData* LoadItem(int idx);