private void SetupAnimationForSize(LayoutData layoutPositionData, TransitionComponents sizeTransitionComponents) { // Text size cant be animated so is set to it's final size. // It is due to the internals of the Text not being able to recalculate fast enough. if (layoutPositionData.Item.Owner is TextLabel || layoutPositionData.Item.Owner is TextField) { float itemWidth = layoutPositionData.Right - layoutPositionData.Left; float itemHeight = layoutPositionData.Bottom - layoutPositionData.Top; // Set size directly. layoutPositionData.Item.Owner.Size2D = new Size2D((int)itemWidth, (int)itemHeight); } else { _coreAnimation.AnimateTo(layoutPositionData.Item.Owner, "Size", new Vector3(layoutPositionData.Right - layoutPositionData.Left, layoutPositionData.Bottom - layoutPositionData.Top, layoutPositionData.Item.Owner.Position.Z), sizeTransitionComponents.Delay, sizeTransitionComponents.Duration, sizeTransitionComponents.AlphaFunction); } }
private void SetupAnimationForPosition(LayoutData layoutPositionData, TransitionComponents positionTransitionComponents) { // A removed item does not have a valid target position within the layout so don't try to position. if (layoutPositionData.ConditionForAnimation != TransitionCondition.Remove) { var vector = new Vector3(layoutPositionData.Left, layoutPositionData.Top, layoutPositionData.Item.Owner.Position.Z); coreAnimation.AnimateTo(layoutPositionData.Item.Owner, "Position", vector, positionTransitionComponents.Delay, positionTransitionComponents.Duration, positionTransitionComponents.AlphaFunction); NUILog.Debug("LayoutController SetupAnimationForPosition View:" + layoutPositionData.Item.Owner.Name + " left:" + layoutPositionData.Left + " top:" + layoutPositionData.Top + " delay:" + positionTransitionComponents.Delay + " duration:" + positionTransitionComponents.Duration); vector.Dispose(); vector = null; } }
/// <summary> /// Sets up the main animation with the animators for each item (each layoutPositionData structure) /// </summary> private void AddAnimatorsToAnimation(LayoutData layoutPositionData) { LayoutTransition positionTransition = new LayoutTransition(); LayoutTransition sizeTransition = new LayoutTransition(); TransitionCondition conditionForAnimators = layoutPositionData.ConditionForAnimation; // LayoutChanged transitions overrides ChangeOnAdd and ChangeOnRemove as siblings will // reposition to the new layout not to the insertion/removal of a sibling. if (layoutPositionData.ConditionForAnimation.HasFlag(TransitionCondition.LayoutChanged)) { conditionForAnimators = TransitionCondition.LayoutChanged; } // Set up a default transitions, will be overwritten if inherited from parent or set explicitly. TransitionComponents positionTransitionComponents = CreateDefaultTransitionComponent(0, 300); TransitionComponents sizeTransitionComponents = CreateDefaultTransitionComponent(0, 300); bool matchedCustomTransitions = false; TransitionList transitionsForCurrentCondition = new TransitionList(); // Note, Transitions set on View rather than LayoutItem so if the Layout changes the transition persist. // Check if item to animate has it's own Transitions for this condition. // If a key exists then a List of at least 1 transition exists. if (layoutPositionData.Item.Owner.LayoutTransitions.ContainsKey(conditionForAnimators)) { // Child has transitions for the condition matchedCustomTransitions = layoutPositionData.Item.Owner.LayoutTransitions.TryGetValue(conditionForAnimators, out transitionsForCurrentCondition); } if (!matchedCustomTransitions) { // Inherit parent transitions as none already set on View for the condition. ILayoutParent layoutParent = layoutPositionData.Item.GetParent(); if (layoutParent != null) { // Item doesn't have it's own transitions for this condition so copy parents if // has a parent with transitions. LayoutGroup layoutGroup = layoutParent as LayoutGroup; TransitionList parentTransitionList; // Note TryGetValue returns null if key not matched. if (layoutGroup != null && layoutGroup.Owner.LayoutTransitions.TryGetValue(conditionForAnimators, out parentTransitionList)) { // Copy parent transitions to temporary TransitionList. List contains transitions for the current condition. LayoutTransitionsHelper.CopyTransitions(parentTransitionList, transitionsForCurrentCondition); } } } // Position/Size transitions can be displayed for a layout changing to another layout or an item being added or removed. // There can only be one position transition and one size position, they will be replaced if set multiple times. // transitionsForCurrentCondition represent all non position (custom) properties that should be animated. // Search for Position property in the transitionsForCurrentCondition list of custom transitions, // and only use the particular parts of the animator as custom transitions should not effect all parameters of Position. // Typically Delay, Duration and Alphafunction can be custom. FindAndReplaceAnimatorComponentsForProperty(transitionsForCurrentCondition, AnimatableProperties.Position, ref positionTransitionComponents); // Size FindAndReplaceAnimatorComponentsForProperty(transitionsForCurrentCondition, AnimatableProperties.Size, ref sizeTransitionComponents); // Add animators to the core Animation, SetupAnimationForCustomTransitions(transitionsForCurrentCondition, layoutPositionData.Item.Owner); SetupAnimationForPosition(layoutPositionData, positionTransitionComponents); SetupAnimationForSize(layoutPositionData, sizeTransitionComponents); // Dispose components positionTransitionComponents.Dispose(); sizeTransitionComponents.Dispose(); }
/// <summary> /// Add transition data for a LayoutItem to the transition stack. /// </summary> /// <param name="transitionDataEntry">Transition data for a LayoutItem.</param> internal void AddTransitionDataEntry(LayoutData transitionDataEntry) { layoutTransitionDataQueue.Add(transitionDataEntry); }
private bool SetFrame(float left, float top, float right, float bottom, bool independent) { bool changed = false; if (_layoutPositionData.Left != left || _layoutPositionData.Right != right || _layoutPositionData.Top != top || _layoutPositionData.Bottom != bottom) { changed = true; float oldWidth = _layoutPositionData.Right - _layoutPositionData.Left; float oldHeight = _layoutPositionData.Bottom - _layoutPositionData.Top; float newWidth = right - left; float newHeight = bottom - top; bool sizeChanged = (newWidth != oldWidth) || (newHeight != oldHeight); // Set condition to layout changed as currently unspecified. Add, Remove would have specified a condition. if (ConditionForAnimation.Equals(TransitionCondition.Unspecified)) { ConditionForAnimation = TransitionCondition.LayoutChanged; } // Store new layout position data _layoutPositionData = new LayoutData(this, ConditionForAnimation, left, top, right, bottom); Debug.WriteLineIf(LayoutDebugFrameData, "LayoutItem FramePositionData View:" + _layoutPositionData.Item.Owner.Name + " left:" + _layoutPositionData.Left + " top:" + _layoutPositionData.Top + " right:" + _layoutPositionData.Right + " bottom:" + _layoutPositionData.Bottom); Container onwerContainer = Owner.GetParent(); View onwerView = onwerContainer is Layer ? new View(Layer.getCPtr(onwerContainer).Handle, false) : onwerContainer as View; if (onwerView != null && onwerView.Layout != null && onwerView.Layout.LayoutWithTransition) { NUIApplication.GetDefaultWindow().LayoutController.AddTransitionDataEntry(_layoutPositionData); } else { if (Owner.Position != null) { if (independent) { // If height or width specification is not explicitly defined, // the size of the owner view must be reset even the ExcludeLayouting is true. if (Owner.HeightSpecification < 0 || Owner.WidthSpecification < 0) { Owner.SetSize(right - left, bottom - top); } } else { Owner.SetSize(right - left, bottom - top); Owner.SetPosition(left, top); } } } // Reset condition for animation ready for next transition when required. ConditionForAnimation = TransitionCondition.Unspecified; } return(changed); }
/// <summary> /// Add transition data for a LayoutItem to the transition stack. /// </summary> /// <param name="transitionDataEntry">Transition data for a LayoutItem.</param> internal void AddTransitionDataEntry(LayoutData transitionDataEntry) { transitionManager.AddTransitionDataEntry(transitionDataEntry); }
private bool SetFrame(float left, float top, float right, float bottom, bool independent) { bool changed = false; if (layoutPositionData.Left != left || layoutPositionData.Right != right || layoutPositionData.Top != top || layoutPositionData.Bottom != bottom) { changed = true; // Set condition to layout changed as currently unspecified. Add, Remove would have specified a condition. if (ConditionForAnimation.Equals(TransitionCondition.Unspecified)) { ConditionForAnimation = TransitionCondition.LayoutChanged; } // Store new layout position data layoutPositionData = new LayoutData(this, ConditionForAnimation, left, top, right, bottom); NUILog.Debug("LayoutItem FramePositionData View:" + layoutPositionData.Item.Owner.Name + " left:" + layoutPositionData.Left + " top:" + layoutPositionData.Top + " right:" + layoutPositionData.Right + " bottom:" + layoutPositionData.Bottom); View ownerView = Owner.GetParent() as View; if (ownerView?.Layout?.LayoutWithTransition ?? false) { var win = Window.Get(Owner); if (win == null) { NUIApplication.GetDefaultWindow().LayoutController.AddTransitionDataEntry(layoutPositionData); } else { win.LayoutController.AddTransitionDataEntry(layoutPositionData); } } else { if (independent) { // If height or width specification is not explicitly defined, // the size of the owner view must be reset even the ExcludeLayouting is true. if (Owner.HeightSpecification < 0 || Owner.WidthSpecification < 0) { Owner.SetSize(right - left, bottom - top); } } else { Owner.SetSize(right - left, bottom - top); Owner.SetPosition(left, top); } } // Reset condition for animation ready for next transition when required. ConditionForAnimation = TransitionCondition.Unspecified; } return(changed); }
private void Initialize() { _layoutPositionData = new LayoutData(this, TransitionCondition.Unspecified, 0, 0, 0, 0); _padding = new Extents(0, 0, 0, 0); _margin = new Extents(0, 0, 0, 0); }
/// <summary> /// Sets up the main animation with the animators for each item (each layoutPositionData structure) /// </summary> private void AddAnimatorsToAnimation(LayoutData layoutPositionData) { LayoutTransition positionTransition = new LayoutTransition(); TransitionCondition conditionForAnimators = layoutPositionData.ConditionForAnimation; // LayoutChanged transitions overrides ChangeOnAdd and ChangeOnRemove as siblings will // reposition to the new layout not to the insertion/removal of a sibling. if (layoutPositionData.ConditionForAnimation.HasFlag(TransitionCondition.LayoutChanged)) { conditionForAnimators = TransitionCondition.LayoutChanged; } // Set up a default transition, will be overwritten if inherited from parent or set explicitly. const int START_TIME = 0; const int END_TIME = 100; AlphaFunction alphaFunction = new AlphaFunction(AlphaFunction.BuiltinFunctions.Linear); // positionTransitionComponents will be overwritten if set explicitly TransitionComponents positionTransitionComponents = new TransitionComponents(START_TIME, END_TIME, alphaFunction); bool matchedCustomTransitions = false; // Inherit parent transitions if none already set on View for the condition. // Transitions set on View rather than LayoutItem so if the Layout changes the transition persist. // Still need to inherit Position animator from parent but not other animatable properties if already set. TransitionList transitionsForCurrentCondition; ILayoutParent layoutParent = layoutPositionData.Item.GetParent(); if (layoutParent != null) { // Check if item to aninmate has it's own Transitions for this condition. if (layoutPositionData.Item.Owner.LayoutTransitions.ContainsKey(conditionForAnimators)) { matchedCustomTransitions = true; // If a key exists then a List of atleast 1 transition exists. } else { // Item doesn't have it's own transitions for this condition so copy parents if // has a parent with transitions. transitionsForCurrentCondition = new TransitionList(); LayoutGroup layoutGroup = layoutParent as LayoutGroup; TransitionList parentTransitionList; // Note TryGetValue returns null if key not matched. if (layoutGroup.Owner.LayoutTransitions.TryGetValue(conditionForAnimators, out parentTransitionList)) { // Copy parent transitions for this condition to temporary TransitionList. LayoutTransitionsHelper.CopyTransitions(parentTransitionList, transitionsForCurrentCondition); SetupAnimationForCustomTransitions(transitionsForCurrentCondition, layoutPositionData.Item.Owner); matchedCustomTransitions = false; } } } // SetupAnimationXXXX functions add Animators to the core Animation, these can be custom or set by the // layout system in the case of Positioning. if (matchedCustomTransitions) { // Position transition can be for a layout changing to another layout or an item being added or removed. // There can only be one position transition, it will be replaced if set multiple times. // transitionsForCurrentCondition represent all non position (custom) properties that should be animated. // There can be multiple properties hence returned as a list. if (layoutPositionData.Item.Owner.LayoutTransitions.TryGetValue(conditionForAnimators, out transitionsForCurrentCondition)) { // Search for Position property in the transitionsForCurrentCondition list of custom transitions, // and only use the particular parts of the animator as custom transitions should not effect all parameters of Position. // Typically Delay, Duration and Alphafunction can be custom. FindAndReplaceAnimatorComponentsForProperty(transitionsForCurrentCondition, AnimatableProperties.Position, ref positionTransitionComponents); SetupAnimationForCustomTransitions(transitionsForCurrentCondition, layoutPositionData.Item.Owner); } } SetupAnimationForPosition(layoutPositionData, positionTransitionComponents); SetupAnimationForText(layoutPositionData); }