aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost/oneconfig/gui/elements/config
diff options
context:
space:
mode:
authorDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-05-06 20:07:44 +0200
committerDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-05-06 20:07:44 +0200
commit1cfdef78d7f51f1d6e50dec4a16ac9dfe5f61a58 (patch)
treefede402dbca2277aef2d81c703265f3e8b8f83a0 /src/main/java/cc/polyfrost/oneconfig/gui/elements/config
parenta2c26edde80c87c4d2a45cd315c3753e303044b1 (diff)
downloadOneConfig-1cfdef78d7f51f1d6e50dec4a16ac9dfe5f61a58.tar.gz
OneConfig-1cfdef78d7f51f1d6e50dec4a16ac9dfe5f61a58.tar.bz2
OneConfig-1cfdef78d7f51f1d6e50dec4a16ac9dfe5f61a58.zip
slider rewrite
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/gui/elements/config')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java31
1 files changed, 19 insertions, 12 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java
index 2e6baae..abae368 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java
@@ -2,8 +2,7 @@ package cc.polyfrost.oneconfig.gui.elements.config;
import cc.polyfrost.oneconfig.config.OneConfigConfig;
import cc.polyfrost.oneconfig.config.interfaces.BasicOption;
-import cc.polyfrost.oneconfig.gui.elements.BasicElement;
-import cc.polyfrost.oneconfig.gui.elements.text.TextInputField;
+import cc.polyfrost.oneconfig.gui.elements.text.NumberInputField;
import cc.polyfrost.oneconfig.lwjgl.RenderManager;
import cc.polyfrost.oneconfig.lwjgl.font.Fonts;
import cc.polyfrost.oneconfig.utils.InputUtils;
@@ -13,36 +12,43 @@ import org.lwjgl.input.Mouse;
import java.lang.reflect.Field;
public class ConfigSlider extends BasicOption {
- private final TextInputField inputField = new TextInputField(84, 24, "", false, false);
+ private final NumberInputField inputField;
private final float min, max;
private boolean isFloat = true;
private final int step;
private boolean dragging = false;
- private int colorTop, colorBottom;
public ConfigSlider(Field field, String name, int size, float min, float max, int step) {
super(field, name, size);
this.min = min;
this.max = max;
this.step = step;
- inputField.onlyAcceptNumbers(true);
- inputField.setCentered(true);
+ inputField = new NumberInputField(84, 24, 0, min, max, step);
}
@Override
public void draw(long vg, int x, int y) {
int xCoordinate = 0;
+ float value = 0;
boolean hovered = InputUtils.isAreaHovered(x + 352, y, 512, 32);
if (hovered && Mouse.isButtonDown(0)) dragging = true;
- if (dragging) xCoordinate = (int) MathUtils.clamp(InputUtils.mouseX(), x + 352, x + 864);
- if (dragging && InputUtils.isClicked()) {
+ if (dragging) {
+ xCoordinate = (int) MathUtils.clamp(InputUtils.mouseX(), x + 352, x + 864);
+ value = MathUtils.map(xCoordinate, x + 352, x + 864, min, max);
+ } else if (inputField.isToggled()) {
+ value = inputField.getCurrentValue();
+ xCoordinate = (int) MathUtils.map(value, min, max, x + 352, x + 864);
+ }
+ if (dragging && InputUtils.isClicked() || inputField.isToggled()) {
dragging = false;
- if (step > 0) xCoordinate = getStepCoordinate(xCoordinate, x);
- setValue(MathUtils.map(xCoordinate, x + 352, x + 864, min, max));
+ if (step > 0) {
+ xCoordinate = getStepCoordinate(xCoordinate, x);
+ value = MathUtils.map(xCoordinate, x + 352, x + 864, min, max);
+ }
+ setValue(value);
}
- float value = 0;
- if (!dragging) {
+ if (!dragging && !inputField.isToggled()) {
try {
Object object = get();
if (object instanceof Integer)
@@ -53,6 +59,7 @@ public class ConfigSlider extends BasicOption {
} catch (IllegalAccessException ignored) {
}
}
+ if (!inputField.isToggled()) inputField.setCurrentValue(value);
RenderManager.drawString(vg, name, x, y + 17, OneConfigConfig.WHITE_90, 14f, Fonts.INTER_MEDIUM);
RenderManager.drawRoundedRect(vg, x + 352, y + 13, 512, 6, OneConfigConfig.GRAY_300, 4f);