From 5588ac161cc269e4368f7b762da9deb496bf5f62 Mon Sep 17 00:00:00 2001 From: Juuxel Date: Sun, 1 Sep 2019 11:00:24 +0300 Subject: Clamp slider values in WAbstractSlider.setValue --- .../java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/main/java/io') 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 e07be56..f4ef1eb 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 @@ -170,8 +170,11 @@ public abstract class WAbstractSlider extends WWidget { } public void setValue(int value) { - this.value = value; - onValueChanged(value); + int previous = this.value; + this.value = MathHelper.clamp(value, min, max); + if (previous != this.value) { + onValueChanged(this.value); + } } @Nullable -- cgit