public FluentElement <T> Register <TEvent>(Call <TEvent> c, TrickleDown trickleDown = TrickleDown.NoTrickleDown) where TEvent : EventBase <TEvent>, new() { var handler = new CallHandle { x = x, eventTypeId = EventBase <TEvent> .TypeId() }; var callback = (EventCallback <TEvent>)(evt => { handler.evt = evt; handler.totalCalls++; handler.trickle = trickleDown; c.Invoke(evt, handler); }); handler.callback = callback; x.RegisterCallback(callback, trickleDown); if (EventStorage <TEvent> .Handlers.ContainsKey(c)) { EventStorage <TEvent> .Handlers[c] = handler; } else { EventStorage <TEvent> .Handlers.Add(c, handler); } return(x); }
bool UnregisterCallback(long eventTypeId, Delegate callback, TrickleDown useTrickleDown) { if (callback == null) { return(false); } EventCallbackList callbackList = GetCallbackListForWriting(); var callbackPhase = useTrickleDown == TrickleDown.TrickleDown ? CallbackPhase.TrickleDownAndTarget : CallbackPhase.TargetAndBubbleUp; return(callbackList.Remove(eventTypeId, callback, callbackPhase)); }
private bool UnregisterCallback(long eventTypeId, Delegate callback, TrickleDown useTrickleDown) { bool flag = callback == null; bool result; if (flag) { result = false; } else { EventCallbackList callbackListForWriting = this.GetCallbackListForWriting(); CallbackPhase phase = (useTrickleDown == TrickleDown.TrickleDown) ? CallbackPhase.TrickleDownAndTarget : CallbackPhase.TargetAndBubbleUp; result = callbackListForWriting.Remove(eventTypeId, callback, phase); } return(result); }
/** * Executes the given callback at most once when the event occurs. */ public static void RegisterCallbackOneShot <TEventType>( this VisualElement visualElement, EventCallback <TEventType> callback, TrickleDown useTrickleDown = TrickleDown.NoTrickleDown) where TEventType : EventBase <TEventType>, new() { bool wasExecuted = false; void RunCallbackIfNotDoneYet(TEventType evt) { if (!wasExecuted) { wasExecuted = true; callback(evt); visualElement.UnregisterCallback <TEventType>(RunCallbackIfNotDoneYet, useTrickleDown); } } visualElement.RegisterCallback <TEventType>(RunCallbackIfNotDoneYet, useTrickleDown); }
public static void RegisterChangeEventCallback(CallbackEventHandler eventHandler, Type type, EventCallback <IChangeEvent> callback, TrickleDown useTrickleDown = TrickleDown.NoTrickleDown) { foreach (var method in eventHandler.GetType().GetMethods()) { if (method.Name != nameof(CallbackEventHandler.RegisterCallback)) { continue; } var genericArguments = method.GetGenericArguments(); if (genericArguments.Length == 1) { var constructedGenericType = typeof(ChangeEvent <>).MakeGenericType(type); var typedMethod = method.MakeGenericMethod(constructedGenericType); typedMethod.Invoke(eventHandler, new object[] { callback, useTrickleDown }); return; } } throw new NotImplementedException(); }
internal static void UnregisterCallback(object registry, long eventTypeId, Delegate callback, TrickleDown useTrickleDown) { unregisterCallbackFunc(registry, eventTypeId, callback, useTrickleDown); }
public static void UnregisterCallback(CallbackEventHandler handler, long eventTypeId, Delegate callback, TrickleDown trickle) { var registry = CallbackEventHandlerRef.GetCallbackRegistry(handler); EventCallbackRegistryRef.UnregisterCallback(registry, eventTypeId, callback, trickle); }
public void UnregisterCallback <TEventType, TUserArgsType>(EventCallback <TEventType, TUserArgsType> callback, Capture useCapture) where TEventType : EventBase <TEventType>, new() { TrickleDown td = (TrickleDown)useCapture; UnregisterCallback <TEventType, TUserArgsType>(callback, td); }
internal bool TryGetUserArgs <TEventType, TCallbackArgs>(EventCallback <TEventType, TCallbackArgs> callback, TrickleDown useTrickleDown, out TCallbackArgs userArgs) where TEventType : EventBase <TEventType>, new() { userArgs = default; if (callback == null) { return(false); } EventCallbackList list = GetCallbackListForReading(); long eventTypeId = EventBase <TEventType> .TypeId(); var callbackPhase = useTrickleDown == TrickleDown.TrickleDown ? CallbackPhase.TrickleDownAndTarget : CallbackPhase.TargetAndBubbleUp; var functor = list.Find(eventTypeId, callback, callbackPhase) as EventCallbackFunctor <TEventType, TCallbackArgs>; if (functor == null) { return(false); } userArgs = functor.userArgs; return(true); }
public void RegisterCallback <TEventType, TUserArgsType>(EventCallback <TEventType, TUserArgsType> callback, TUserArgsType userArgs, TrickleDown useTrickleDown = TrickleDown.NoTrickleDown) where TEventType : EventBase <TEventType>, new() { if (m_CallbackRegistry == null) { m_CallbackRegistry = new EventCallbackRegistry(); } m_CallbackRegistry.RegisterCallback <TEventType, TUserArgsType>(callback, userArgs, useTrickleDown); GlobalCallbackRegistry.RegisterListeners <TEventType>(this, callback, useTrickleDown); }
public bool UnregisterCallback <TEventType, TCallbackArgs>(EventCallback <TEventType, TCallbackArgs> callback, Capture useCapture) where TEventType : EventBase <TEventType>, new() { TrickleDown td = (TrickleDown)useCapture; return(UnregisterCallback <TEventType, TCallbackArgs>(callback, td)); }
internal void RegisterCallback <TEventType>(EventCallback <TEventType> callback, InvokePolicy invokePolicy, TrickleDown useTrickleDown = TrickleDown.NoTrickleDown) where TEventType : EventBase <TEventType>, new() { if (m_CallbackRegistry == null) { m_CallbackRegistry = new EventCallbackRegistry(); } m_CallbackRegistry.RegisterCallback(callback, useTrickleDown, invokePolicy); GlobalCallbackRegistry.RegisterListeners <TEventType>(this, callback, useTrickleDown); AddEventCategories <TEventType>(); }
internal bool TryGetUserArgs <TEventType, TCallbackArgs>(EventCallback <TEventType, TCallbackArgs> callback, TrickleDown useTrickleDown, out TCallbackArgs userData) where TEventType : EventBase <TEventType>, new() { userData = default(TCallbackArgs); if (m_CallbackRegistry != null) { return(m_CallbackRegistry.TryGetUserArgs(callback, useTrickleDown, out userData)); } return(false); }
public void RegisterCallback <TEventType, TCallbackArgs>(EventCallback <TEventType, TCallbackArgs> callback, TCallbackArgs userArgs, TrickleDown useTrickleDown = TrickleDown.NoTrickleDown) where TEventType : EventBase <TEventType>, new() { bool flag = callback == null; if (flag) { throw new ArgumentException("callback parameter is null"); } long eventTypeId = EventBase <TEventType> .TypeId(); CallbackPhase phase = (useTrickleDown == TrickleDown.TrickleDown) ? CallbackPhase.TrickleDownAndTarget : CallbackPhase.TargetAndBubbleUp; EventCallbackList eventCallbackList = this.GetCallbackListForReading(); bool flag2 = eventCallbackList != null; if (flag2) { EventCallbackFunctor <TEventType, TCallbackArgs> eventCallbackFunctor = eventCallbackList.Find(eventTypeId, callback, phase) as EventCallbackFunctor <TEventType, TCallbackArgs>; bool flag3 = eventCallbackFunctor != null; if (flag3) { eventCallbackFunctor.userArgs = userArgs; return; } } eventCallbackList = this.GetCallbackListForWriting(); eventCallbackList.Add(new EventCallbackFunctor <TEventType, TCallbackArgs>(callback, userArgs, phase)); }
internal bool TryGetUserArgs <TEventType, TCallbackArgs>(EventCallback <TEventType, TCallbackArgs> callback, TrickleDown useTrickleDown, out TCallbackArgs userArgs) where TEventType : EventBase <TEventType>, new() { userArgs = default(TCallbackArgs); bool flag = callback == null; bool result; if (flag) { result = false; } else { EventCallbackList callbackListForReading = this.GetCallbackListForReading(); long eventTypeId = EventBase <TEventType> .TypeId(); CallbackPhase phase = (useTrickleDown == TrickleDown.TrickleDown) ? CallbackPhase.TrickleDownAndTarget : CallbackPhase.TargetAndBubbleUp; EventCallbackFunctor <TEventType, TCallbackArgs> eventCallbackFunctor = callbackListForReading.Find(eventTypeId, callback, phase) as EventCallbackFunctor <TEventType, TCallbackArgs>; bool flag2 = eventCallbackFunctor == null; if (flag2) { result = false; } else { userArgs = eventCallbackFunctor.userArgs; result = true; } } return(result); }
public void RegisterCallback <TEventType>(EventCallback <TEventType> callback, TrickleDown useTrickleDown = TrickleDown.NoTrickleDown) where TEventType : EventBase <TEventType>, new() { bool flag = callback == null; if (flag) { throw new ArgumentException("callback parameter is null"); } long eventTypeId = EventBase <TEventType> .TypeId(); CallbackPhase phase = (useTrickleDown == TrickleDown.TrickleDown) ? CallbackPhase.TrickleDownAndTarget : CallbackPhase.TargetAndBubbleUp; EventCallbackList eventCallbackList = this.GetCallbackListForReading(); bool flag2 = eventCallbackList == null || !eventCallbackList.Contains(eventTypeId, callback, phase); if (flag2) { eventCallbackList = this.GetCallbackListForWriting(); eventCallbackList.Add(new EventCallbackFunctor <TEventType>(callback, phase)); } }
public static void RegisterListeners <TEventType>(CallbackEventHandler ceh, Delegate callback, TrickleDown useTrickleDown) { bool flag = !GlobalCallbackRegistry.IsEventDebuggerConnected; if (!flag) { Dictionary <Type, List <GlobalCallbackRegistry.ListenerRecord> > dictionary; bool flag2 = !GlobalCallbackRegistry.s_Listeners.TryGetValue(ceh, out dictionary); if (flag2) { dictionary = new Dictionary <Type, List <GlobalCallbackRegistry.ListenerRecord> >(); GlobalCallbackRegistry.s_Listeners.Add(ceh, dictionary); } Type expr_4A = callback.Method.DeclaringType; string text = ((expr_4A != null) ? expr_4A.Name : null) ?? string.Empty; string displayName = (callback.Target as VisualElement).GetDisplayName(true); string name = string.Concat(new string[] { text, ".", callback.Method.Name, " > ", useTrickleDown.ToString(), " [", displayName, "]" }); List <GlobalCallbackRegistry.ListenerRecord> list; bool flag3 = !dictionary.TryGetValue(typeof(TEventType), out list); if (flag3) { list = new List <GlobalCallbackRegistry.ListenerRecord>(); dictionary.Add(typeof(TEventType), list); } StackFrame stackFrame = new StackFrame(2, true); list.Add(new GlobalCallbackRegistry.ListenerRecord { hashCode = callback.GetHashCode(), name = name, fileName = stackFrame.GetFileName(), lineNumber = stackFrame.GetFileLineNumber() }); } }
/// <summary> /// RegisterCallback on element, as well as children, and return the element /// </summary> /// <param name="element">The target element in which to register the callback</param> /// <param name="callback">The callback in which to register</param> /// <param name="includeChildren">Register child elements in addition to the target element</param> /// <typeparam name="TEventType">The event callback type in which to register</typeparam> /// <returns>The target element</returns> public static void UnregisterCallback <TEventType>(this VisualElement element, EventCallback <TEventType> callback, bool includeChildren, TrickleDown useTrickleDown = TrickleDown.NoTrickleDown) where TEventType : EventBase <TEventType>, new() { element.UnregisterCallback(callback); if (!includeChildren) { return; } var children = element.Query <VisualElement>().Descendents <VisualElement>().ToList(); children.ForEach(x => x.UnregisterCallback(callback)); }
public FluentElement <T> Register <TEvent>(EventCallback <TEvent> evt, TrickleDown trickleDown = TrickleDown.NoTrickleDown) where TEvent : EventBase <TEvent>, new() { x.RegisterCallback(evt, trickleDown); return(x); }
public static void RegisterListeners <TEventType>(CallbackEventHandler ceh, Delegate callback, TrickleDown useTrickleDown) { if (!IsEventDebuggerConnected) { return; } Dictionary <Type, List <ListenerRecord> > dict; if (!s_Listeners.TryGetValue(ceh, out dict)) { dict = new Dictionary <Type, List <ListenerRecord> >(); s_Listeners.Add(ceh, dict); } var declType = callback.Method.DeclaringType?.Name ?? string.Empty; string objectName = (callback.Target as VisualElement).GetDisplayName(); string itemName = declType + "." + callback.Method.Name + " > " + useTrickleDown + " [" + objectName + "]"; List <ListenerRecord> callbackRecords; if (!dict.TryGetValue(typeof(TEventType), out callbackRecords)) { callbackRecords = new List <ListenerRecord>(); dict.Add(typeof(TEventType), callbackRecords); } StackFrame callStack = new StackFrame(2, true); callbackRecords.Add(new ListenerRecord { hashCode = callback.GetHashCode(), name = itemName, fileName = callStack.GetFileName(), lineNumber = callStack.GetFileLineNumber() }); }
/// <summary> /// Adds an event handler to the instance. If the event handler has already been registered for the same phase (either TrickleDown or BubbleUp) then this method has no effect. /// </summary> /// <param name="callback">The event handler to add.</param> /// <param name="useTrickleDown">By default, this callback is called during the BubbleUp phase. Pass TrickleDown.TrickleDown to call this callback during the TrickleDown phase.</param> public void RegisterCallback <TEventType>(EventCallback <TEventType> callback, TrickleDown useTrickleDown = TrickleDown.NoTrickleDown) where TEventType : EventBase <TEventType>, new() { if (m_CallbackRegistry == null) { m_CallbackRegistry = new EventCallbackRegistry(); } m_CallbackRegistry.RegisterCallback(callback, useTrickleDown, default); GlobalCallbackRegistry.RegisterListeners <TEventType>(this, callback, useTrickleDown); AddEventCategories <TEventType>(); }
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) { if (borderStartEndWidth == default) { borderStartEndWidth = new Vector2(1, 0); } var pulseIn = new ValueAnimation <StyleValues>(); var pulseOut = new ValueAnimation <StyleValues>(); IVisualElementScheduledItem repeatedAnim = null; var doHover = false; target.UnregisterCallback <MouseOverEvent>(evt => { repeatedAnim = null; doHover = true; if (addBorder) { target.style.borderBottomWidth = borderStartEndWidth.x; target.style.borderLeftWidth = borderStartEndWidth.x; target.style.borderRightWidth = borderStartEndWidth.x; target.style.borderTopWidth = borderStartEndWidth.x; } // -- Pulse color will fade original => desired color -- // -- via the AnimateTo local function. Once completed -- // -- the AnimateFrom function is called animating back -- // -- to the original color. This is then repeated for -- // -- as long as the mouse is hovered over the target -- void PulseIn(in ValueAnimation <StyleValues> pulse) { if (pulse.isRunning) { pulse.Stop(); } pulseIn = target.AnimateBorderColor(pulseStartColor, pulseEndColor, colorDuration, () => PulseOut(pulseIn)); } void PulseOut(in ValueAnimation <StyleValues> pulse) { if (pulse.isRunning) { pulse.Stop(); } pulseOut = target.AnimateBorderColor(pulseEndColor, pulseStartColor, colorDuration); } if (pulseIn.isRunning) { pulseIn.Stop(); } if (pulseOut.isRunning) { pulseOut.Stop(); } repeatedAnim = target.schedule.Execute(() => PulseIn(pulseOut)).StartingIn(0).Every(colorDuration * 2 + 20).Until(() => !doHover); if (stopPropagation) { evt.StopPropagation(); } }, includeChildren); target.UnregisterCallback <MouseOutEvent>(evt => { doHover = false; if (pulseIn.isRunning) { pulseIn?.Stop(); } if (pulseOut.isRunning) { pulseOut?.Stop(); } if (repeatedAnim.isActive) { repeatedAnim.Pause(); } if (addBorder) { target.style.borderBottomWidth = borderStartEndWidth.y; target.style.borderLeftWidth = borderStartEndWidth.y; target.style.borderRightWidth = borderStartEndWidth.y; target.style.borderTopWidth = borderStartEndWidth.y; } if (pulseIn.isRunning) { pulseIn.Stop(); } if (pulseOut.isRunning) { pulseOut.Stop(); } target.style.borderBottomColor = original; target.style.borderLeftColor = original; target.style.borderRightColor = original; target.style.borderTopColor = original; if (stopPropagation) { evt.StopPropagation(); } }, includeChildren); }
public void UnregisterCallback <TEventType, TUserArgsType>(EventCallback <TEventType, TUserArgsType> callback, TrickleDown useTrickleDown = TrickleDown.NoTrickleDown) where TEventType : EventBase <TEventType>, new() { if (m_CallbackRegistry != null) { m_CallbackRegistry.UnregisterCallback(callback, useTrickleDown); } GlobalCallbackRegistry.UnregisterListeners <TEventType>(this, callback); }
public void RegisterCallback <TEventType, TCallbackArgs>(EventCallback <TEventType, TCallbackArgs> callback, TCallbackArgs userArgs, Capture useCapture) where TEventType : EventBase <TEventType>, new() { TrickleDown td = (TrickleDown)useCapture; RegisterCallback <TEventType, TCallbackArgs>(callback, userArgs, td); }
public void RegisterCallback <TEventType>(EventCallback <TEventType> callback, TrickleDown useTrickleDown = TrickleDown.NoTrickleDown, InvokePolicy invokePolicy = default) where TEventType : EventBase <TEventType>, new() { if (callback == null) { throw new ArgumentException("callback parameter is null"); } long eventTypeId = EventBase <TEventType> .TypeId(); var callbackPhase = useTrickleDown == TrickleDown.TrickleDown ? CallbackPhase.TrickleDownAndTarget : CallbackPhase.TargetAndBubbleUp; EventCallbackList callbackList = GetCallbackListForReading(); if (callbackList == null || callbackList.Contains(eventTypeId, callback, callbackPhase) == false) { callbackList = GetCallbackListForWriting(); callbackList.Add(new EventCallbackFunctor <TEventType>(callback, callbackPhase, invokePolicy)); } }
public void RegisterCallback <TEventType, TCallbackArgs>(EventCallback <TEventType, TCallbackArgs> callback, TCallbackArgs userArgs, TrickleDown useTrickleDown = TrickleDown.NoTrickleDown, InvokePolicy invokePolicy = default) where TEventType : EventBase <TEventType>, new() { if (callback == null) { throw new ArgumentException("callback parameter is null"); } long eventTypeId = EventBase <TEventType> .TypeId(); var callbackPhase = useTrickleDown == TrickleDown.TrickleDown ? CallbackPhase.TrickleDownAndTarget : CallbackPhase.TargetAndBubbleUp; EventCallbackList callbackList = GetCallbackListForReading(); if (callbackList != null) { var functor = callbackList.Find(eventTypeId, callback, callbackPhase) as EventCallbackFunctor <TEventType, TCallbackArgs>; if (functor != null) { functor.userArgs = userArgs; return; } } callbackList = GetCallbackListForWriting(); callbackList.Add(new EventCallbackFunctor <TEventType, TCallbackArgs>(callback, userArgs, callbackPhase, invokePolicy)); }
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) { if (borderStartEndWidth == default) { borderStartEndWidth = new Vector2(1, 0); } var doHover = false; var pulseIn = new ValueAnimation <StyleValues>(); var pulseOut = new ValueAnimation <StyleValues>(); IVisualElementScheduledItem repeatedAnim = null; if (animatedItems == null) { animatedItems = new AnimatedItems <MouseOverEvent, MouseOutEvent>(target); } EventCallback <MouseOverEvent> mouseOverEvent = evt => { if (animRunCheck.Length > 0) { if (animRunCheck.Any(t => t.isRunning)) { return; } } if (!animatedItems.AllowRun) { return; } repeatedAnim = null; doHover = true; if (addBorder) { target.style.borderBottomWidth = borderStartEndWidth.x; target.style.borderLeftWidth = borderStartEndWidth.x; target.style.borderRightWidth = borderStartEndWidth.x; target.style.borderTopWidth = borderStartEndWidth.x; } // -- Pulse color will fade original => desired color -- // -- via the AnimateTo local function. Once completed -- // -- the AnimateFrom function is called animating back -- // -- to the original color. This is then repeated for -- // -- as long as the mouse is hovered over the target -- void PulseIn(in ValueAnimation <StyleValues> pulse) { if (pulse.isRunning) { pulse.Stop(); } pulseIn = target.AnimateBorderColor(pulseStartColor, pulseEndColor, colorDuration, () => PulseOut(pulseIn)); } void PulseOut(in ValueAnimation <StyleValues> pulse) { if (pulse.isRunning) { pulse.Stop(); } pulseOut = target.AnimateBorderColor(pulseEndColor, pulseStartColor, colorDuration); } if (pulseIn.isRunning) { pulseIn.Stop(); } if (pulseOut.isRunning) { pulseOut.Stop(); } repeatedAnim = target.schedule.Execute(() => PulseIn(pulseOut)).StartingIn(0).Every(colorDuration * 2 + 20).Until(() => !doHover); if (stopPropagation) { evt.StopPropagation(); } }; EventCallback <MouseOutEvent> mouseOutEvent = evt => { if (!animatedItems.AllowRun) { return; } doHover = false; if (pulseIn.isRunning) { pulseIn?.Stop(); } if (pulseOut.isRunning) { pulseOut?.Stop(); } if (repeatedAnim != null && repeatedAnim.isActive) { repeatedAnim.Pause(); } if (addBorder) { target.style.borderBottomWidth = borderStartEndWidth.y; target.style.borderLeftWidth = borderStartEndWidth.y; target.style.borderRightWidth = borderStartEndWidth.y; target.style.borderTopWidth = borderStartEndWidth.y; } if (pulseIn.isRunning) { pulseIn.Stop(); } if (pulseOut.isRunning) { pulseOut.Stop(); } target.style.borderBottomColor = original; target.style.borderLeftColor = original; target.style.borderRightColor = original; target.style.borderTopColor = original; if (stopPropagation) { evt.StopPropagation(); } }; target.RegisterCallback(mouseOverEvent, includeChildren, useTrickleDown); target.RegisterCallback(mouseOutEvent, includeChildren, useTrickleDown); animatedItems.AnimatedItemList = new List <ValueAnimation <StyleValues> > { pulseIn, pulseOut }; animatedItems.EventCallbacks = (mouseOverEvent, mouseOutEvent); return(animatedItems); }
public bool UnregisterCallback <TEventType, TCallbackArgs>(EventCallback <TEventType, TCallbackArgs> callback, TrickleDown useTrickleDown = TrickleDown.NoTrickleDown) where TEventType : EventBase <TEventType>, new() { long eventTypeId = EventBase <TEventType> .TypeId(); return(UnregisterCallback(eventTypeId, callback, useTrickleDown)); }
// -------------------------------------------------------- @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) { initialWidth = initialWidth == 0f ? target.resolvedStyle.width : initialWidth; var enterAnim = new ValueAnimation <StyleValues>(); var leaveAnim = new ValueAnimation <StyleValues>(); enterAnim = afterAnimation ? target.AnimateWidth(initialWidth, desiredWidth, duration, callback: hoverCallback) : target.AnimateWidth(initialWidth, desiredWidth, duration); enterAnim.KeepAlive(); leaveAnim = target.AnimateWidth(desiredWidth, initialWidth, duration, easing: Easy.EaseInOutQuint); leaveAnim.KeepAlive(); void MouseEnter() { enterAnim.Start(); } // @formatter:off void MouseLeave() { leaveAnim.Start(); } // @formatter:on EventCallback <MouseOverEvent> mouseOverEvent = evt => { if (enterAnim.isRunning) { enterAnim.Stop(); } if (leaveAnim.isRunning) { leaveAnim.Stop(); } MouseEnter(); if (!afterAnimation) { hoverCallback?.Invoke(); } if (stopPropagation) { evt.StopPropagation(); } }; EventCallback <MouseOutEvent> mouseOutEvent = evt => { if (enterAnim.isRunning) { enterAnim.Stop(); } if (leaveAnim.isRunning) { leaveAnim.Stop(); } MouseLeave(); if (stopPropagation) { evt.StopPropagation(); } target.schedule.Execute(leaveCallback).StartingIn(duration); }; target.RegisterCallback(mouseOverEvent, includeChildren, useTrickleDown); target.RegisterCallback(mouseOutEvent, includeChildren, useTrickleDown); return(new AnimatedItems <MouseOverEvent, MouseOutEvent>(target) { AnimatedItemList = new List <ValueAnimation <StyleValues> > { enterAnim, leaveAnim }, EventCallbacks = (mouseOverEvent, mouseOutEvent) });
public void UnregisterCallback <TEventType>(EventCallback <TEventType> callback, TrickleDown useTrickleDown = TrickleDown.NoTrickleDown) where TEventType : EventBase <TEventType>, new() { if (m_CallbackRegistry != null) { m_CallbackRegistry.UnregisterCallback(callback, useTrickleDown); } }