fix: Force devs to choose between ValueClamped and ValueUnclamped

This commit is contained in:
Kaz Wolfe 2025-03-23 18:28:07 -07:00
parent 3074115b34
commit e84654005e
No known key found for this signature in database
GPG key ID: 258813F53A16EBB4
5 changed files with 23 additions and 14 deletions

View file

@ -1,6 +1,8 @@
using System.Diagnostics; using System.Diagnostics;
using System.Numerics; using System.Numerics;
using Dalamud.Utility;
namespace Dalamud.Interface.Animation; namespace Dalamud.Interface.Animation;
/// <summary> /// <summary>
@ -42,10 +44,17 @@ public abstract class Easing
/// </summary> /// </summary>
public bool IsInverse { get; set; } public bool IsInverse { get; set; }
/// <summary>
/// Gets the current value of the animation, following unclamped logic.
/// </summary>
[Obsolete($"This field has been deprecated. Use either {nameof(ValueClamped)} or {nameof(ValueUnclamped)} instead.", true)]
[Api13ToDo("Map this field to ValueClamped, probably.")]
public double Value => this.ValueUnclamped;
/// <summary> /// <summary>
/// Gets the current value of the animation, from 0 to 1. /// Gets the current value of the animation, from 0 to 1.
/// </summary> /// </summary>
public double Value => Math.Clamp(this.ValueUnclamped, 0, 1); public double ValueClamped => Math.Clamp(this.ValueUnclamped, 0, 1);
/// <summary> /// <summary>
/// Gets or sets the current value of the animation, not limited to a range of 0 to 1. /// Gets or sets the current value of the animation, not limited to a range of 0 to 1.

View file

@ -21,8 +21,8 @@ internal sealed partial class ActiveNotification
var opacity = var opacity =
Math.Clamp( Math.Clamp(
(float)(this.hideEasing.IsRunning (float)(this.hideEasing.IsRunning
? (this.hideEasing.IsDone || ReducedMotions ? 0 : 1f - this.hideEasing.Value) ? (this.hideEasing.IsDone || ReducedMotions ? 0 : 1f - this.hideEasing.ValueClamped)
: (this.showEasing.IsDone || ReducedMotions ? 1 : this.showEasing.Value)), : (this.showEasing.IsDone || ReducedMotions ? 1 : this.showEasing.ValueClamped)),
0f, 0f,
1f); 1f);
if (opacity <= 0) if (opacity <= 0)
@ -106,7 +106,7 @@ internal sealed partial class ActiveNotification
} }
else if (this.expandoEasing.IsRunning) else if (this.expandoEasing.IsRunning)
{ {
var easedValue = ReducedMotions ? 1f : (float)this.expandoEasing.Value; var easedValue = ReducedMotions ? 1f : (float)this.expandoEasing.ValueClamped;
if (this.underlyingNotification.Minimized) if (this.underlyingNotification.Minimized)
ImGui.PushStyleVar(ImGuiStyleVar.Alpha, opacity * (1f - easedValue)); ImGui.PushStyleVar(ImGuiStyleVar.Alpha, opacity * (1f - easedValue));
else else
@ -295,8 +295,8 @@ internal sealed partial class ActiveNotification
{ {
relativeOpacity = relativeOpacity =
this.underlyingNotification.Minimized this.underlyingNotification.Minimized
? 1f - (float)this.expandoEasing.Value ? 1f - (float)this.expandoEasing.ValueClamped
: (float)this.expandoEasing.Value; : (float)this.expandoEasing.ValueClamped;
} }
else else
{ {
@ -543,7 +543,7 @@ internal sealed partial class ActiveNotification
float barL, barR; float barL, barR;
if (this.DismissReason is not null) if (this.DismissReason is not null)
{ {
var v = this.hideEasing.IsDone || ReducedMotions ? 0f : 1f - (float)this.hideEasing.Value; var v = this.hideEasing.IsDone || ReducedMotions ? 0f : 1f - (float)this.hideEasing.ValueClamped;
var midpoint = (this.prevProgressL + this.prevProgressR) / 2f; var midpoint = (this.prevProgressL + this.prevProgressR) / 2f;
var length = (this.prevProgressR - this.prevProgressL) / 2f; var length = (this.prevProgressR - this.prevProgressL) / 2f;
barL = midpoint - (length * v); barL = midpoint - (length * v);

View file

@ -226,7 +226,7 @@ internal sealed partial class ActiveNotification : IActiveNotification
if (Math.Abs(underlyingProgress - this.progressBefore) < 0.000001f || this.progressEasing.IsDone || ReducedMotions) if (Math.Abs(underlyingProgress - this.progressBefore) < 0.000001f || this.progressEasing.IsDone || ReducedMotions)
return underlyingProgress; return underlyingProgress;
var state = ReducedMotions ? 1f : Math.Clamp((float)this.progressEasing.Value, 0f, 1f); var state = ReducedMotions ? 1f : Math.Clamp((float)this.progressEasing.ValueClamped, 0f, 1f);
return this.progressBefore + (state * (underlyingProgress - this.progressBefore)); return this.progressBefore + (state * (underlyingProgress - this.progressBefore));
} }
} }

View file

@ -147,7 +147,7 @@ internal sealed class ComponentDemoWindow : Window
ImGui.Bullet(); ImGui.Bullet();
ImGui.SetCursorPos(cursor + new Vector2(0, 10)); ImGui.SetCursorPos(cursor + new Vector2(0, 10));
ImGui.Text($"{easing.GetType().Name} ({easing.Value})"); ImGui.Text($"{easing.GetType().Name} ({easing.ValueClamped})");
ImGuiHelpers.ScaledDummy(5); ImGuiHelpers.ScaledDummy(5);
} }
} }

View file

@ -204,7 +204,7 @@ internal class TitleScreenMenuWindow : Window, IDisposable
moveEasing.Update(); moveEasing.Update();
var finalPos = (i + 1) * this.shadeTexture.Value.Height * scale; var finalPos = (i + 1) * this.shadeTexture.Value.Height * scale;
var pos = moveEasing.Value * finalPos; var pos = moveEasing.ValueClamped * finalPos;
// FIXME(goat): Sometimes, easings can overshoot and bring things out of alignment. // FIXME(goat): Sometimes, easings can overshoot and bring things out of alignment.
if (moveEasing.IsDone) if (moveEasing.IsDone)
@ -251,7 +251,7 @@ internal class TitleScreenMenuWindow : Window, IDisposable
this.fadeOutEasing.Update(); this.fadeOutEasing.Update();
using (ImRaii.PushStyle(ImGuiStyleVar.Alpha, (float)this.fadeOutEasing.Value)) using (ImRaii.PushStyle(ImGuiStyleVar.Alpha, (float)this.fadeOutEasing.ValueClamped))
{ {
var i = 0; var i = 0;
foreach (var entry in entries) foreach (var entry in entries)
@ -317,7 +317,7 @@ internal class TitleScreenMenuWindow : Window, IDisposable
var initialCursor = ImGui.GetCursorPos(); var initialCursor = ImGui.GetCursorPos();
using (ImRaii.PushStyle(ImGuiStyleVar.Alpha, (float)shadeEasing.Value)) using (ImRaii.PushStyle(ImGuiStyleVar.Alpha, (float)shadeEasing.ValueClamped))
{ {
var texture = this.shadeTexture.Value; var texture = this.shadeTexture.Value;
ImGui.Image(texture.ImGuiHandle, new Vector2(texture.Width, texture.Height) * scale); ImGui.Image(texture.ImGuiHandle, new Vector2(texture.Width, texture.Height) * scale);
@ -367,7 +367,7 @@ internal class TitleScreenMenuWindow : Window, IDisposable
if (overrideAlpha) if (overrideAlpha)
{ {
ImGui.PushStyleVar(ImGuiStyleVar.Alpha, isFirst ? 1f : (float)logoEasing.Value); ImGui.PushStyleVar(ImGuiStyleVar.Alpha, isFirst ? 1f : (float)logoEasing.ValueClamped);
} }
else if (isFirst) else if (isFirst)
{ {
@ -392,7 +392,7 @@ internal class TitleScreenMenuWindow : Window, IDisposable
if (overrideAlpha) if (overrideAlpha)
{ {
ImGui.PushStyleVar(ImGuiStyleVar.Alpha, showText ? (float)logoEasing.Value : 0f); ImGui.PushStyleVar(ImGuiStyleVar.Alpha, showText ? (float)logoEasing.ValueClamped : 0f);
} }
// Drop shadow // Drop shadow