From 9c655343bb91e2c7e117e2f99c2053d55f30e842 Mon Sep 17 00:00:00 2001 From: Juuxel Date: Sat, 31 Aug 2019 23:56:17 +0300 Subject: Some slider updates - WIP dark mode textures for simple sliders - Vertical/rotated labeled sliders - Text alignment for slider labels - Add missing getters for nicer Kotlin usage --- .../cotton/gui/widget/WAbstractSlider.java | 10 ++++ .../cottonmc/cotton/gui/widget/WLabeledSlider.java | 60 ++++++++++++++++++---- .../github/cottonmc/cotton/gui/widget/WSlider.java | 31 +++++++---- 3 files changed, 81 insertions(+), 20 deletions(-) (limited to 'src/main/java') 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 641b396..aa5e78d 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 @@ -143,10 +143,20 @@ public abstract class WAbstractSlider extends WWidget { onValueChanged(value); } + @Nullable + public IntConsumer getValueChangeListener() { + return valueChangeListener; + } + public void setValueChangeListener(@Nullable IntConsumer valueChangeListener) { this.valueChangeListener = valueChangeListener; } + @Nullable + public Runnable getDraggingFinishedListener() { + return draggingFinishedListener; + } + public void setDraggingFinishedListener(@Nullable Runnable draggingFinishedListener) { this.draggingFinishedListener = draggingFinishedListener; } 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 a959485..4541427 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 @@ -1,6 +1,8 @@ package io.github.cottonmc.cotton.gui.widget; +import com.mojang.blaze3d.systems.RenderSystem; import io.github.cottonmc.cotton.gui.client.ScreenDrawing; +import io.github.cottonmc.cotton.gui.widget.data.Alignment; import io.github.cottonmc.cotton.gui.widget.data.Axis; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -21,20 +23,33 @@ import javax.annotation.Nullable; public class WLabeledSlider extends WAbstractSlider { @Nullable private Text label = null; @Nullable private LabelUpdater labelUpdater = null; + private Alignment labelAlignment = Alignment.CENTER; public WLabeledSlider(int min, int max) { - super(min, max, Axis.HORIZONTAL); + this(min, max, Axis.HORIZONTAL); } - public WLabeledSlider(int min, int max, Text label) { - this(min, max); + public WLabeledSlider(int min, int max, Axis axis) { + super(min, max, axis); + } + + public WLabeledSlider(int min, int max, Axis axis, @Nullable Text label) { + this(min, max, axis); this.label = label; } + public WLabeledSlider(int min, int max, @Nullable Text label) { + this(min, max); + this.label = label; + } @Override public void setSize(int x, int y) { - super.setSize(x, 20); + if (axis == Axis.HORIZONTAL) { + super.setSize(x, 20); + } else { + super.setSize(20, y); + } } @Nullable @@ -54,6 +69,19 @@ public class WLabeledSlider extends WAbstractSlider { } } + public Alignment getLabelAlignment() { + return labelAlignment; + } + + public void setLabelAlignment(Alignment labelAlignment) { + this.labelAlignment = labelAlignment; + } + + @Nullable + public LabelUpdater getLabelUpdater() { + return labelUpdater; + } + public void setLabelUpdater(@Nullable LabelUpdater labelUpdater) { this.labelUpdater = labelUpdater; } @@ -71,27 +99,39 @@ public class WLabeledSlider extends WAbstractSlider { @Environment(EnvType.CLIENT) @Override public void paintBackground(int x, int y, int mouseX, int mouseY) { - drawButton(x, y, 0, width); + int aWidth = axis == Axis.HORIZONTAL ? width : height; + int aHeight = axis == Axis.HORIZONTAL ? height : width; + int rotMouseX = axis == Axis.HORIZONTAL ? mouseX : (height - mouseY); + int rotMouseY = axis == Axis.HORIZONTAL ? mouseY : mouseX; + + RenderSystem.pushMatrix(); + RenderSystem.translatef(x, y, 0); + if (axis == Axis.VERTICAL) { + RenderSystem.translatef(0, height, 0); + RenderSystem.rotatef(270, 0, 0, 1); + } + drawButton(0, 0, 0, aWidth); // 1: regular, 2: hovered, 0: disabled/dragging int thumbX = Math.round(coordToValueRatio * (value - min)); int thumbY = 0; int thumbWidth = getThumbWidth(); - int thumbHeight = height; - boolean hovering = mouseX >= thumbX && mouseX <= thumbX + thumbWidth && mouseY >= thumbY && mouseY <= thumbY + thumbHeight; + int thumbHeight = aHeight; + boolean hovering = rotMouseX >= thumbX && rotMouseX <= thumbX + thumbWidth && rotMouseY >= thumbY && rotMouseY <= thumbY + thumbHeight; int thumbState = dragging || hovering ? 2 : 1; - drawButton(x + thumbX, y + thumbY, thumbState, thumbWidth); + drawButton(thumbX, thumbY, thumbState, thumbWidth); if (thumbState == 1 && isFocused()) { float px = 1 / 32f; - ScreenDrawing.texturedRect(x + thumbX, y + thumbY, thumbWidth, thumbHeight, WSlider.TEXTURE, 24*px, 0*px, 32*px, 20*px, 0xFFFFFFFF); + ScreenDrawing.texturedRect(thumbX, thumbY, thumbWidth, thumbHeight, WSlider.LIGHT_TEXTURE, 24*px, 0*px, 32*px, 20*px, 0xFFFFFFFF); } if (label != null) { int color = isMouseInsideBounds(mouseX, mouseY) ? 0xFFFFA0 : 0xE0E0E0; - ScreenDrawing.drawCenteredWithShadow(label.asFormattedString(), x + width / 2, y + height / 2 - 4, color); + ScreenDrawing.drawStringWithShadow(label.asFormattedString(), labelAlignment, 2, aHeight / 2 - 4, aWidth - 4, color); } + RenderSystem.popMatrix(); } // state = 1: regular, 2: hovered, 0: disabled/dragging diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WSlider.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WSlider.java index 3bd7c20..b921945 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WSlider.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WSlider.java @@ -1,6 +1,7 @@ package io.github.cottonmc.cotton.gui.widget; import io.github.cottonmc.cotton.gui.client.BackgroundPainter; +import io.github.cottonmc.cotton.gui.client.LibGuiClient; import io.github.cottonmc.cotton.gui.client.ScreenDrawing; import io.github.cottonmc.cotton.gui.widget.data.Axis; import net.fabricmc.api.EnvType; @@ -17,7 +18,8 @@ import javax.annotation.Nullable; public class WSlider extends WAbstractSlider { public static final int TRACK_WIDTH = 6; public static final int THUMB_SIZE = 8; - public static final Identifier TEXTURE = new Identifier("libgui", "textures/widget/slider.png"); + public static final Identifier LIGHT_TEXTURE = new Identifier("libgui", "textures/widget/slider.png"); + public static final Identifier DARK_TEXTURE = new Identifier("libgui", "textures/widget/slider_dark.png"); @Environment(EnvType.CLIENT) @Nullable @@ -27,6 +29,7 @@ public class WSlider extends WAbstractSlider { super(min, max, axis); } + @Deprecated public WSlider(int max, Axis axis) { this(0, max, axis); } @@ -46,6 +49,7 @@ public class WSlider extends WAbstractSlider { return ao >= aoCenter - TRACK_WIDTH / 2 - 2 && ao <= aoCenter + TRACK_WIDTH / 2 + 2; } + @SuppressWarnings("SuspiciousNameCombination") @Environment(EnvType.CLIENT) @Override public void paintBackground(int x, int y, int mouseX, int mouseY) { @@ -57,6 +61,7 @@ public class WSlider extends WAbstractSlider { int thumbX, thumbY; // thumbXOffset: thumb texture x offset in pixels int thumbXOffset; + Identifier texture = LibGuiClient.config.darkMode ? DARK_TEXTURE : LIGHT_TEXTURE; if (axis == Axis.VERTICAL) { int trackX = x + width / 2 - TRACK_WIDTH / 2; @@ -64,33 +69,39 @@ public class WSlider extends WAbstractSlider { thumbY = height - THUMB_SIZE + 1 - (int) (coordToValueRatio * (value - min)); thumbXOffset = 0; - ScreenDrawing.texturedRect(trackX, y + 1, TRACK_WIDTH, 1, TEXTURE, 16*px, 0*px, 22*px, 1*px, 0xFFFFFFFF); - ScreenDrawing.texturedRect(trackX, y + 2, TRACK_WIDTH, height - 2, TEXTURE, 16*px, 1*px, 22*px, 2*px, 0xFFFFFFFF); - ScreenDrawing.texturedRect(trackX, y + height, TRACK_WIDTH, 1, TEXTURE, 16*px, 2*px, 22*px, 3*px, 0xFFFFFFFF); + ScreenDrawing.texturedRect(trackX, y + 1, TRACK_WIDTH, 1, texture, 16*px, 0*px, 22*px, 1*px, 0xFFFFFFFF); + ScreenDrawing.texturedRect(trackX, y + 2, TRACK_WIDTH, height - 2, texture, 16*px, 1*px, 22*px, 2*px, 0xFFFFFFFF); + ScreenDrawing.texturedRect(trackX, y + height, TRACK_WIDTH, 1, texture, 16*px, 2*px, 22*px, 3*px, 0xFFFFFFFF); } else { int trackY = y + height / 2 - TRACK_WIDTH / 2; thumbX = Math.round(coordToValueRatio * (value - min)); thumbY = height / 2 - THUMB_SIZE / 2; thumbXOffset = 8; - ScreenDrawing.texturedRect(x, trackY, 1, TRACK_WIDTH, TEXTURE, 16*px, 3*px, 17*px, 9*px, 0xFFFFFFFF); - ScreenDrawing.texturedRect(x + 1, trackY, width - 2, TRACK_WIDTH, TEXTURE, 17*px, 3*px, 18*px, 9*px, 0xFFFFFFFF); - ScreenDrawing.texturedRect(x + width - 1, trackY, 1, TRACK_WIDTH, TEXTURE, 18*px, 3*px, 19*px, 9*px, 0xFFFFFFFF); + ScreenDrawing.texturedRect(x, trackY, 1, TRACK_WIDTH, texture, 16*px, 3*px, 17*px, 9*px, 0xFFFFFFFF); + ScreenDrawing.texturedRect(x + 1, trackY, width - 2, TRACK_WIDTH, texture, 17*px, 3*px, 18*px, 9*px, 0xFFFFFFFF); + ScreenDrawing.texturedRect(x + width - 1, trackY, 1, TRACK_WIDTH, texture, 18*px, 3*px, 19*px, 9*px, 0xFFFFFFFF); } // thumbState values: // 0: default, 1: dragging, 2: hovered int thumbState = dragging ? 1 : (mouseX >= thumbX && mouseX <= thumbX + THUMB_SIZE && mouseY >= thumbY && mouseY <= thumbY + THUMB_SIZE ? 2 : 0); - ScreenDrawing.texturedRect(x + thumbX, y + thumbY, THUMB_SIZE, THUMB_SIZE, TEXTURE, thumbXOffset*px, 0*px + thumbState * 8*px, (thumbXOffset + 8)*px, 8*px + thumbState * 8*px, 0xFFFFFFFF); + ScreenDrawing.texturedRect(x + thumbX, y + thumbY, THUMB_SIZE, THUMB_SIZE, texture, thumbXOffset*px, 0*px + thumbState * 8*px, (thumbXOffset + 8)*px, 8*px + thumbState * 8*px, 0xFFFFFFFF); if (thumbState == 0 && isFocused()) { - ScreenDrawing.texturedRect(x + thumbX, y + thumbY, THUMB_SIZE, THUMB_SIZE, TEXTURE, 0*px, 24*px, 8*px, 32*px, 0xFFFFFFFF); + ScreenDrawing.texturedRect(x + thumbX, y + thumbY, THUMB_SIZE, THUMB_SIZE, texture, 0*px, 24*px, 8*px, 32*px, 0xFFFFFFFF); } } } @Environment(EnvType.CLIENT) - public void setBackgroundPainter(BackgroundPainter backgroundPainter) { + @Nullable + public BackgroundPainter getBackgroundPainter() { + return backgroundPainter; + } + + @Environment(EnvType.CLIENT) + public void setBackgroundPainter(@Nullable BackgroundPainter backgroundPainter) { this.backgroundPainter = backgroundPainter; } } -- cgit From 0d6f07bc2360ae83d4bc4348c3cad3ed10bac12b Mon Sep 17 00:00:00 2001 From: Juuxel Date: Sun, 1 Sep 2019 10:17:21 +0300 Subject: Add scrolling support for sliders --- .../cotton/gui/widget/WAbstractSlider.java | 51 +++++++++++++++++----- 1 file changed, 41 insertions(+), 10 deletions(-) (limited to 'src/main/java') 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 aa5e78d..677686d 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 @@ -25,6 +25,11 @@ import java.util.function.IntConsumer; * */ public abstract class WAbstractSlider extends WWidget { + /** + * The minimum time between two draggingFinished events caused by scrolling ({@link #onMouseScroll}). + */ + private static final int SCROLLING_DRAGGING_FINISHED_RATE_LIMIT = 10; + protected final int min, max; protected final Axis axis; @@ -49,10 +54,12 @@ public abstract class WAbstractSlider extends WWidget { /** * True if there is a pending dragging finished event caused by the keyboard. */ - private boolean valueChangedWithKeys = false; + private boolean pendingDraggingFinishedFromKeyboard = false; + private int draggingFinishedFromScrollingTimer = 0; + private boolean pendingDraggingFinishedFromScrolling = false; @Nullable private IntConsumer valueChangeListener = null; - @Nullable private Runnable draggingFinishedListener = null; + @Nullable private IntConsumer draggingFinishedListener = null; protected WAbstractSlider(int min, int max, Axis axis) { if (max <= min) @@ -116,7 +123,7 @@ public abstract class WAbstractSlider extends WWidget { @Override public void onClick(int x, int y, int button) { moveSlider(x, y); - if (draggingFinishedListener != null) draggingFinishedListener.run(); + if (draggingFinishedListener != null) draggingFinishedListener.accept(value); } private void moveSlider(int x, int y) { @@ -130,10 +137,34 @@ public abstract class WAbstractSlider extends WWidget { @Override public WWidget onMouseUp(int x, int y, int button) { dragging = false; - if (draggingFinishedListener != null) draggingFinishedListener.run(); + if (draggingFinishedListener != null) draggingFinishedListener.accept(value); return super.onMouseUp(x, y, button); } + @Override + public void onMouseScroll(int x, int y, double amount) { + int previous = value; + value = MathHelper.clamp(value + (int) (valueToCoordRatio * amount * 2), min, max); + + if (previous != value) { + onValueChanged(value); + pendingDraggingFinishedFromScrolling = true; + } + } + + @Override + public void tick() { + if (draggingFinishedFromScrollingTimer > 0) { + draggingFinishedFromScrollingTimer--; + } + + if (pendingDraggingFinishedFromScrolling && draggingFinishedFromScrollingTimer <= 0) { + if (draggingFinishedListener != null) draggingFinishedListener.accept(value); + pendingDraggingFinishedFromScrolling = false; + draggingFinishedFromScrollingTimer = SCROLLING_DRAGGING_FINISHED_RATE_LIMIT; + } + } + public int getValue() { return value; } @@ -153,11 +184,11 @@ public abstract class WAbstractSlider extends WWidget { } @Nullable - public Runnable getDraggingFinishedListener() { + public IntConsumer getDraggingFinishedListener() { return draggingFinishedListener; } - public void setDraggingFinishedListener(@Nullable Runnable draggingFinishedListener) { + public void setDraggingFinishedListener(@Nullable IntConsumer draggingFinishedListener) { this.draggingFinishedListener = draggingFinishedListener; } @@ -200,15 +231,15 @@ public abstract class WAbstractSlider extends WWidget { if (valueChanged) { onValueChanged(value); - valueChangedWithKeys = true; + pendingDraggingFinishedFromKeyboard = true; } } @Override public void onKeyReleased(int ch, int key, int modifiers) { - if (valueChangedWithKeys && (isDecreasingKey(ch) || isIncreasingKey(ch))) { - if (draggingFinishedListener != null) draggingFinishedListener.run(); - valueChangedWithKeys = false; + if (pendingDraggingFinishedFromKeyboard && (isDecreasingKey(ch) || isIncreasingKey(ch))) { + if (draggingFinishedListener != null) draggingFinishedListener.accept(value); + pendingDraggingFinishedFromKeyboard = false; } } -- cgit From 4587fc8700462a939ae5ee5cd81a2ff176880001 Mon Sep 17 00:00:00 2001 From: Juuxel Date: Sun, 1 Sep 2019 10:50:05 +0300 Subject: Improve dark slider textures --- .../cottonmc/cotton/gui/widget/WAbstractSlider.java | 4 ++-- .../io/github/cottonmc/cotton/gui/widget/WSlider.java | 2 +- .../assets/libgui/textures/widget/slider.png | Bin 2978 -> 0 bytes .../assets/libgui/textures/widget/slider_dark.png | Bin 2723 -> 2871 bytes .../assets/libgui/textures/widget/slider_light.png | Bin 0 -> 2978 bytes 5 files changed, 3 insertions(+), 3 deletions(-) delete mode 100644 src/main/resources/assets/libgui/textures/widget/slider.png create mode 100644 src/main/resources/assets/libgui/textures/widget/slider_light.png (limited to 'src/main/java') 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 677686d..e07be56 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 @@ -28,7 +28,7 @@ public abstract class WAbstractSlider extends WWidget { /** * The minimum time between two draggingFinished events caused by scrolling ({@link #onMouseScroll}). */ - private static final int SCROLLING_DRAGGING_FINISHED_RATE_LIMIT = 10; + private static final int DRAGGING_FINISHED_RATE_LIMIT_FOR_SCROLLING = 10; protected final int min, max; protected final Axis axis; @@ -161,7 +161,7 @@ public abstract class WAbstractSlider extends WWidget { if (pendingDraggingFinishedFromScrolling && draggingFinishedFromScrollingTimer <= 0) { if (draggingFinishedListener != null) draggingFinishedListener.accept(value); pendingDraggingFinishedFromScrolling = false; - draggingFinishedFromScrollingTimer = SCROLLING_DRAGGING_FINISHED_RATE_LIMIT; + draggingFinishedFromScrollingTimer = DRAGGING_FINISHED_RATE_LIMIT_FOR_SCROLLING; } } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WSlider.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WSlider.java index b921945..2dd3a8e 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WSlider.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WSlider.java @@ -18,7 +18,7 @@ import javax.annotation.Nullable; public class WSlider extends WAbstractSlider { public static final int TRACK_WIDTH = 6; public static final int THUMB_SIZE = 8; - public static final Identifier LIGHT_TEXTURE = new Identifier("libgui", "textures/widget/slider.png"); + public static final Identifier LIGHT_TEXTURE = new Identifier("libgui", "textures/widget/slider_light.png"); public static final Identifier DARK_TEXTURE = new Identifier("libgui", "textures/widget/slider_dark.png"); @Environment(EnvType.CLIENT) diff --git a/src/main/resources/assets/libgui/textures/widget/slider.png b/src/main/resources/assets/libgui/textures/widget/slider.png deleted file mode 100644 index e41250e..0000000 Binary files a/src/main/resources/assets/libgui/textures/widget/slider.png and /dev/null differ diff --git a/src/main/resources/assets/libgui/textures/widget/slider_dark.png b/src/main/resources/assets/libgui/textures/widget/slider_dark.png index fd7e8af..d558e11 100644 Binary files a/src/main/resources/assets/libgui/textures/widget/slider_dark.png and b/src/main/resources/assets/libgui/textures/widget/slider_dark.png differ diff --git a/src/main/resources/assets/libgui/textures/widget/slider_light.png b/src/main/resources/assets/libgui/textures/widget/slider_light.png new file mode 100644 index 0000000..e41250e Binary files /dev/null and b/src/main/resources/assets/libgui/textures/widget/slider_light.png differ -- cgit 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') 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 From 5d26c800f398c549fd6128833852d494ce2e8f1a Mon Sep 17 00:00:00 2001 From: Juuxel Date: Sun, 22 Sep 2019 15:04:00 +0300 Subject: Add silent WAbstractSlider.setValue and a callListeners flag --- .../cottonmc/cotton/gui/widget/WAbstractSlider.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/main/java') 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; *

You can set two listeners on a slider: *

    *
  • - * A value change listener that gets all value changes (including direct setValue calls). + * A value change listener that gets all value changes. *
  • *
  • * 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); } } -- cgit