@@ -16,7 +16,6 @@ namespace instance.id.EATK
1616 public static class HoverAnimations
1717 {
1818 #region Hover Animations
19-
2019 // --------------------------------------------------- @HoverColor
2120 // ---------------------------------------------------------------
2221 /// <summary>
@@ -38,7 +37,7 @@ public static class HoverAnimations
3837 /// <param name="animate">Whether to animate the transition of the background color</param>
3938 /// <param name="unregister">Whether this command is issued to register or unregister this event</param>
4039 public static void HoverColor < T > ( this T target , StyleColor original , Color hoverColor , Func < T , bool > condition = null ,
41- T conditionElement = null , bool animate = false , bool unregister = false ) where T : VisualElement
40+ T conditionElement = null , bool animate = false , bool unregister = false ) where T : VisualElement
4241 {
4342 ValueAnimation < StyleValues > mouseOver = new ValueAnimation < StyleValues > ( ) ;
4443 ValueAnimation < StyleValues > mouseOut = new ValueAnimation < StyleValues > ( ) ;
@@ -123,7 +122,7 @@ public static void HoverColor<T>(this T target, StyleColor original, Color hover
123122 /// <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>
124123 /// <param name="animate">Whether to animate the transition of the background color</param>
125124 public static void HoverBackground ( this VisualElement target , StyleColor original , Color hoverColor , Func < VisualElement , bool > condition = null ,
126- VisualElement conditionElement = null , bool animate = false , int animDuration = 250 )
125+ VisualElement conditionElement = null , bool animate = false , int animDuration = 250 )
127126 {
128127 var mouseOver = new ValueAnimation < StyleValues > ( ) ;
129128 var mouseOut = new ValueAnimation < StyleValues > ( ) ;
@@ -189,7 +188,6 @@ public static void HoverBorder(this VisualElement target, Color original, Color
189188 target . style . borderRightColor = hoverColor ;
190189 target . style . borderTopColor = hoverColor ;
191190
192-
193191 evt . StopPropagation ( ) ;
194192 } ) ;
195193 target . RegisterCallback < MouseOutEvent > ( evt =>
@@ -202,7 +200,6 @@ public static void HoverBorder(this VisualElement target, Color original, Color
202200 target . style . borderTopWidth = borderStartEndWidth . y ;
203201 }
204202
205-
206203 target . style . borderBottomColor = original ;
207204 target . style . borderLeftColor = original ;
208205 target . style . borderRightColor = original ;
@@ -242,18 +239,18 @@ public static void HoverBorder(this VisualElement target, Color original, Color
242239 /// </example>
243240 public static AnimatedItems < MouseOverEvent , MouseOutEvent >
244241 HoverBorderPulse (
245- this VisualElement target ,
246- Color pulseStartColor ,
247- Color pulseEndColor ,
248- Color original = default ,
249- bool addBorder = false ,
250- Vector2 borderStartEndWidth = default ,
251- int colorDuration = 1000 ,
252- bool includeChildren = true ,
253- bool stopPropagation = true ,
254- TrickleDown useTrickleDown = TrickleDown . NoTrickleDown ,
255- AnimatedItems < MouseOverEvent , MouseOutEvent > animatedItems = null ,
256- params ValueAnimation < StyleValues > [ ] animRunCheck )
242+ this VisualElement target ,
243+ Color pulseStartColor ,
244+ Color pulseEndColor ,
245+ Color original = default ,
246+ bool addBorder = false ,
247+ Vector2 borderStartEndWidth = default ,
248+ int colorDuration = 1000 ,
249+ bool includeChildren = true ,
250+ bool stopPropagation = true ,
251+ TrickleDown useTrickleDown = TrickleDown . NoTrickleDown ,
252+ AnimatedItems < MouseOverEvent , MouseOutEvent > animatedItems = null ,
253+ params ValueAnimation < StyleValues > [ ] animRunCheck )
257254 {
258255 if ( borderStartEndWidth == default )
259256 borderStartEndWidth = new Vector2 ( 1 , 0 ) ;
@@ -340,20 +337,19 @@ void PulseOut(in ValueAnimation<StyleValues> pulse)
340337 target . RegisterCallback ( mouseOverEvent , includeChildren , useTrickleDown ) ;
341338 target . RegisterCallback ( mouseOutEvent , includeChildren , useTrickleDown ) ;
342339
343- animatedItems . AnimatedItemList = new List < ValueAnimation < StyleValues > > { pulseIn , pulseOut } ;
340+ animatedItems . AnimatedItemList = new List < ValueAnimation < StyleValues > > { pulseIn , pulseOut } ;
344341 animatedItems . EventCallbacks = ( mouseOverEvent , mouseOutEvent ) ;
345342 return animatedItems ;
346343 }
347344
348345 #region Unregister
349-
350346 public static void HoverBorderPulseUnregister (
351- this VisualElement target , Color pulseStartColor , Color pulseEndColor , Color original = default , bool addBorder = false ,
352- Vector2 borderStartEndWidth = default ,
353- int colorDuration = 1000 ,
354- bool includeChildren = true ,
355- bool stopPropagation = true ,
356- TrickleDown useTrickleDown = TrickleDown . NoTrickleDown )
347+ this VisualElement target , Color pulseStartColor , Color pulseEndColor , Color original = default , bool addBorder = false ,
348+ Vector2 borderStartEndWidth = default ,
349+ int colorDuration = 1000 ,
350+ bool includeChildren = true ,
351+ bool stopPropagation = true ,
352+ TrickleDown useTrickleDown = TrickleDown . NoTrickleDown )
357353 {
358354 if ( borderStartEndWidth == default )
359355 borderStartEndWidth = new Vector2 ( 1 , 0 ) ;
@@ -419,7 +415,6 @@ void PulseOut(in ValueAnimation<StyleValues> pulse)
419415 if ( pulseIn . isRunning ) pulseIn . Stop ( ) ;
420416 if ( pulseOut . isRunning ) pulseOut . Stop ( ) ;
421417
422-
423418 target . style . borderBottomColor = original ;
424419 target . style . borderLeftColor = original ;
425420 target . style . borderRightColor = original ;
@@ -428,10 +423,9 @@ void PulseOut(in ValueAnimation<StyleValues> pulse)
428423 if ( stopPropagation ) evt . StopPropagation ( ) ;
429424 } , includeChildren ) ;
430425 }
431-
432426 #endregion
433427
434- // -------------------------------------------------- @HoverBorder
428+ // -------------------------------------------------- @HoverBorder
435429 // ---------------------------------------------------------------
436430 /// <summary>
437431 /// Adds background hover capability that will not be lost like CSS:hover when programatically setting background color
@@ -457,17 +451,17 @@ public static void HoverOpacity(this VisualElement target, float startValue, flo
457451 evt . StopPropagation ( ) ;
458452 } ) ;
459453 }
460-
454+
461455 // -------------------------------------------------------- @HoverWidth
462456 // -- Animate the width of target element to desired value on hover --
463457 // --------------------------------------------------------------------
464458 public static AnimatedItems < MouseOverEvent , MouseOutEvent > HoverWidth (
465- this VisualElement target , float initialWidth = 0f , float desiredWidth = 100f , int duration = 1000 , Action hoverCallback = null ,
466- Action leaveCallback = null ,
467- bool afterAnimation = false ,
468- bool includeChildren = true ,
469- bool stopPropagation = true ,
470- TrickleDown useTrickleDown = TrickleDown . NoTrickleDown )
459+ this VisualElement target , float initialWidth = 0f , float desiredWidth = 100f , int duration = 1000 , Action hoverCallback = null ,
460+ Action leaveCallback = null ,
461+ bool afterAnimation = false ,
462+ bool includeChildren = true ,
463+ bool stopPropagation = true ,
464+ TrickleDown useTrickleDown = TrickleDown . NoTrickleDown )
471465 {
472466 initialWidth = initialWidth == 0f ? target . resolvedStyle . width : initialWidth ;
473467 var enterAnim = new ValueAnimation < StyleValues > ( ) ;
@@ -510,7 +504,7 @@ void MouseEnter()
510504
511505 return new AnimatedItems < MouseOverEvent , MouseOutEvent > ( target )
512506 {
513- AnimatedItemList = new List < ValueAnimation < StyleValues > > { enterAnim , leaveAnim } ,
507+ AnimatedItemList = new List < ValueAnimation < StyleValues > > { enterAnim , leaveAnim } ,
514508 EventCallbacks = ( mouseOverEvent , mouseOutEvent )
515509 } ;
516510 }
@@ -519,13 +513,13 @@ void MouseEnter()
519513 // -- Animate the Height of target element to desired value on hover --
520514 // --------------------------------------------------------------------
521515 public static AnimatedItems < MouseOverEvent , MouseOutEvent > HoverHeight (
522- this VisualElement target ,
523- float initialHeight = 0f ,
524- float desiredHeight = 100f ,
525- int duration = 1000 ,
526- Action hoverCallback = null ,
527- Action leaveCallback = null ,
528- bool afterAnimation = false )
516+ this VisualElement target ,
517+ float initialHeight = 0f ,
518+ float desiredHeight = 100f ,
519+ int duration = 1000 ,
520+ Action hoverCallback = null ,
521+ Action leaveCallback = null ,
522+ bool afterAnimation = false )
529523 {
530524 initialHeight = initialHeight == 0f ? target . resolvedStyle . height : initialHeight ;
531525 var enterAnim = new ValueAnimation < StyleValues > ( ) ;
@@ -562,7 +556,7 @@ void MouseEnter()
562556
563557 return new AnimatedItems < MouseOverEvent , MouseOutEvent > ( target )
564558 {
565- AnimatedItemList = new List < ValueAnimation < StyleValues > > { enterAnim , leaveAnim } ,
559+ AnimatedItemList = new List < ValueAnimation < StyleValues > > { enterAnim , leaveAnim } ,
566560 EventCallbacks = ( mouseOverEvent , mouseOutEvent )
567561 } ;
568562 }
@@ -583,6 +577,43 @@ public static void HoverToolTip(this VisualElement target, Action callback)
583577 } ) ;
584578 }
585579
580+ public static void HoverAction ( this VisualElement target , Action mouseInAction , Action mouseOutAction = default , List < VisualElement > extendedTargets = default )
581+ {
582+ target . RegisterCallback < MouseOverEvent > ( evt =>
583+ {
584+ mouseInAction ? . Invoke ( ) ;
585+ // evt.StopPropagation();
586+ } ) ;
587+
588+ if ( extendedTargets != default )
589+ {
590+ foreach ( var extendedTarget in extendedTargets )
591+ {
592+ extendedTarget . RegisterCallback < MouseOverEvent > ( evt =>
593+ {
594+ mouseInAction ? . Invoke ( ) ;
595+ // evt.StopPropagation();
596+ } ) ;
597+ }
598+ }
599+
600+ target . RegisterCallback < MouseLeaveEvent > ( evt =>
601+ {
602+ if ( extendedTargets != default && extendedTargets . Contains ( evt . currentTarget ) ) return ;
603+ mouseOutAction ? . Invoke ( ) ;
604+ // evt.StopPropagation();
605+ } ) ;
606+
607+ if ( extendedTargets == default ) return ;
608+ foreach ( var extendedTarget in extendedTargets )
609+ {
610+ extendedTarget . RegisterCallback < MouseLeaveEvent > ( evt =>
611+ {
612+ mouseOutAction ? . Invoke ( ) ;
613+ // evt.StopPropagation();
614+ } ) ;
615+ }
616+ }
586617 #endregion
587618 }
588619}
0 commit comments