Skip to content

Commit

Permalink
Added several new animations, helper datatypes, etc. Updated to 2022.2
Browse files Browse the repository at this point in the history
  • Loading branch information
instance-id committed Jun 9, 2023
1 parent 9174582 commit 411a7bf
Show file tree
Hide file tree
Showing 170 changed files with 9,267 additions and 2,778 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ public static class ContinuousAnimations
{
public static bool debug = false;

public static IVisualElementScheduledItem AnimBorderPulse(
this VisualElement element,
AnimValueStore<Color> valueStore)
{
return AnimBorderPulse(element, valueStore.initial, valueStore.final);
}
// -------------------------------------------------- @HoverBorder
// ---------------------------------------------------------------
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,15 @@ namespace instance.id.EATK
public static class Easy
{
private const float HalfPi = 1.570796f;

public static float Step(float t) => (double) t < 0.5 ? 0.0f : 1f;

public static float Linear(float t) => t;

public static float InSine(float t) => Mathf.Sin((float) (1.57079637050629 * ((double) t - 1.0))) + 1f;

public static float OutSine(float t) => Mathf.Sin(t * 1.570796f);

public static float InOutSine(float t) => (float) (((double) Mathf.Sin((float) (3.14159274101257 * ((double) t - 0.5))) + 1.0) * 0.5);

public static float InQuad(float t) => t * t;

public static float OutQuad(float t) => t * (2f - t);

public static float OutExpo(float t) {
return t.Equals(1f) ? 1 : 1 - Mathf.Pow(2, -10 * t);

}

public static float InOutQuad(float t)
Expand All @@ -41,13 +32,9 @@ public static float InOutQuad(float t)
}

public static float InCubic(float t) => Easy.InPower(t, 3);

public static float OutCubic(float t) => Easy.OutPower(t, 3);

public static float InOutCubic(float t) => Easy.InOutPower(t, 3);

public static float InPower(float t, int power) => Mathf.Pow(t, (float) power);

public static float OutPower(float t, int power)
{
int num = power % 2 == 0 ? -1 : 1;
Expand All @@ -57,20 +44,16 @@ public static float OutPower(float t, int power)
public static float InOutPower(float t, int power)
{
t *= 2f;
if ((double) t < 1.0)
return Easy.InPower(t, power) * 0.5f;
if ((double) t < 1.0) return Easy.InPower(t, power) * 0.5f;
int num = power % 2 == 0 ? -1 : 1;
return (float) ((double) num * 0.5 * ((double) Mathf.Pow(t - 2f, (float) power) + (double) (num * 2)));
}

public static float InBounce(float t) => 1f - Easy.OutBounce(1f - t);

public static float OutBounce(float t)
{
if ((double) t < 0.363636374473572)
return 121f / 16f * t * t;
if ((double) t < 0.727272748947144)
return (float) (121.0 / 16.0 * (double) (t -= 0.5454546f) * (double) t + 0.75);
if ((double) t < 0.363636374473572) return 121f / 16f * t * t;
if ((double) t < 0.727272748947144) return (float) (121.0 / 16.0 * (double) (t -= 0.5454546f) * (double) t + 0.75);
return (double) t < 0.909090936183929
? (float) (121.0 / 16.0 * (double) (t -= 0.8181818f) * (double) t + 15.0 / 16.0)
: (float) (121.0 / 16.0 * (double) (t -= 0.9545454f) * (double) t + 63.0 / 64.0);
Expand All @@ -81,21 +64,17 @@ public static float InOutBounce(float t) =>

public static float InElastic(float t)
{
if ((double) t == 0.0)
return 0.0f;
if ((double) t == 1.0)
return 1f;
if ((double) t == 0.0) return 0.0f;
if ((double) t == 1.0) return 1f;
float num1 = 0.3f;
float num2 = num1 / 4f;
return (float) -((double) Mathf.Pow(2f, 10f * --t) * (double) Mathf.Sin((float) (((double) t - (double) num2) * 6.28318548202515) / num1));
}

public static float OutElastic(float t)
{
if ((double) t == 0.0)
return 0.0f;
if ((double) t == 1.0)
return 1f;
if ((double) t == 0.0) return 0.0f;
if ((double) t == 1.0) return 1f;
float num1 = 0.3f;
float num2 = num1 / 4f;
return (float) ((double) Mathf.Pow(2f, -10f * t) * (double) Mathf.Sin((float) (((double) t - (double) num2) * 6.28318548202515) / num1) + 1.0);
Expand All @@ -116,9 +95,7 @@ public static float InOutBack(float t) =>
(double) t < 0.5 ? Easy.InBack(t * 2f) * 0.5f : (float) ((double) Easy.OutBack((float) (((double) t - 0.5) * 2.0)) * 0.5 + 0.5);

public static float InBack(float t, float s) => (float) ((double) t * (double) t * (((double) s + 1.0) * (double) t - (double) s));

public static float OutBack(float t, float s) => 1f - Easy.InBack(1f - t, s);

public static float InOutBack(float t, float s) =>
(double) t < 0.5 ? Easy.InBack(t * 2f, s) * 0.5f : (float) ((double) Easy.OutBack((float) (((double) t - 0.5) * 2.0), s) * 0.5 + 0.5);

Expand All @@ -139,7 +116,6 @@ public static float InOutCirc(float t)
return (float) (0.5 * ((double) Mathf.Sqrt((float) (1.0 - (double) t * (double) t)) + 1.0));
}


public static float EaseInOutQuint(float t)
{
return (float) (t < 0.5f ? 16f * t * t * t * t * t : 1 - Math.Pow(-2 * t + 2, 5) / 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ namespace instance.id.EATK
public static class HoverAnimations
{
#region Hover Animations

// --------------------------------------------------- @HoverColor
// ---------------------------------------------------------------
/// <summary>
Expand All @@ -38,7 +37,7 @@ public static class HoverAnimations
/// <param name="animate">Whether to animate the transition of the background color</param>
/// <param name="unregister">Whether this command is issued to register or unregister this event</param>
public static void HoverColor<T>(this T target, StyleColor original, Color hoverColor, Func<T, bool> condition = null,
T conditionElement = null, bool animate = false, bool unregister = false) where T : VisualElement
T conditionElement = null, bool animate = false, bool unregister = false) where T : VisualElement
{
ValueAnimation<StyleValues> mouseOver = new ValueAnimation<StyleValues>();
ValueAnimation<StyleValues> mouseOut = new ValueAnimation<StyleValues>();
Expand Down Expand Up @@ -123,7 +122,7 @@ public static void HoverColor<T>(this T target, StyleColor original, Color hover
/// <param name="conditionElement">The element in which the optional condition will be evaluated. Ex. in the example of 'bool Condition(VisualElement sRow) => selectedRow == packageListRow;', the conditionalElement would be 'VisualElement selectedRow'</param>
/// <param name="animate">Whether to animate the transition of the background color</param>
public static void HoverBackground(this VisualElement target, StyleColor original, Color hoverColor, Func<VisualElement, bool> condition = null,
VisualElement conditionElement = null, bool animate = false, int animDuration = 250)
VisualElement conditionElement = null, bool animate = false, int animDuration = 250)
{
var mouseOver = new ValueAnimation<StyleValues>();
var mouseOut = new ValueAnimation<StyleValues>();
Expand Down Expand Up @@ -189,7 +188,6 @@ public static void HoverBorder(this VisualElement target, Color original, Color
target.style.borderRightColor = hoverColor;
target.style.borderTopColor = hoverColor;


evt.StopPropagation();
});
target.RegisterCallback<MouseOutEvent>(evt =>
Expand All @@ -202,7 +200,6 @@ public static void HoverBorder(this VisualElement target, Color original, Color
target.style.borderTopWidth = borderStartEndWidth.y;
}


target.style.borderBottomColor = original;
target.style.borderLeftColor = original;
target.style.borderRightColor = original;
Expand Down Expand Up @@ -242,18 +239,18 @@ public static void HoverBorder(this VisualElement target, Color original, Color
/// </example>
public static AnimatedItems<MouseOverEvent, MouseOutEvent>
HoverBorderPulse(
this VisualElement target,
Color pulseStartColor,
Color pulseEndColor,
Color original = default,
bool addBorder = false,
Vector2 borderStartEndWidth = default,
int colorDuration = 1000,
bool includeChildren = true,
bool stopPropagation = true,
TrickleDown useTrickleDown = TrickleDown.NoTrickleDown,
AnimatedItems<MouseOverEvent, MouseOutEvent> animatedItems = null,
params ValueAnimation<StyleValues>[] animRunCheck)
this VisualElement target,
Color pulseStartColor,
Color pulseEndColor,
Color original = default,
bool addBorder = false,
Vector2 borderStartEndWidth = default,
int colorDuration = 1000,
bool includeChildren = true,
bool stopPropagation = true,
TrickleDown useTrickleDown = TrickleDown.NoTrickleDown,
AnimatedItems<MouseOverEvent, MouseOutEvent> animatedItems = null,
params ValueAnimation<StyleValues>[] animRunCheck)
{
if (borderStartEndWidth == default)
borderStartEndWidth = new Vector2(1, 0);
Expand Down Expand Up @@ -340,20 +337,19 @@ void PulseOut(in ValueAnimation<StyleValues> pulse)
target.RegisterCallback(mouseOverEvent, includeChildren, useTrickleDown);
target.RegisterCallback(mouseOutEvent, includeChildren, useTrickleDown);

animatedItems.AnimatedItemList = new List<ValueAnimation<StyleValues>> { pulseIn, pulseOut };
animatedItems.AnimatedItemList = new List<ValueAnimation<StyleValues>> {pulseIn, pulseOut};
animatedItems.EventCallbacks = (mouseOverEvent, mouseOutEvent);
return animatedItems;
}

#region Unregister

public static void HoverBorderPulseUnregister(
this VisualElement target, Color pulseStartColor, Color pulseEndColor, Color original = default, bool addBorder = false,
Vector2 borderStartEndWidth = default,
int colorDuration = 1000,
bool includeChildren = true,
bool stopPropagation = true,
TrickleDown useTrickleDown = TrickleDown.NoTrickleDown)
this VisualElement target, Color pulseStartColor, Color pulseEndColor, Color original = default, bool addBorder = false,
Vector2 borderStartEndWidth = default,
int colorDuration = 1000,
bool includeChildren = true,
bool stopPropagation = true,
TrickleDown useTrickleDown = TrickleDown.NoTrickleDown)
{
if (borderStartEndWidth == default)
borderStartEndWidth = new Vector2(1, 0);
Expand Down Expand Up @@ -419,7 +415,6 @@ void PulseOut(in ValueAnimation<StyleValues> pulse)
if (pulseIn.isRunning) pulseIn.Stop();
if (pulseOut.isRunning) pulseOut.Stop();


target.style.borderBottomColor = original;
target.style.borderLeftColor = original;
target.style.borderRightColor = original;
Expand All @@ -428,10 +423,9 @@ void PulseOut(in ValueAnimation<StyleValues> pulse)
if (stopPropagation) evt.StopPropagation();
}, includeChildren);
}

#endregion

// -------------------------------------------------- @HoverBorder
// -------------------------------------------------- @HoverBorder
// ---------------------------------------------------------------
/// <summary>
/// Adds background hover capability that will not be lost like CSS:hover when programatically setting background color
Expand All @@ -457,17 +451,17 @@ public static void HoverOpacity(this VisualElement target, float startValue, flo
evt.StopPropagation();
});
}

// -------------------------------------------------------- @HoverWidth
// -- Animate the width of target element to desired value on hover --
// --------------------------------------------------------------------
public static AnimatedItems<MouseOverEvent, MouseOutEvent> HoverWidth(
this VisualElement target, float initialWidth = 0f, float desiredWidth = 100f, int duration = 1000, Action hoverCallback = null,
Action leaveCallback = null,
bool afterAnimation = false,
bool includeChildren = true,
bool stopPropagation = true,
TrickleDown useTrickleDown = TrickleDown.NoTrickleDown)
this VisualElement target, float initialWidth = 0f, float desiredWidth = 100f, int duration = 1000, Action hoverCallback = null,
Action leaveCallback = null,
bool afterAnimation = false,
bool includeChildren = true,
bool stopPropagation = true,
TrickleDown useTrickleDown = TrickleDown.NoTrickleDown)
{
initialWidth = initialWidth == 0f ? target.resolvedStyle.width : initialWidth;
var enterAnim = new ValueAnimation<StyleValues>();
Expand Down Expand Up @@ -510,7 +504,7 @@ void MouseEnter()

return new AnimatedItems<MouseOverEvent, MouseOutEvent>(target)
{
AnimatedItemList = new List<ValueAnimation<StyleValues>> { enterAnim, leaveAnim },
AnimatedItemList = new List<ValueAnimation<StyleValues>> {enterAnim, leaveAnim},
EventCallbacks = (mouseOverEvent, mouseOutEvent)
};
}
Expand All @@ -519,13 +513,13 @@ void MouseEnter()
// -- Animate the Height of target element to desired value on hover --
// --------------------------------------------------------------------
public static AnimatedItems<MouseOverEvent, MouseOutEvent> HoverHeight(
this VisualElement target,
float initialHeight = 0f,
float desiredHeight = 100f,
int duration = 1000,
Action hoverCallback = null,
Action leaveCallback = null,
bool afterAnimation = false)
this VisualElement target,
float initialHeight = 0f,
float desiredHeight = 100f,
int duration = 1000,
Action hoverCallback = null,
Action leaveCallback = null,
bool afterAnimation = false)
{
initialHeight = initialHeight == 0f ? target.resolvedStyle.height : initialHeight;
var enterAnim = new ValueAnimation<StyleValues>();
Expand Down Expand Up @@ -562,7 +556,7 @@ void MouseEnter()

return new AnimatedItems<MouseOverEvent, MouseOutEvent>(target)
{
AnimatedItemList = new List<ValueAnimation<StyleValues>> { enterAnim, leaveAnim },
AnimatedItemList = new List<ValueAnimation<StyleValues>> {enterAnim, leaveAnim},
EventCallbacks = (mouseOverEvent, mouseOutEvent)
};
}
Expand All @@ -583,6 +577,43 @@ public static void HoverToolTip(this VisualElement target, Action callback)
});
}

public static void HoverAction(this VisualElement target, Action mouseInAction, Action mouseOutAction = default, List<VisualElement> extendedTargets = default)
{
target.RegisterCallback<MouseOverEvent>(evt =>
{
mouseInAction?.Invoke();
// evt.StopPropagation();
});

if (extendedTargets != default)
{
foreach (var extendedTarget in extendedTargets)
{
extendedTarget.RegisterCallback<MouseOverEvent>(evt =>
{
mouseInAction?.Invoke();
// evt.StopPropagation();
});
}
}

target.RegisterCallback<MouseLeaveEvent>(evt =>
{
if (extendedTargets != default && extendedTargets.Contains(evt.currentTarget)) return;
mouseOutAction?.Invoke();
// evt.StopPropagation();
});

if (extendedTargets == default) return;
foreach (var extendedTarget in extendedTargets)
{
extendedTarget.RegisterCallback<MouseLeaveEvent>(evt =>
{
mouseOutAction?.Invoke();
// evt.StopPropagation();
});
}
}
#endregion
}
}
Expand Down
Loading

0 comments on commit 411a7bf

Please sign in to comment.