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.Numerics;
using Dalamud.Utility;
namespace Dalamud.Interface.Animation;
/// <summary>
@ -42,10 +44,17 @@ public abstract class Easing
/// </summary>
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>
/// Gets the current value of the animation, from 0 to 1.
/// </summary>
public double Value => Math.Clamp(this.ValueUnclamped, 0, 1);
public double ValueClamped => Math.Clamp(this.ValueUnclamped, 0, 1);
/// <summary>
/// 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 =
Math.Clamp(
(float)(this.hideEasing.IsRunning
? (this.hideEasing.IsDone || ReducedMotions ? 0 : 1f - this.hideEasing.Value)
: (this.showEasing.IsDone || ReducedMotions ? 1 : this.showEasing.Value)),
? (this.hideEasing.IsDone || ReducedMotions ? 0 : 1f - this.hideEasing.ValueClamped)
: (this.showEasing.IsDone || ReducedMotions ? 1 : this.showEasing.ValueClamped)),
0f,
1f);
if (opacity <= 0)
@ -106,7 +106,7 @@ internal sealed partial class ActiveNotification
}
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)
ImGui.PushStyleVar(ImGuiStyleVar.Alpha, opacity * (1f - easedValue));
else
@ -295,8 +295,8 @@ internal sealed partial class ActiveNotification
{
relativeOpacity =
this.underlyingNotification.Minimized
? 1f - (float)this.expandoEasing.Value
: (float)this.expandoEasing.Value;
? 1f - (float)this.expandoEasing.ValueClamped
: (float)this.expandoEasing.ValueClamped;
}
else
{
@ -543,7 +543,7 @@ internal sealed partial class ActiveNotification
float barL, barR;
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 length = (this.prevProgressR - this.prevProgressL) / 2f;
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)
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));
}
}

View file

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

View file

@ -204,7 +204,7 @@ internal class TitleScreenMenuWindow : Window, IDisposable
moveEasing.Update();
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.
if (moveEasing.IsDone)
@ -251,7 +251,7 @@ internal class TitleScreenMenuWindow : Window, IDisposable
this.fadeOutEasing.Update();
using (ImRaii.PushStyle(ImGuiStyleVar.Alpha, (float)this.fadeOutEasing.Value))
using (ImRaii.PushStyle(ImGuiStyleVar.Alpha, (float)this.fadeOutEasing.ValueClamped))
{
var i = 0;
foreach (var entry in entries)
@ -317,7 +317,7 @@ internal class TitleScreenMenuWindow : Window, IDisposable
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;
ImGui.Image(texture.ImGuiHandle, new Vector2(texture.Width, texture.Height) * scale);
@ -367,7 +367,7 @@ internal class TitleScreenMenuWindow : Window, IDisposable
if (overrideAlpha)
{
ImGui.PushStyleVar(ImGuiStyleVar.Alpha, isFirst ? 1f : (float)logoEasing.Value);
ImGui.PushStyleVar(ImGuiStyleVar.Alpha, isFirst ? 1f : (float)logoEasing.ValueClamped);
}
else if (isFirst)
{
@ -392,7 +392,7 @@ internal class TitleScreenMenuWindow : Window, IDisposable
if (overrideAlpha)
{
ImGui.PushStyleVar(ImGuiStyleVar.Alpha, showText ? (float)logoEasing.Value : 0f);
ImGui.PushStyleVar(ImGuiStyleVar.Alpha, showText ? (float)logoEasing.ValueClamped : 0f);
}
// Drop shadow