Skip to content

Commit

Permalink
Update ColorField.java
Browse files Browse the repository at this point in the history
  • Loading branch information
Fexcraft committed Jul 12, 2022
1 parent 5710fcd commit d6e72dd
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/net/fexcraft/app/fmt/ui/field/ColorField.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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();
}
}
Expand All @@ -100,9 +100,7 @@ public ColorField(Component root, BiConsumer<Integer, Boolean> 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);
}
}
Expand All @@ -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
Expand All @@ -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());
}

Expand All @@ -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;
}

}

0 comments on commit d6e72dd

Please sign in to comment.