From bc977bc55028a178c58f17bdcc74d7a3fea7601a Mon Sep 17 00:00:00 2001 From: Matthew Peng <54301439+MEEPofFaith@users.noreply.github.com> Date: Thu, 30 Sep 2021 21:58:47 -0700 Subject: [PATCH 1/2] Option to unclamp `ProgressBar` --- arc-core/src/arc/scene/ui/ProgressBar.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arc-core/src/arc/scene/ui/ProgressBar.java b/arc-core/src/arc/scene/ui/ProgressBar.java index 4720c83b9..906ec242a 100644 --- a/arc-core/src/arc/scene/ui/ProgressBar.java +++ b/arc-core/src/arc/scene/ui/ProgressBar.java @@ -27,6 +27,7 @@ public class ProgressBar extends Element implements Disableable{ final boolean vertical; float position; boolean disabled; + boolean clamped = true; private ProgressBarStyle style; private float min, max, stepSize; private float value, animateFromValue; @@ -261,7 +262,7 @@ else if(animateDuration > 0){ * bar knob's range. */ protected float clamp(float value){ - return Mathf.clamp(value, min, max); + return clamped ? Mathf.clamp(value, min, max) : value; } /** Sets the range of this progress bar. The progress bar's current value is clamped to the range. */ @@ -332,6 +333,11 @@ public void setVisualInterpolation(Interp interpolation){ public void setRound(boolean round){ this.round = round; } + + /** If true (the default), the value will be clamped to the range if it somehow ends up out of it. */ + public void setClamped(boolean clamp){ + this.clamped = clamp; + } @Override public boolean isDisabled(){ From 1fb5fde29660e3731f518dafe4e3495b373eee50 Mon Sep 17 00:00:00 2001 From: Matthew Peng <54301439+MEEPofFaith@users.noreply.github.com> Date: Thu, 30 Sep 2021 22:23:43 -0700 Subject: [PATCH 2/2] Better-ish implementation --- arc-core/src/arc/scene/ui/ProgressBar.java | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/arc-core/src/arc/scene/ui/ProgressBar.java b/arc-core/src/arc/scene/ui/ProgressBar.java index 906ec242a..170a70793 100644 --- a/arc-core/src/arc/scene/ui/ProgressBar.java +++ b/arc-core/src/arc/scene/ui/ProgressBar.java @@ -27,7 +27,6 @@ public class ProgressBar extends Element implements Disableable{ final boolean vertical; float position; boolean disabled; - boolean clamped = true; private ProgressBarStyle style; private float min, max, stepSize; private float value, animateFromValue; @@ -235,12 +234,12 @@ protected float getKnobPosition(){ /** * Sets the progress bar position, rounded to the nearest step size and clamped to the minimum and maximum values. - * {@link #clamp(float)} can be overridden to allow values outside of the progress bar's min/max range. * @return false if the value was not changed because the progress bar already had the value or it was canceled by a * listener. */ - public boolean setValue(float value){ - value = clamp(Math.round(value / stepSize) * stepSize); + public boolean setValue(float value, boolean clampValue){ + float val = Math.round(value / stepSize) * stepSize; + value = clampValue ? clamp(val) : val; float oldValue = this.value; if(value == oldValue) return false; float oldVisualValue = getVisualValue(); @@ -256,13 +255,16 @@ else if(animateDuration > 0){ Pools.free(changeEvent); return !cancelled; } + + public boolean setValue(float value){ + return setValue(value, true); + } /** - * Clamps the value to the progress bar's min/max range. This can be overridden to allow a range different from the progress - * bar knob's range. + * Clamps the value to the progress bar's min/max range. */ protected float clamp(float value){ - return clamped ? Mathf.clamp(value, min, max) : value; + return Mathf.clamp(value, min, max); } /** Sets the range of this progress bar. The progress bar's current value is clamped to the range. */ @@ -333,11 +335,6 @@ public void setVisualInterpolation(Interp interpolation){ public void setRound(boolean round){ this.round = round; } - - /** If true (the default), the value will be clamped to the range if it somehow ends up out of it. */ - public void setClamped(boolean clamp){ - this.clamped = clamp; - } @Override public boolean isDisabled(){