mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 08:27:45 +00:00
Sizing
This commit is contained in:
1 parent
9480212c4d
commit
3ea6303fc3
3 files changed
+34
-3
No files matched your search
@@ -1,5 +1,6 @@
|
||||
package somehussar.gui;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@@ -15,10 +16,31 @@ public @interface GuiEditable {
|
||||
* Higher value = higher priority.
|
||||
*/
|
||||
int order() default 0;
|
||||
|
||||
}
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface Group {
|
||||
String value();
|
||||
}
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface Size {
|
||||
int labelWidth() default 60;
|
||||
int fieldWidth() default 50;
|
||||
|
||||
GuiEditable.Size DEFAULT_SIZE = new GuiEditable.Size() {
|
||||
@Override
|
||||
public int labelWidth() {
|
||||
return 60;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fieldWidth() {
|
||||
return 50;
|
||||
}
|
||||
@Override public Class<? extends Annotation> annotationType() { return GuiEditable.Size.class; }
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ public final class GuiFieldHandler {
|
||||
return CACHE.computeIfAbsent(type, GuiFieldHandler::scanClass);
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings({"RawUseOfParameterized"})
|
||||
private static ClassMetadata scanClass(Class<?> type) {
|
||||
if (!type.isAnnotationPresent(GuiEditable.class)) {
|
||||
return null;
|
||||
@@ -66,6 +66,9 @@ public final class GuiFieldHandler {
|
||||
if (fieldConfig == null) return null;
|
||||
if (Modifier.isFinal(field.getModifiers())) return null;
|
||||
|
||||
GuiEditable.Size size = field.getAnnotation(GuiEditable.Size.class);
|
||||
if (size == null) size = GuiEditable.Size.DEFAULT_SIZE;;
|
||||
|
||||
field.setAccessible(true);
|
||||
EditableField.Builder builder = new EditableField.Builder()
|
||||
.name(fieldConfig.value())
|
||||
@@ -73,7 +76,9 @@ public final class GuiFieldHandler {
|
||||
.getter(LOOKUP.unreflectGetter(field))
|
||||
.setter(LOOKUP.unreflectSetter(field))
|
||||
.constraints(buildConstraints(field))
|
||||
.order(fieldConfig.order());
|
||||
.order(fieldConfig.order())
|
||||
.size(size);
|
||||
|
||||
|
||||
GuiEditable.Group group = field.getAnnotation(GuiEditable.Group.class);
|
||||
if (group != null)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package somehussar.gui.field;
|
||||
|
||||
import somehussar.gui.FieldConstraints;
|
||||
import somehussar.gui.GuiEditable;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
|
||||
@@ -13,6 +14,7 @@ public final class EditableField<T> {
|
||||
private final FieldConstraints constraints;
|
||||
private final int order;
|
||||
private final String group;
|
||||
private final GuiEditable.Size size;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
@@ -54,6 +56,7 @@ public final class EditableField<T> {
|
||||
this.constraints = b.constraints;
|
||||
this.order = b.order;
|
||||
this.group = b.group;
|
||||
this.size = b.size;
|
||||
}
|
||||
|
||||
public static class Builder<T> {
|
||||
@@ -64,6 +67,7 @@ public final class EditableField<T> {
|
||||
private FieldConstraints constraints;
|
||||
private int order;
|
||||
private String group = null;
|
||||
private GuiEditable.Size size;
|
||||
|
||||
public Builder<T> name(String v) { this.name = v; return this; }
|
||||
public Builder<T> type(Class<T> v) { this.type = v; return this; }
|
||||
@@ -72,10 +76,10 @@ public final class EditableField<T> {
|
||||
public Builder<T> constraints(FieldConstraints v) { this.constraints = v; return this; }
|
||||
public Builder<T> order(int order) { this.order = order; return this; }
|
||||
public Builder<T> group(String value) { this.group = value; return this; }
|
||||
public Builder<T> size(GuiEditable.Size size) { this.size = size; return this; }
|
||||
|
||||
public EditableField<T> build() {
|
||||
return new EditableField<>(this);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user