From f75430ba4fff52c1363029f14578403e4643ebbc Mon Sep 17 00:00:00 2001 From: Juuxel <6596629+Juuxel@users.noreply.github.com> Date: Thu, 21 May 2020 01:49:36 +0300 Subject: Expose WAbstractSlider.isIncreasing/DecreasingKey as a public API --- .../cotton/gui/widget/WAbstractSlider.java | 30 +++++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'src/main/java') 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); -- cgit