diff options
author | xander <xander@isxander.dev> | 2022-09-03 14:08:53 +0100 |
---|---|---|
committer | xander <xander@isxander.dev> | 2022-09-03 14:08:53 +0100 |
commit | 3027527637373d7df682bf56368cf176ffcc19a8 (patch) | |
tree | 7d06ac25b09b1944626e3007ef6831f455c36ec0 /src/main/java/dev/isxander/yacl/gui | |
parent | be878535f0cd82fe3a0a7c7268e1e6fff5c76a2e (diff) | |
download | YetAnotherConfigLib-3027527637373d7df682bf56368cf176ffcc19a8.tar.gz YetAnotherConfigLib-3027527637373d7df682bf56368cf176ffcc19a8.tar.bz2 YetAnotherConfigLib-3027527637373d7df682bf56368cf176ffcc19a8.zip |
pass through type class to option for controllers to use
Diffstat (limited to 'src/main/java/dev/isxander/yacl/gui')
-rw-r--r-- | src/main/java/dev/isxander/yacl/gui/controllers/EnumController.java | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/src/main/java/dev/isxander/yacl/gui/controllers/EnumController.java b/src/main/java/dev/isxander/yacl/gui/controllers/EnumController.java index 5bb3caf..75d2bca 100644 --- a/src/main/java/dev/isxander/yacl/gui/controllers/EnumController.java +++ b/src/main/java/dev/isxander/yacl/gui/controllers/EnumController.java @@ -22,7 +22,6 @@ import java.util.function.Function; public class EnumController<T extends Enum<T>> implements Controller<T> { private final Option<T> option; private final Function<T, Text> valueFormatter; - private final Class<T> enumClass; /** * Constructs a cycling enum controller with a default value formatter. @@ -30,10 +29,9 @@ public class EnumController<T extends Enum<T>> implements Controller<T> { * enum is a {@link NameableEnum} else, just use {@link Enum#name()} * * @param option bound option - * @param enumClass class of enum */ - public EnumController(Option<T> option, Class<T> enumClass) { - this(option, enumClass, value -> { + public EnumController(Option<T> option) { + this(option, value -> { if (value instanceof NameableEnum nameableEnum) return nameableEnum.getDisplayName(); return Text.of(value.name()); @@ -44,13 +42,11 @@ public class EnumController<T extends Enum<T>> implements Controller<T> { * Constructs a cycling enum controller. * * @param option bound option - * @param enumClass class of enum * @param valueFormatter format the enum into any {@link Text} */ - public EnumController(Option<T> option, Class<T> enumClass, Function<T, Text> valueFormatter) { + public EnumController(Option<T> option, Function<T, Text> valueFormatter) { this.option = option; this.valueFormatter = valueFormatter; - this.enumClass = enumClass; } /** @@ -74,7 +70,7 @@ public class EnumController<T extends Enum<T>> implements Controller<T> { */ @Override public ControllerWidget<EnumController<T>> provideWidget(YACLScreen screen, Dimension<Integer> widgetDimension) { - return new EnumControllerElement<>(this, screen, widgetDimension, enumClass.getEnumConstants()); + return new EnumControllerElement<>(this, screen, widgetDimension, option().typeClass().getEnumConstants()); } @ApiStatus.Internal |