diff options
author | Juuxel <6596629+Juuxel@users.noreply.github.com> | 2020-02-21 08:37:57 +0200 |
---|---|---|
committer | Juuxel <6596629+Juuxel@users.noreply.github.com> | 2020-02-21 08:37:57 +0200 |
commit | 5cab567e8b9ff95e2637459dc0d92f6696052100 (patch) | |
tree | 8812aae283e0cf18019df4ecd51a744c124e661d | |
parent | f0778f0e5222a34090860236473f51d03d871b6d (diff) | |
download | LibGui-5cab567e8b9ff95e2637459dc0d92f6696052100.tar.gz LibGui-5cab567e8b9ff95e2637459dc0d92f6696052100.tar.bz2 LibGui-5cab567e8b9ff95e2637459dc0d92f6696052100.zip |
Add more getters and setters for scroll bars
Closes #34.
-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; } } |