From cebe4050e6cd6415f6480f407077a3a3778ad205 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 16 Dec 2023 12:49:25 +0300 Subject: =?UTF-8?q?fixes=20#4059=20(NewStory:=20=D0=B6=D0=B5=D1=81=D1=82?= =?UTF-8?q?=D0=BA=D0=B8=D0=B5=20=D1=82=D0=BE=D1=80=D0=BC=D0=BE=D0=B7=D0=B0?= =?UTF-8?q?,=20=D0=B2=D1=82=D0=BE=D1=80=D0=B0=D1=8F=20=D1=87=D0=B0=D1=81?= =?UTF-8?q?=D1=82=D1=8C=20=D0=BC=D0=B0=D1=80=D0=BB=D0=B5=D0=B7=D0=BE=D0=BD?= =?UTF-8?q?=D1=81=D0=BA=D0=BE=D0=B3=D0=BE=20=D0=B1=D0=B0=D0=BB=D0=B5=D1=82?= =?UTF-8?q?=D0=B0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/NewStory/src/history_control.cpp | 28 ++++++++++++++++------------ plugins/NewStory/src/history_control.h | 2 +- 2 files changed, 17 insertions(+), 13 deletions(-) (limited to 'plugins/NewStory') diff --git a/plugins/NewStory/src/history_control.cpp b/plugins/NewStory/src/history_control.cpp index f0fd1d29b0..b495a3ac06 100644 --- a/plugins/NewStory/src/history_control.cpp +++ b/plugins/NewStory/src/history_control.cpp @@ -515,11 +515,18 @@ bool NewstoryListData::HasSelection() const return false; } -void NewstoryListData::HitTotal(int y) +void NewstoryListData::HitTotal(int yCurr, int yTotal) { - int i = 0; - while (i < totalCount && y > 0) - y -= GetItemHeight(i++); + int i = 0, y = yCurr; + while (i < totalCount && y > 0) { + auto *pItem = GetItem(i++); + if (!pItem->m_bLoaded) { + i = (totalCount * yCurr) / yTotal; + y = 0; + break; + } + else y -= GetItemHeight(pItem); + } scrollTopItem = i; scrollTopPixel = y; @@ -685,13 +692,10 @@ void NewstoryListData::RecalcScrollBar() } if (numRec != totalCount) { - yTotal = (yTotal * totalCount) / numRec; - for (int i = 0; i < totalCount; i++) - if (i == scrollTopItem) { - yTop = yTotal - scrollTopPixel; - break; - } - } + double averageH = double(yTotal) / double(numRec); + yTotal = totalCount * averageH; + yTop = scrollTopItem * averageH; + } SCROLLINFO si = {}; si.cbSize = sizeof(si); @@ -1400,7 +1404,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->HitTotal(si.nTrackPos); + data->HitTotal(si.nTrackPos, si.nMax); break; default: diff --git a/plugins/NewStory/src/history_control.h b/plugins/NewStory/src/history_control.h index 2f9cd9ac56..463bfe15c2 100644 --- a/plugins/NewStory/src/history_control.h +++ b/plugins/NewStory/src/history_control.h @@ -63,7 +63,7 @@ struct NewstoryListData : public MZeroedObject int GetItemHeight(int index); int GetItemHeight(ItemData *pItem); bool HasSelection() const; - void HitTotal(int y); + void HitTotal(int yCurr, int yTotal); void LineUp(); void LineDown(); ItemData* LoadItem(int idx); -- cgit v1.2.3