diff options
author | LopyMine <127966446+LopyMine@users.noreply.github.com> | 2023-10-15 16:17:06 +0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-15 14:17:06 +0300 |
commit | 3e74a563b2d2d3e0683733c3b4e52bac768659fd (patch) | |
tree | f1f27e705b5882b1bfa4e50f8eafe3e876dc5e28 /src/main | |
parent | 41726ca942739f7283e0530aaa08cece365b3146 (diff) | |
download | LibGui-3e74a563b2d2d3e0683733c3b4e52bac768659fd.tar.gz LibGui-3e74a563b2d2d3e0683733c3b4e52bac768659fd.tar.bz2 LibGui-3e74a563b2d2d3e0683733c3b4e52bac768659fd.zip |
Added set/getScrollingSpeed methods and updated ScrollBarTestGui.java (#218)
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java | 29 |
1 files changed, 27 insertions, 2 deletions
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 add8688..ac5ddcb 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 @@ -15,7 +15,8 @@ import io.github.cottonmc.cotton.gui.widget.data.InputResult; public class WScrollBar extends WWidget { private static final Identifier FOCUS_TEXTURE = new Identifier(LibGuiCommon.MOD_ID, "widget/scroll_bar/focus"); - private static final int SCROLLING_SPEED = 4; + public static final int DEFAULT_SCROLLING_SPEED = 4; + private int scrollingSpeed = 4; protected Axis axis = Axis.HORIZONTAL; protected int value; @@ -203,7 +204,7 @@ public class WScrollBar extends WWidget { @Environment(EnvType.CLIENT) @Override public InputResult onMouseScroll(int x, int y, double horizontalAmount, double verticalAmount) { - setValue(getValue() + (int) (horizontalAmount - verticalAmount) * SCROLLING_SPEED); + setValue(getValue() + (int) (horizontalAmount - verticalAmount) * scrollingSpeed); return InputResult.PROCESSED; } @@ -227,6 +228,30 @@ public class WScrollBar extends WWidget { return this; } + /** + * Sets the mouse scroll speed; + * <p> + * Default value: {@value #DEFAULT_SCROLLING_SPEED} + * @param scrollingSpeed the scroll speed + * @return this scroll bar + */ + public WScrollBar setScrollingSpeed(int scrollingSpeed) { + if(scrollingSpeed < 0) throw new IllegalArgumentException("Negative value for scrolling speed"); + if(scrollingSpeed == 0) throw new IllegalArgumentException("Zero value for scrolling speed"); + + this.scrollingSpeed = scrollingSpeed; + return this; + } + + /** + * Gets the mouse scroll speed; + * <p> + * Default value: {@value #DEFAULT_SCROLLING_SPEED} + */ + public int getScrollingSpeed() { + return scrollingSpeed; + } + public int getWindow() { return window; } |