diff --git a/src/net/fexcraft/app/fmt/ui/field/ColorField.java b/src/net/fexcraft/app/fmt/ui/field/ColorField.java index a5001dc3..50795cfb 100644 --- a/src/net/fexcraft/app/fmt/ui/field/ColorField.java +++ b/src/net/fexcraft/app/fmt/ui/field/ColorField.java @@ -50,7 +50,7 @@ public ColorField(Component root, String field, int x, int y, int w, int h){ if(event.getAction() == CLICK){ try(MemoryStack stack = MemoryStack.stackPush()) { ByteBuffer color = stack.malloc(3); - String result = TinyFileDialogs.tinyfd_colorChooser("Choose A Color", "#" + Integer.toHexString((int)getValue()), null, color); + String result = TinyFileDialogs.tinyfd_colorChooser("Choose A Color", "#" + amz((int)getValue()), null, color); if(result == null) return; this.getTextState().setText(result); value = null; FMTB.MODEL.updateValue(this, fieldid); } } @@ -75,7 +75,7 @@ public ColorField(Component root, Setting setting, int x, int y, int w, int h){ if(event.getAction() == CLICK){ try(MemoryStack stack = MemoryStack.stackPush()) { ByteBuffer color = stack.malloc(3); - String result = TinyFileDialogs.tinyfd_colorChooser("Choose A Color", "#" + Integer.toHexString((int)getValue()), null, color); + String result = TinyFileDialogs.tinyfd_colorChooser("Choose A Color", "#" + amz((int)getValue()), null, color); if(result == null) return; this.getTextState().setText(result); value = null; ((RGB)setting.getValue()).packed = (int)getValue(); } } @@ -100,9 +100,7 @@ public ColorField(Component root, BiConsumer update, int x, in if(event.getAction() == CLICK){ try(MemoryStack stack = MemoryStack.stackPush()) { ByteBuffer color = stack.malloc(3); - String colorstring = Integer.toHexString((int)getValue()); - for(int i = 0; i < 5; i++) if(colorstring.length() < 6) colorstring = "0" + colorstring; else break; - String result = TinyFileDialogs.tinyfd_colorChooser("Choose A Color", "#" + colorstring, null, color); + String result = TinyFileDialogs.tinyfd_colorChooser("Choose A Color", "#" + amz((int)getValue()), null, color); if(result == null) return; this.getTextState().setText(result); value = null; update.accept((int)getValue(), event.getButton() == MouseButton.MOUSE_BUTTON_LEFT); } } @@ -120,7 +118,8 @@ public float getValue(){ catch(Exception e){ log(e); } - apply(newval); return value = (int)newval; + apply(newval); + return value = (int)newval; } @Override @@ -130,7 +129,7 @@ public float tryAdd(float flat, boolean positive, float rate){ @Override public void apply(float val){ - getTextState().setText("#" + Integer.toHexString(value = (int)val)); + getTextState().setText("#" + amz(value = (int)val)); setCaretPosition(getTextState().getText().length()); } @@ -145,4 +144,10 @@ public String id(){ return fieldid; } + public String amz(int hex){ + String str = Integer.toHexString(hex); + for(int i = 0; i < 5; i++) if(str.length() < 6) str = "0" + str; else break; + return str; + } + }