diff options
-rw-r--r-- | src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java | 4 | ||||
-rw-r--r-- | src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java | 31 |
2 files changed, 31 insertions, 4 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 0c002da..32e56c4 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 @@ -122,9 +122,9 @@ public class WListPanel<D, W extends WWidget> extends WClippedPanel { //scrollBar.setSize(8, this.height); //Fix up the scrollbar handle and track metrics - scrollBar.window = cellsHigh; + scrollBar.setWindow(cellsHigh); //scrollBar.setMaxValue(data.size()); - int scrollOffset = scrollBar.value; + int scrollOffset = scrollBar.getValue(); //System.out.println(scrollOffset); int presentCells = Math.min(data.size()-scrollOffset, cellsHigh); diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java index e493152..71ec4e4 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java @@ -121,13 +121,40 @@ public class WScrollBar extends WWidget { public int getValue() { return value; } - + + public WScrollBar setValue(int value) { + this.value = value; + checkValue(); + return this; + } + + public int getMaxValue() { + return maxValue; + } + public WScrollBar setMaxValue(int max) { this.maxValue = max; + checkValue(); + return this; + } + + public int getWindow() { + return window; + } + + public WScrollBar setWindow(int window) { + this.window = window; + return this; + } + + /** + * Checks that the current value is in the correct range + * and adjusts it if needed. + */ + protected void checkValue() { if (this.value>maxValue-window) { this.value = maxValue-window; } if (this.value<0) this.value = 0; - return this; } } |