aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuuxel <kasperi.kauppi@gmail.com>2019-09-22 15:04:00 +0300
committerJuuxel <kasperi.kauppi@gmail.com>2019-09-22 15:04:00 +0300
commit5d26c800f398c549fd6128833852d494ce2e8f1a (patch)
tree1f3c7a44d88fcd05c1ff2d6b458ec96201c363bc
parent0254decd7173d1207333554ac3283c22c9b37fb6 (diff)
downloadLibGui-5d26c800f398c549fd6128833852d494ce2e8f1a.tar.gz
LibGui-5d26c800f398c549fd6128833852d494ce2e8f1a.tar.bz2
LibGui-5d26c800f398c549fd6128833852d494ce2e8f1a.zip
Add silent WAbstractSlider.setValue and a callListeners flag
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java
index f4ef1eb..9aa0782 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java
@@ -14,7 +14,7 @@ import java.util.function.IntConsumer;
* <p>You can set two listeners on a slider:
* <ul>
* <li>
- * A value change listener that gets all value changes (including direct setValue calls).
+ * A value change listener that gets all value changes.
* </li>
* <li>
* A dragging finished listener that gets called when the player stops dragging the slider
@@ -169,11 +169,26 @@ public abstract class WAbstractSlider extends WWidget {
return value;
}
+ /**
+ * Sets the slider value without calling listeners.
+ * @param value the new value
+ */
public void setValue(int value) {
+ setValue(value, false);
+ }
+
+ /**
+ * Sets the slider value.
+ *
+ * @param value the new value
+ * @param callListeners if true, call all slider listeners
+ */
+ public void setValue(int value, boolean callListeners) {
int previous = this.value;
this.value = MathHelper.clamp(value, min, max);
- if (previous != this.value) {
+ if (callListeners && previous != this.value) {
onValueChanged(this.value);
+ if (draggingFinishedListener != null) draggingFinishedListener.accept(value);
}
}