aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/dev/isxander/yacl/gui/controllers/cycling
diff options
context:
space:
mode:
authorisXander <isxander@users.noreply.github.com>2022-10-06 22:11:40 +0100
committerisXander <isxander@users.noreply.github.com>2022-10-06 22:11:50 +0100
commit1b40278b7b1d930d918c558a946d46fbaeee50a2 (patch)
treec8b4b65831d264cea7a5c914b97d1d03cf899eb3 /src/main/java/dev/isxander/yacl/gui/controllers/cycling
parent2eb6fa164da23c547ceccf8d2773a1e12eedb4f3 (diff)
downloadYetAnotherConfigLib-1b40278b7b1d930d918c558a946d46fbaeee50a2.tar.gz
YetAnotherConfigLib-1b40278b7b1d930d918c558a946d46fbaeee50a2.tar.bz2
YetAnotherConfigLib-1b40278b7b1d930d918c558a946d46fbaeee50a2.zip
javadoc & changelog for cycling package
Diffstat (limited to 'src/main/java/dev/isxander/yacl/gui/controllers/cycling')
-rw-r--r--src/main/java/dev/isxander/yacl/gui/controllers/cycling/CyclingListController.java31
-rw-r--r--src/main/java/dev/isxander/yacl/gui/controllers/cycling/ICyclingController.java19
2 files changed, 50 insertions, 0 deletions
diff --git a/src/main/java/dev/isxander/yacl/gui/controllers/cycling/CyclingListController.java b/src/main/java/dev/isxander/yacl/gui/controllers/cycling/CyclingListController.java
index a894eff..3b14066 100644
--- a/src/main/java/dev/isxander/yacl/gui/controllers/cycling/CyclingListController.java
+++ b/src/main/java/dev/isxander/yacl/gui/controllers/cycling/CyclingListController.java
@@ -6,41 +6,72 @@ import net.minecraft.text.Text;
import java.util.function.Function;
+/**
+ * A controller where once clicked, cycles through elements
+ * in the provided list.
+ */
public class CyclingListController<T> implements ICyclingController<T> {
private final Option<T> option;
private final Function<T, Text> valueFormatter;
private final ImmutableList<T> values;
+ /**
+ * Constructs a {@link CyclingListController}, with a default
+ * value formatter of {@link Object#toString()}.
+ * @param option option of which to bind the controller to
+ * @param values the values to cycle through
+ */
public CyclingListController(Option<T> option, Iterable<T> values) {
this(option, values, value -> Text.of(value.toString()));
}
+ /**
+ * Constructs a {@link CyclingListController}
+ * @param option option of which to bind the controller to
+ * @param values the values to cycle through
+ * @param valueFormatter function of how to convert each value to a string to display
+ */
public CyclingListController(Option<T> option, Iterable<T> values, Function<T, Text> valueFormatter) {
this.option = option;
this.valueFormatter = valueFormatter;
this.values = ImmutableList.copyOf(values);
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public Option<T> option() {
return option;
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public Text formatValue() {
return valueFormatter.apply(option().pendingValue());
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void setPendingValue(int ordinal) {
option().requestSet(values.get(ordinal));
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public int getPendingValue() {
return values.indexOf(option().pendingValue());
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public int getCycleLength() {
return values.size();
diff --git a/src/main/java/dev/isxander/yacl/gui/controllers/cycling/ICyclingController.java b/src/main/java/dev/isxander/yacl/gui/controllers/cycling/ICyclingController.java
index 39f0b35..081b572 100644
--- a/src/main/java/dev/isxander/yacl/gui/controllers/cycling/ICyclingController.java
+++ b/src/main/java/dev/isxander/yacl/gui/controllers/cycling/ICyclingController.java
@@ -5,13 +5,32 @@ import dev.isxander.yacl.api.utils.Dimension;
import dev.isxander.yacl.gui.AbstractWidget;
import dev.isxander.yacl.gui.YACLScreen;
+/**
+ * This interface simply generifies setting and getting of
+ * the pending value, using an ordinal so elements can cycle through
+ * without knowing the content.
+ */
public interface ICyclingController<T> extends Controller<T> {
+ /**
+ * Sets the pending value to whatever corresponds to the ordinal
+ * @param ordinal index of element to set
+ */
void setPendingValue(int ordinal);
+ /**
+ * Gets the pending ordinal that corresponds to the actual value
+ * @return ordinal
+ */
int getPendingValue();
+ /**
+ * Allows the element when it should wrap-around back to zeroth ordinal
+ */
int getCycleLength();
+ /**
+ * {@inheritDoc}
+ */
@Override
default AbstractWidget provideWidget(YACLScreen screen, Dimension<Integer> widgetDimension) {
return new CyclingControllerElement(this, screen, widgetDimension);