diff options
author | Juuxel <6596629+Juuxel@users.noreply.github.com> | 2021-02-02 17:51:41 +0200 |
---|---|---|
committer | Juuxel <6596629+Juuxel@users.noreply.github.com> | 2021-02-02 17:52:31 +0200 |
commit | f5e123896a53957d61c40a48beea8a0a473f9db6 (patch) | |
tree | 92850b0cfc957859289f79e014f06cc0cfd3bc33 /src/main/java/io | |
parent | 2588e014d5c647ee62021369b9831adae4b7c7a0 (diff) | |
download | LibGui-f5e123896a53957d61c40a48beea8a0a473f9db6.tar.gz LibGui-f5e123896a53957d61c40a48beea8a0a473f9db6.tar.bz2 LibGui-f5e123896a53957d61c40a48beea8a0a473f9db6.zip |
WScrollPanel: Add mouse scrolling support
Diffstat (limited to 'src/main/java/io')
-rw-r--r-- | src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollPanel.java | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollPanel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollPanel.java index e66d359..b3513cb 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollPanel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollPanel.java @@ -6,6 +6,7 @@ import net.fabricmc.fabric.api.util.TriState; import net.minecraft.client.util.math.MatrixStack; import io.github.cottonmc.cotton.gui.widget.data.Axis; +import io.github.cottonmc.cotton.gui.widget.data.InputResult; /** * Similar to the JScrollPane in Swing, this widget represents a scrollable widget. @@ -104,12 +105,8 @@ public class WScrollPanel extends WClippedPanel { public void layout() { children.clear(); - boolean horizontal = (scrollingHorizontally == TriState.DEFAULT) - ? (widget.width > this.width - SCROLL_BAR_SIZE) - : scrollingHorizontally.get(); - boolean vertical = (scrollingVertically == TriState.DEFAULT) - ? (widget.height > this.height - SCROLL_BAR_SIZE) - : scrollingVertically.get(); + boolean horizontal = hasHorizontalScrollbar(); + boolean vertical = hasVerticalScrollbar(); int offset = (horizontal && vertical) ? SCROLL_BAR_SIZE : 0; verticalScrollBar.setSize(SCROLL_BAR_SIZE, this.height - offset); @@ -131,4 +128,25 @@ public class WScrollPanel extends WClippedPanel { if (vertical) children.add(verticalScrollBar); if (horizontal) children.add(horizontalScrollBar); } + + private boolean hasHorizontalScrollbar() { + return (scrollingHorizontally == TriState.DEFAULT) + ? (widget.width > this.width - SCROLL_BAR_SIZE) + : scrollingHorizontally.get(); + } + + private boolean hasVerticalScrollbar() { + return (scrollingVertically == TriState.DEFAULT) + ? (widget.height > this.height - SCROLL_BAR_SIZE) + : scrollingVertically.get(); + } + + @Override + public InputResult onMouseScroll(int x, int y, double amount) { + if (hasVerticalScrollbar()) { + return verticalScrollBar.onMouseScroll(0, 0, amount); + } + + return InputResult.IGNORED; + } } |