aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/dev/isxander/yacl/api/Option.java
diff options
context:
space:
mode:
authorxander <xander@isxander.dev>2022-09-01 08:57:59 +0100
committerxander <xander@isxander.dev>2022-09-01 08:57:59 +0100
commit6f8ef7daaafd71090b2c334c10eadc8dedc738d9 (patch)
treed4054a65d99070c944132be83d25e109750dc5f9 /src/main/java/dev/isxander/yacl/api/Option.java
parent9d0a5e937f97c1c17d034393e01636d5241f376a (diff)
downloadYetAnotherConfigLib-6f8ef7daaafd71090b2c334c10eadc8dedc738d9.tar.gz
YetAnotherConfigLib-6f8ef7daaafd71090b2c334c10eadc8dedc738d9.tar.bz2
YetAnotherConfigLib-6f8ef7daaafd71090b2c334c10eadc8dedc738d9.zip
GUI Implementation
Added groups Added button "option" Added test mod
Diffstat (limited to 'src/main/java/dev/isxander/yacl/api/Option.java')
-rw-r--r--src/main/java/dev/isxander/yacl/api/Option.java21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/main/java/dev/isxander/yacl/api/Option.java b/src/main/java/dev/isxander/yacl/api/Option.java
index 1c7a8a1..5a98d50 100644
--- a/src/main/java/dev/isxander/yacl/api/Option.java
+++ b/src/main/java/dev/isxander/yacl/api/Option.java
@@ -10,6 +10,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
+import java.util.function.Function;
import java.util.function.Supplier;
public interface Option<T> {
@@ -23,11 +24,17 @@ public interface Option<T> {
boolean changed();
+ T pendingValue();
+
void requestSet(T value);
void applyValue();
- static <T> Builder<T> createBuilder() {
+ void forgetPendingValue();
+
+ void requestSetDefault();
+
+ static <T> Builder<T> createBuilder(Class<T> clazz) {
return new Builder<>();
}
@@ -36,7 +43,7 @@ public interface Option<T> {
private final List<Text> tooltipLines = new ArrayList<>();
- private Control<T> control;
+ private Function<Option<T>, Control<T>> controlGetter;
private Binding<T> binding;
@@ -58,10 +65,10 @@ public interface Option<T> {
return this;
}
- public Builder<T> controller(@NotNull Control<T> control) {
+ public Builder<T> controller(@NotNull Function<Option<T>, Control<T>> control) {
Validate.notNull(control, "`control` cannot be null");
- this.control = control;
+ this.controlGetter = control;
return this;
}
@@ -73,7 +80,7 @@ public interface Option<T> {
}
public Builder<T> binding(@NotNull T def, @NotNull Supplier<@NotNull T> getter, @NotNull Consumer<@NotNull T> setter) {
- Validate.notNull(def, "`default` must not be null");
+ Validate.notNull(def, "`def` must not be null");
Validate.notNull(getter, "`getter` must not be null");
Validate.notNull(setter, "`setter` must not be null");
@@ -83,7 +90,7 @@ public interface Option<T> {
public Option<T> build() {
Validate.notNull(name, "`name` must not be null when building `Option`");
- Validate.notNull(control, "`control` must not be null when building `Option`");
+ Validate.notNull(controlGetter, "`control` must not be null when building `Option`");
Validate.notNull(binding, "`binding` must not be null when building `Option`");
MutableText concatenatedTooltip = Text.empty();
@@ -95,7 +102,7 @@ public interface Option<T> {
concatenatedTooltip.append(line);
}
- return new OptionImpl<>(name, concatenatedTooltip, control, binding);
+ return new OptionImpl<>(name, concatenatedTooltip, controlGetter, binding);
}
}
}