Tk Source Code

Artifact [88b0fb83]
Login

Artifact 88b0fb83a3adfa0f7415aaebf1a986f3812101b7ba0f343d9b8016ab186f064f:

Attachment "treeview.diff" to ticket [a9e637f1] added by sbron 2023-12-25 11:18:49.
Index: generic/ttk/ttkTreeview.c
==================================================================
--- generic/ttk/ttkTreeview.c
+++ generic/ttk/ttkTreeview.c
@@ -1615,11 +1615,11 @@
  * 	Invokes scroll callbacks.
  */
 static void TreeviewDoLayout(void *clientData)
 {
     Treeview *tv = clientData;
-    int visibleRows;
+    int totalRows, visibleRows;
 
     Ttk_PlaceLayout(tv->core.layout,tv->core.state,Ttk_WinBox(tv->core.tkwin));
     tv->tree.treeArea = Ttk_ClientRegion(tv->core.layout, "treearea");
 
     ResizeColumns(tv, tv->tree.treeArea.width);
@@ -1634,16 +1634,26 @@
 	    &tv->tree.treeArea, 1, tv->tree.headingHeight, TTK_SIDE_TOP);
     } else {
 	tv->tree.headingArea = Ttk_MakeBox(0,0,0,0);
     }
 
-    visibleRows = tv->tree.treeArea.height / tv->tree.rowHeight;
     tv->tree.root->state |= TTK_STATE_OPEN;
+    totalRows = CountRows(tv->tree.root) - 1;
+    visibleRows = tv->tree.treeArea.height / tv->tree.rowHeight;
+    if (tv->tree.treeArea.height % tv->tree.rowHeight) {
+        /* When the treeview height doesn't correspond to an exact number
+         * of rows, the visible row count must be incremented to draw a
+         * partial row at the bottom. The total row count must also be
+         * incremented to be able to scroll all the way to the bottom.
+         */
+        visibleRows++;
+        totalRows++;
+    }
     TtkScrolled(tv->tree.yscrollHandle,
 	    tv->tree.yscroll.first,
 	    tv->tree.yscroll.first + visibleRows,
-	    CountRows(tv->tree.root) - 1);
+	    totalRows);
 }
 
 /* + TreeviewSize --
  * 	SizeProc() widget hook.  Size is determined by
  * 	-height option and column widths.