From e71d2283b1eb16bc769e51910e2a400817021819 Mon Sep 17 00:00:00 2001 From: Juuxel Date: Wed, 28 Aug 2019 20:56:47 +0300 Subject: Sliders: Add keyboard support, fix clicking, highlight when focused --- .../cotton/gui/client/modmenu/ConfigGui.java | 2 +- .../github/cottonmc/cotton/gui/widget/WSlider.java | 80 ++++++++++++++++----- .../assets/libgui/textures/widget/slider.png | Bin 2295 -> 2597 bytes 3 files changed, 62 insertions(+), 20 deletions(-) (limited to 'src/main') diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ConfigGui.java b/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ConfigGui.java index 2bca040..fc3e3b5 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ConfigGui.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ConfigGui.java @@ -33,7 +33,7 @@ public class ConfigGui extends LightweightGuiDescription { testField.setSuggestion("test"); root.add(testField, 0, 3, 4, 1); root.add(new WSlider(-1, 1, Axis.VERTICAL).setValueChangeListener(System.out::println), 6, 0, 1, 3); - root.add(new WSlider(-1, 0, Axis.HORIZONTAL).setValueChangeListener(System.out::println), 1, 4, 4, 1); + root.add(new WSlider(1, 2, Axis.HORIZONTAL).setValueChangeListener(System.out::println), 1, 4, 4, 1); root.add(new WKirbSprite(), 5, 4); diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WSlider.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WSlider.java index 26574dd..d981304 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WSlider.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WSlider.java @@ -6,6 +6,7 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; +import org.lwjgl.glfw.GLFW; import javax.annotation.Nullable; import java.util.function.IntConsumer; @@ -15,7 +16,9 @@ import java.util.function.IntConsumer; * *

You can set two listeners on a slider: *