aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJuuxel <6596629+Juuxel@users.noreply.github.com>2020-05-21 01:49:36 +0300
committerJuuxel <6596629+Juuxel@users.noreply.github.com>2020-05-21 01:49:36 +0300
commitf75430ba4fff52c1363029f14578403e4643ebbc (patch)
tree7daef11ba20a3ae2a87439d5c0e7b5c84ea80ed5 /src
parent67369945f0529a457b024a6645642995b3b94492 (diff)
downloadLibGui-f75430ba4fff52c1363029f14578403e4643ebbc.tar.gz
LibGui-f75430ba4fff52c1363029f14578403e4643ebbc.tar.bz2
LibGui-f75430ba4fff52c1363029f14578403e4643ebbc.zip
Expose WAbstractSlider.isIncreasing/DecreasingKey as a public API
Diffstat (limited to 'src')
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java30
1 files changed, 23 insertions, 7 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java
index 17b88c1..1a440e9 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java
@@ -304,18 +304,18 @@ public abstract class WAbstractSlider extends WWidget {
public void onKeyPressed(int ch, int key, int modifiers) {
boolean valueChanged = false;
if (modifiers == 0) {
- if (isDecreasingKey(ch) && value > min) {
+ if (isDecreasingKey(ch, direction) && value > min) {
value--;
valueChanged = true;
- } else if (isIncreasingKey(ch) && value < max) {
+ } else if (isIncreasingKey(ch, direction) && value < max) {
value++;
valueChanged = true;
}
} else if (modifiers == GLFW.GLFW_MOD_CONTROL) {
- if (isDecreasingKey(ch) && value != min) {
+ if (isDecreasingKey(ch, direction) && value != min) {
value = min;
valueChanged = true;
- } else if (isIncreasingKey(ch) && value != max) {
+ } else if (isIncreasingKey(ch, direction) && value != max) {
value = max;
valueChanged = true;
}
@@ -330,19 +330,35 @@ public abstract class WAbstractSlider extends WWidget {
@Environment(EnvType.CLIENT)
@Override
public void onKeyReleased(int ch, int key, int modifiers) {
- if (pendingDraggingFinishedFromKeyboard && (isDecreasingKey(ch) || isIncreasingKey(ch))) {
+ if (pendingDraggingFinishedFromKeyboard && (isDecreasingKey(ch, direction) || isIncreasingKey(ch, direction))) {
if (draggingFinishedListener != null) draggingFinishedListener.accept(value);
pendingDraggingFinishedFromKeyboard = false;
}
}
- private boolean isDecreasingKey(int ch) {
+ /**
+ * Tests if the key should decrease sliders with the specified direction.
+ *
+ * @param ch the key code
+ * @param direction the direction
+ * @return true if the key should decrease sliders with the direction, false otherwise
+ * @since 2.0.0
+ */
+ public static boolean isDecreasingKey(int ch, Direction direction) {
return direction.isInverted()
? (ch == GLFW.GLFW_KEY_RIGHT || ch == GLFW.GLFW_KEY_UP)
: (ch == GLFW.GLFW_KEY_LEFT || ch == GLFW.GLFW_KEY_DOWN);
}
- private boolean isIncreasingKey(int ch) {
+ /**
+ * Tests if the key should increase sliders with the specified direction.
+ *
+ * @param ch the key code
+ * @param direction the direction
+ * @return true if the key should increase sliders with the direction, false otherwise
+ * @since 2.0.0
+ */
+ public static boolean isIncreasingKey(int ch, Direction direction) {
return direction.isInverted()
? (ch == GLFW.GLFW_KEY_LEFT || ch == GLFW.GLFW_KEY_DOWN)
: (ch == GLFW.GLFW_KEY_RIGHT || ch == GLFW.GLFW_KEY_UP);