|
@@ -1,6 +1,7 @@
|
|
|
package me.shedaniel.clothconfig2.gui.widget;
|
|
|
|
|
|
import me.shedaniel.clothconfig2.ClothConfigInitializer;
|
|
|
+import me.shedaniel.clothconfig2.api.RunSixtyTimesEverySec;
|
|
|
import me.shedaniel.math.api.Rectangle;
|
|
|
import me.shedaniel.math.impl.PointHelper;
|
|
|
import net.minecraft.client.MinecraftClient;
|
|
@@ -18,11 +19,24 @@ public abstract class DynamicNewSmoothScrollingEntryListWidget<E extends Dynamic
|
|
|
protected boolean smoothScrolling = true;
|
|
|
protected long start;
|
|
|
protected long duration;
|
|
|
+ protected RunSixtyTimesEverySec clamper = () -> {
|
|
|
+ target = clamp(target);
|
|
|
+ if (target < 0) {
|
|
|
+ target = target * getBounceBackMultiplier();
|
|
|
+ } else if (target > getMaxScroll()) {
|
|
|
+ target = (target - getMaxScroll()) * getBounceBackMultiplier() + getMaxScroll();
|
|
|
+ } else
|
|
|
+ unregisterClamper();
|
|
|
+ };
|
|
|
|
|
|
public DynamicNewSmoothScrollingEntryListWidget(MinecraftClient client, int width, int height, int top, int bottom, Identifier backgroundLocation) {
|
|
|
super(client, width, height, top, bottom, backgroundLocation);
|
|
|
}
|
|
|
|
|
|
+ protected void unregisterClamper() {
|
|
|
+ clamper.unregisterTick();
|
|
|
+ }
|
|
|
+
|
|
|
public final double clamp(double v) {
|
|
|
return clamp(v, SmoothScrollingSettings.CLAMP_EXTENSION);
|
|
|
}
|
|
@@ -109,11 +123,8 @@ public abstract class DynamicNewSmoothScrollingEntryListWidget<E extends Dynamic
|
|
|
|
|
|
private void updatePosition(float delta) {
|
|
|
target = clamp(target);
|
|
|
- if (target < 0) {
|
|
|
- target = target * getBounceBackMultiplier();
|
|
|
- } else if (target > getMaxScroll()) {
|
|
|
- target = (target - getMaxScroll()) * getBounceBackMultiplier() + getMaxScroll();
|
|
|
- }
|
|
|
+ if ((target < 0 || target > getMaxScroll()) && !clamper.isRegistered())
|
|
|
+ clamper.registerTick();
|
|
|
if (!Precision.almostEquals(scroll, target, Precision.FLOAT_EPSILON))
|
|
|
scroll = (float) Interpolation.expoEase(scroll, target, Math.min((System.currentTimeMillis() - start) / ((double) duration), 1));
|
|
|
else
|