From 5cab567e8b9ff95e2637459dc0d92f6696052100 Mon Sep 17 00:00:00 2001 From: Juuxel <6596629+Juuxel@users.noreply.github.com> Date: Fri, 21 Feb 2020 08:37:57 +0200 Subject: Add more getters and setters for scroll bars Closes #34. --- .../cottonmc/cotton/gui/widget/WListPanel.java | 4 +-- .../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 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; } } -- cgit