From ba1f9689d6a35fe0dc9f60ce4351030f52609d4f Mon Sep 17 00:00:00 2001 From: Juuxel <6596629+Juuxel@users.noreply.github.com> Date: Wed, 15 Apr 2020 15:47:04 +0300 Subject: Improve labeled slider docs --- .../cottonmc/cotton/gui/widget/WLabeledSlider.java | 69 ++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java index 4541427..af5ab58 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java @@ -25,19 +25,47 @@ public class WLabeledSlider extends WAbstractSlider { @Nullable private LabelUpdater labelUpdater = null; private Alignment labelAlignment = Alignment.CENTER; + /** + * Constructs a horizontal slider with no default label. + * + * @param min the minimum value + * @param max the maximum value + */ public WLabeledSlider(int min, int max) { this(min, max, Axis.HORIZONTAL); } + /** + * Constructs a slider with no default label. + * + * @param min the minimum value + * @param max the maximum value + * @param axis the slider axis + */ public WLabeledSlider(int min, int max, Axis axis) { super(min, max, axis); } + /** + * Constructs a slider. + * + * @param min the minimum value + * @param max the maximum value + * @param axis the slider axis + * @param label the slider label (can be null) + */ public WLabeledSlider(int min, int max, Axis axis, @Nullable Text label) { this(min, max, axis); this.label = label; } + /** + * Constructs a horizontal slider. + * + * @param min the minimum value + * @param max the maximum value + * @param label the slider label (can be null) + */ public WLabeledSlider(int min, int max, @Nullable Text label) { this(min, max); this.label = label; @@ -52,11 +80,21 @@ public class WLabeledSlider extends WAbstractSlider { } } + /** + * Gets the current label of this slider. + * + * @return the label + */ @Nullable public Text getLabel() { return label; } + /** + * Sets the label of this slider. + * + * @param label the new label + */ public void setLabel(@Nullable Text label) { this.label = label; } @@ -69,19 +107,39 @@ public class WLabeledSlider extends WAbstractSlider { } } + /** + * Gets the text alignment of this slider's label. + * + * @return the alignment + */ public Alignment getLabelAlignment() { return labelAlignment; } + /** + * Sets the text alignment of this slider's label. + * + * @param labelAlignment the new alignment + */ public void setLabelAlignment(Alignment labelAlignment) { this.labelAlignment = labelAlignment; } + /** + * Gets the {@link LabelUpdater} of this slider. + * + * @return the label updater + */ @Nullable public LabelUpdater getLabelUpdater() { return labelUpdater; } + /** + * Sets the {@link LabelUpdater} of this slider. + * + * @param labelUpdater the new label updater + */ public void setLabelUpdater(@Nullable LabelUpdater labelUpdater) { this.labelUpdater = labelUpdater; } @@ -150,8 +208,19 @@ public class WLabeledSlider extends WAbstractSlider { ScreenDrawing.texturedRect(x + halfWidth, y, halfWidth, 20, AbstractButtonWidget.WIDGETS_LOCATION, buttonEndLeft, buttonTop, 200 * px, buttonTop + buttonHeight, 0xFFFFFFFF); } + /** + * A label updater updates the label of a slider based on the current value. + * + *

Useful for situations when you want to have display values on the slider. + */ @FunctionalInterface public interface LabelUpdater { + /** + * Gets the updated label for the new slider value. + * + * @param value the slider value + * @return the label + */ Text updateLabel(int value); } } -- cgit