2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Collections.Generic;
20 using System.ComponentModel;
25 /// Define a List of LayoutTransitions
27 /// Hidden-API which is usually used as Inhouse-API. If required to be opened as Public-API, ACR process is needed.
28 [EditorBrowsable(EditorBrowsableState.Never)]
29 public class TransitionList : List<LayoutTransition> {}
32 /// The properties that can be animated.
34 /// Hidden-API which is usually used as Inhouse-API. If required to be opened as Public-API, ACR process is needed.
35 [EditorBrowsable(EditorBrowsableState.Never)]
36 public enum AnimatableProperties
39 /// Position property.
41 /// Hidden-API which is usually used as Inhouse-API. If required to be opened as Public-API, ACR process is needed.
42 [EditorBrowsable(EditorBrowsableState.Never)]
47 /// Hidden-API which is usually used as Inhouse-API. If required to be opened as Public-API, ACR process is needed.
48 [EditorBrowsable(EditorBrowsableState.Never)]
53 /// Hidden-API which is usually used as Inhouse-API. If required to be opened as Public-API, ACR process is needed.
54 [EditorBrowsable(EditorBrowsableState.Never)]
59 /// Parts of the transition that can be configured to provide a custom effect.
61 /// Hidden-API which is usually used as Inhouse-API. If required to be opened as Public-API, ACR process is needed.
62 [EditorBrowsable(EditorBrowsableState.Never)]
63 public class TransitionComponents
66 /// TransitionComponents default constructor.
68 /// Hidden-API which is usually used as Inhouse-API. If required to be opened as Public-API, ACR process is needed.
69 [EditorBrowsable(EditorBrowsableState.Never)]
70 public TransitionComponents()
74 AlphaFunction = new AlphaFunction(AlphaFunction.BuiltinFunctions.Linear);
78 /// TransitionComponents constructor. Stores delay, duration and AlphaFunction.
80 /// <param name="delay">The delay before the animator starts.</param>
81 /// <param name="duration">the duration fo the animator.</param>
82 /// <param name="alphaFunction">alpha function to use .</param>
83 /// Hidden-API which is usually used as Inhouse-API. If required to be opened as Public-API, ACR process is needed.
84 [EditorBrowsable(EditorBrowsableState.Never)]
85 public TransitionComponents(int delay, int duration, AlphaFunction alphaFunction)
89 AlphaFunction = alphaFunction;
93 /// Time the transition should execute. Milliseconds.
95 /// Hidden-API which is usually used as Inhouse-API. If required to be opened as Public-API, ACR process is needed.
96 [EditorBrowsable(EditorBrowsableState.Never)]
99 /// Delay before the transition executes. Milliseconds.
101 /// Hidden-API which is usually used as Inhouse-API. If required to be opened as Public-API, ACR process is needed.
102 [EditorBrowsable(EditorBrowsableState.Never)]
105 /// Function to alter the transition path over time.
107 /// Hidden-API which is usually used as Inhouse-API. If required to be opened as Public-API, ACR process is needed.
108 [EditorBrowsable(EditorBrowsableState.Never)]
109 public AlphaFunction AlphaFunction;
113 /// LayoutTransition stores the aninmation setting for a transition conidition.
115 /// Hidden-API which is usually used as Inhouse-API. If required to be opened as Public-API, ACR process is needed.
116 [EditorBrowsable(EditorBrowsableState.Never)]
117 public class LayoutTransition
120 /// LayoutTransition default constructor.
122 /// Hidden-API which is usually used as Inhouse-API. If required to be opened as Public-API, ACR process is needed.
123 [EditorBrowsable(EditorBrowsableState.Never)]
124 public LayoutTransition()
126 Condition = TransitionCondition.Unspecified;
127 AnimatableProperty = AnimatableProperties.Position;
132 /// LayoutTransition constructor.
134 /// <param name="condition">The animatable condition.</param>
135 /// <param name="animatableProperty">the property to animate.</param>
136 /// <param name="targetValue">target value of the property.</param>
137 /// <param name="animator">Components to define the animator.</param>
138 /// Hidden-API which is usually used as Inhouse-API. If required to be opened as Public-API, ACR process is needed.
139 [EditorBrowsable(EditorBrowsableState.Never)]
140 public LayoutTransition( TransitionCondition condition,
141 AnimatableProperties animatableProperty,
143 TransitionComponents animator)
145 Condition = condition;
146 AnimatableProperty = animatableProperty;
148 TargetValue = targetValue;
152 /// Condition for this Transition
154 /// Hidden-API which is usually used as Inhouse-API. If required to be opened as Public-API, ACR process is needed.
155 [EditorBrowsable(EditorBrowsableState.Never)]
156 public TransitionCondition Condition{get; set;}
158 /// Property to animate.
160 /// Hidden-API which is usually used as Inhouse-API. If required to be opened as Public-API, ACR process is needed.
161 [EditorBrowsable(EditorBrowsableState.Never)]
162 public AnimatableProperties AnimatableProperty{get; set;}
164 /// Components of the Animator.
166 /// Hidden-API which is usually used as Inhouse-API. If required to be opened as Public-API, ACR process is needed.
167 [EditorBrowsable(EditorBrowsableState.Never)]
168 public TransitionComponents Animator{get; set;}
170 /// Target value to animate to.
172 /// Hidden-API which is usually used as Inhouse-API. If required to be opened as Public-API, ACR process is needed.
173 [EditorBrowsable(EditorBrowsableState.Never)]
174 public object TargetValue{get; set;}
179 /// Class to help manage the adding and updating of transitions.
181 internal static class LayoutTransitionsHelper
184 /// Adds the given transition and condition to a transition list.
186 /// <param name="targetTransitionList">The list to add the transition to.</param>
187 /// <param name="condition">Condition for the transition.</param>
188 /// <param name="transition">The transition to add.</param>
189 /// <param name="explicitlySet">True is set explicitly, false if inherited.</param>
190 static public void AddTransitionForCondition(
191 Dictionary<TransitionCondition, TransitionList> targetTransitionList,
192 TransitionCondition condition,
193 LayoutTransition transition,
196 bool replaced = false;
197 bool conditionNotInDictionary = false;
198 TransitionList transitionListMatchingCondition;
199 if (targetTransitionList.TryGetValue(condition, out transitionListMatchingCondition))
201 for (var index=0; index < transitionListMatchingCondition?.Count; index++ )
203 if (transitionListMatchingCondition[index].AnimatableProperty == transition.AnimatableProperty)
207 transitionListMatchingCondition[index] = transition;
216 conditionNotInDictionary = true;
219 if (replaced == false)
221 if (transitionListMatchingCondition == null)
223 transitionListMatchingCondition = new TransitionList();
225 transitionListMatchingCondition.Add(transition);
226 // Update dictionary with new or replaced entry.
227 if (conditionNotInDictionary)
229 targetTransitionList.Add(condition, transitionListMatchingCondition); // new entry
233 targetTransitionList[condition] = transitionListMatchingCondition; // replaced
239 /// Retreive the transition list for the given condition.
241 /// <param name="sourceTransitionCollection">The source collection of transition lists to retrieve.</param>
242 /// <param name="condition">Condition for the transition.</param>
243 /// <param name="transitionsForCondition">transition list to return as out parameter.</param>
244 /// <returns>True if a transition list found for the given condition></returns>
245 static public bool GetTransitionsListForCondition(
246 Dictionary<TransitionCondition, TransitionList> sourceTransitionCollection,
247 TransitionCondition condition,
248 TransitionList transitionsForCondition )
250 TransitionCondition resolvedCondition = condition;
251 bool matched = false;
252 // LayoutChanged transitions overrides ChangeOnAdd and ChangeOnRemove as siblings will
253 // reposition to the new layout not to the insertion/removal of a sibling.
254 if ((condition & TransitionCondition.LayoutChanged) == TransitionCondition.LayoutChanged)
256 resolvedCondition = TransitionCondition.LayoutChanged;
259 if (sourceTransitionCollection.TryGetValue(resolvedCondition, out transitionsForCondition))
268 /// Copy the transitions in the source list to the target list
270 /// <param name="sourceTransitionList">The source transition list.</param>
271 /// <param name="targetTransitionList">The target transition list to copy to.</param>
272 static public void CopyTransitions( TransitionList sourceTransitionList,
273 TransitionList targetTransitionList )
275 targetTransitionList.Clear();
276 foreach (LayoutTransition transitionToApply in sourceTransitionList)
278 // Overwite existing transitions
279 targetTransitionList.Add(transitionToApply);
285 } // namespace Tizen.NUI