Skip to content

Commit d6e72dd

Browse files
committed
Update ColorField.java
1 parent 5710fcd commit d6e72dd

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/net/fexcraft/app/fmt/ui/field/ColorField.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public ColorField(Component root, String field, int x, int y, int w, int h){
5050
if(event.getAction() == CLICK){
5151
try(MemoryStack stack = MemoryStack.stackPush()) {
5252
ByteBuffer color = stack.malloc(3);
53-
String result = TinyFileDialogs.tinyfd_colorChooser("Choose A Color", "#" + Integer.toHexString((int)getValue()), null, color);
53+
String result = TinyFileDialogs.tinyfd_colorChooser("Choose A Color", "#" + amz((int)getValue()), null, color);
5454
if(result == null) return; this.getTextState().setText(result); value = null; FMTB.MODEL.updateValue(this, fieldid);
5555
}
5656
}
@@ -75,7 +75,7 @@ public ColorField(Component root, Setting setting, int x, int y, int w, int h){
7575
if(event.getAction() == CLICK){
7676
try(MemoryStack stack = MemoryStack.stackPush()) {
7777
ByteBuffer color = stack.malloc(3);
78-
String result = TinyFileDialogs.tinyfd_colorChooser("Choose A Color", "#" + Integer.toHexString((int)getValue()), null, color);
78+
String result = TinyFileDialogs.tinyfd_colorChooser("Choose A Color", "#" + amz((int)getValue()), null, color);
7979
if(result == null) return; this.getTextState().setText(result); value = null; ((RGB)setting.getValue()).packed = (int)getValue();
8080
}
8181
}
@@ -100,9 +100,7 @@ public ColorField(Component root, BiConsumer<Integer, Boolean> update, int x, in
100100
if(event.getAction() == CLICK){
101101
try(MemoryStack stack = MemoryStack.stackPush()) {
102102
ByteBuffer color = stack.malloc(3);
103-
String colorstring = Integer.toHexString((int)getValue());
104-
for(int i = 0; i < 5; i++) if(colorstring.length() < 6) colorstring = "0" + colorstring; else break;
105-
String result = TinyFileDialogs.tinyfd_colorChooser("Choose A Color", "#" + colorstring, null, color);
103+
String result = TinyFileDialogs.tinyfd_colorChooser("Choose A Color", "#" + amz((int)getValue()), null, color);
106104
if(result == null) return; this.getTextState().setText(result); value = null; update.accept((int)getValue(), event.getButton() == MouseButton.MOUSE_BUTTON_LEFT);
107105
}
108106
}
@@ -120,7 +118,8 @@ public float getValue(){
120118
catch(Exception e){
121119
log(e);
122120
}
123-
apply(newval); return value = (int)newval;
121+
apply(newval);
122+
return value = (int)newval;
124123
}
125124

126125
@Override
@@ -130,7 +129,7 @@ public float tryAdd(float flat, boolean positive, float rate){
130129

131130
@Override
132131
public void apply(float val){
133-
getTextState().setText("#" + Integer.toHexString(value = (int)val));
132+
getTextState().setText("#" + amz(value = (int)val));
134133
setCaretPosition(getTextState().getText().length());
135134
}
136135

@@ -145,4 +144,10 @@ public String id(){
145144
return fieldid;
146145
}
147146

147+
public String amz(int hex){
148+
String str = Integer.toHexString(hex);
149+
for(int i = 0; i < 5; i++) if(str.length() < 6) str = "0" + str; else break;
150+
return str;
151+
}
152+
148153
}

0 commit comments

Comments
 (0)