From 4678523c9713ac01ffa8db2054788cbbfce441f8 Mon Sep 17 00:00:00 2001 From: dani162 <34603476+dani162@users.noreply.github.com> Date: Sun, 27 Feb 2022 12:51:35 +0100 Subject: Corrected calculation of the current visible elements in the list panel. (#152) * Corrected calculation of the current visible elements in the list panel. The change fixes the problem that the last element/elements in the list are not shown because the margin spaces weren't properly calculated in the visibleCells variable. Removed unnecessary for-loop run-trough. * Should add one margin to layoutHeight because the dividing element also has margin Co-authored-by: dani162 <{ID}+{username}@users.noreply.github.com> --- src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java index 1247d02..5440bd5 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java @@ -139,7 +139,7 @@ public class WListPanel extends WClippedPanel { if (cellHeight<4) cellHeight=4; int layoutHeight = this.getHeight()-(margin*2); - int cellsHigh = Math.max(layoutHeight / cellHeight, 1); // At least one cell is always visible + int cellsHigh = Math.max((layoutHeight+margin) / (cellHeight + margin), 1); // At least one cell is always visible //System.out.println("Adding children..."); @@ -157,7 +157,7 @@ public class WListPanel extends WClippedPanel { int presentCells = Math.min(data.size()-scrollOffset, cellsHigh); if (presentCells>0) { - for(int i=0; i=data.size()) break; if (index<0) continue; //THIS IS A THING THAT IS HAPPENING >:( -- cgit