From 1b40278b7b1d930d918c558a946d46fbaeee50a2 Mon Sep 17 00:00:00 2001 From: isXander Date: Thu, 6 Oct 2022 22:11:40 +0100 Subject: javadoc & changelog for cycling package --- .../controllers/cycling/CyclingListController.java | 31 ++++++++++++++++++++++ .../controllers/cycling/ICyclingController.java | 19 +++++++++++++ 2 files changed, 50 insertions(+) (limited to 'src/main/java/dev/isxander/yacl/gui/controllers/cycling') 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 implements ICyclingController { private final Option option; private final Function valueFormatter; private final ImmutableList 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 option, Iterable 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 option, Iterable values, Function valueFormatter) { this.option = option; this.valueFormatter = valueFormatter; this.values = ImmutableList.copyOf(values); } + /** + * {@inheritDoc} + */ @Override public Option 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 extends Controller { + /** + * 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 widgetDimension) { return new CyclingControllerElement(this, screen, widgetDimension); -- cgit