From 6c547276ecd32ca58bb8d6f94c5f687dbd96e259 Mon Sep 17 00:00:00 2001 From: ErrorFlynn Date: Sat, 5 Oct 2019 11:19:42 -0400 Subject: [PATCH] bug fix: nana::drawerbase::listbox::essence::where This method incorrectly calculates the position of checkboxes in the listbox content area. It uses the formula `new_where.second * item_h + header_visible_px()` to calculate the number of pixels between the top of the viewport and a checkbox. The problem is that when the first visible item is only partially visible, `new_where.second * item_h` produces an excess of pixels equal to the vertical segment of the first visible item that is not in the viewport. This excess value produces a downward displacement of the calculated checkbox position, so it must be accounted for in the aforementioned formula. This problem occurs because at some point, the library switched from scrolling in item-sized increments to smooth scrolling (in older versions, it used to be that it was impossible for an item to be only partially visible). Relevant thread: http://nanapro.org/en-us/forum/index.php?u=/topic/1227/ggnana-listbox-with-a-check-box-for-each-list-item#post-3359 --- source/gui/widgets/listbox.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/gui/widgets/listbox.cpp b/source/gui/widgets/listbox.cpp index a62a80f8..1fa6a29e 100644 --- a/source/gui/widgets/listbox.cpp +++ b/source/gui/widgets/listbox.cpp @@ -2387,7 +2387,9 @@ namespace nana nana::rectangle r; if (rect_lister(r)) { - auto top = new_where.second * item_h + header_visible_px(); + //potential displacement due to partially visible first visible item + auto disp = origin.y - first_display().item * item_h; + auto top = new_where.second * item_h + header_visible_px() - disp; if (checkarea(item_xpos(r), static_cast(top)).is_hit(pos)) new_where.first = parts::checker; }