diff options
author | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-05-06 20:07:44 +0200 |
---|---|---|
committer | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-05-06 20:07:44 +0200 |
commit | 1cfdef78d7f51f1d6e50dec4a16ac9dfe5f61a58 (patch) | |
tree | fede402dbca2277aef2d81c703265f3e8b8f83a0 /src/main/java/cc/polyfrost/oneconfig/gui/elements/text | |
parent | a2c26edde80c87c4d2a45cd315c3753e303044b1 (diff) | |
download | OneConfig-1cfdef78d7f51f1d6e50dec4a16ac9dfe5f61a58.tar.gz OneConfig-1cfdef78d7f51f1d6e50dec4a16ac9dfe5f61a58.tar.bz2 OneConfig-1cfdef78d7f51f1d6e50dec4a16ac9dfe5f61a58.zip |
slider rewrite
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/gui/elements/text')
-rw-r--r-- | src/main/java/cc/polyfrost/oneconfig/gui/elements/text/NumberInputField.java | 81 | ||||
-rw-r--r-- | src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java | 1 |
2 files changed, 42 insertions, 40 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/NumberInputField.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/NumberInputField.java index 0e28a90..1eefe74 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/NumberInputField.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/NumberInputField.java @@ -33,49 +33,50 @@ public class NumberInputField extends TextInputField { downArrow.update(x + width + 4, y + 14); try { current = Float.parseFloat(input); - if (current < min || current > max) { - super.errored = true; - } else { - upArrow.disable(false); - downArrow.disable(false); - } - if (current == max) colorTop = OneConfigConfig.GRAY_500_80; - if (current == min) colorBottom = OneConfigConfig.GRAY_500_80; - - colorTop = ColorUtils.getColor(colorTop, 2, upArrow.isHovered(), upArrow.isClicked()); - colorBottom = ColorUtils.getColor(colorBottom, 2, downArrow.isHovered(), downArrow.isClicked()); - if (upArrow.isClicked()) { - current += step; - if (current > max) current = max; - setCurrentValue(current); - } - if (downArrow.isClicked()) { - current -= step; - if(current < min) current = min; - setCurrentValue(current); - } - if (current >= max) { - NanoVG.nvgGlobalAlpha(vg, 0.3f); - upArrow.disable(true); - } - RenderManager.drawRoundedRectVaried(vg, x + width + 4, y, 12, 14, colorTop, 6f, 6f, 0f, 0f); - RenderManager.drawImage(vg, Images.UP_ARROW, x + width + 5, y + 2, 10, 10); - if (current >= max) NanoVG.nvgGlobalAlpha(vg, 1f); - - if (current <= min) { - NanoVG.nvgGlobalAlpha(vg, 0.3f); - downArrow.disable(true); - } - RenderManager.drawRoundedRectVaried(vg, x + width + 4, y + 14, 12, 14, colorBottom, 0f, 0f, 6f, 6f); - NanoVG.nvgTranslate(vg, x + width + 15, y + 25); - NanoVG.nvgRotate(vg, (float) Math.toRadians(180)); - RenderManager.drawImage(vg, Images.UP_ARROW, 0, 0, 10, 10); - NanoVG.nvgResetTransform(vg); - NanoVG.nvgGlobalAlpha(vg, 1f); + } catch (NumberFormatException e) { + super.errored = true; + } - } catch (Exception e) { + if (current < min || current > max) { super.errored = true; + } else { + upArrow.disable(false); + downArrow.disable(false); + } + if (current == max) colorTop = OneConfigConfig.GRAY_500_80; + if (current == min) colorBottom = OneConfigConfig.GRAY_500_80; + + colorTop = ColorUtils.getColor(colorTop, 2, upArrow.isHovered(), upArrow.isClicked()); + colorBottom = ColorUtils.getColor(colorBottom, 2, downArrow.isHovered(), downArrow.isClicked()); + if (upArrow.isClicked()) { + current += step; + if (current > max) current = max; + setCurrentValue(current); } + if (downArrow.isClicked()) { + current -= step; + if (current < min) current = min; + setCurrentValue(current); + } + if (current >= max) { + NanoVG.nvgGlobalAlpha(vg, 0.3f); + upArrow.disable(true); + } + RenderManager.drawRoundedRectVaried(vg, x + width + 4, y, 12, 14, colorTop, 6f, 6f, 0f, 0f); + RenderManager.drawImage(vg, Images.UP_ARROW, x + width + 5, y + 2, 10, 10); + if (current >= max) NanoVG.nvgGlobalAlpha(vg, 1f); + + if (current <= min) { + NanoVG.nvgGlobalAlpha(vg, 0.3f); + downArrow.disable(true); + } + RenderManager.drawRoundedRectVaried(vg, x + width + 4, y + 14, 12, 14, colorBottom, 0f, 0f, 6f, 6f); + NanoVG.nvgTranslate(vg, x + width + 15, y + 25); + NanoVG.nvgRotate(vg, (float) Math.toRadians(180)); + RenderManager.drawImage(vg, Images.UP_ARROW, 0, 0, 10, 10); + NanoVG.nvgResetTransform(vg); + NanoVG.nvgGlobalAlpha(vg, 1f); + try { super.draw(vg, x, y - 2); } catch (Exception e) { diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java index 6983ae8..2ad851b 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java @@ -96,6 +96,7 @@ public class TextInputField extends BasicElement { } int color = toggled ? OneConfigConfig.WHITE : OneConfigConfig.WHITE_60; if (!toggled) caretPos = input.length(); + if (caretPos > input.length()) caretPos = input.length(); float width; StringBuilder s = new StringBuilder(); if (!password) { |