2 * Copyright(c) 2020 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.
19 using System.ComponentModel;
20 using System.Reflection;
21 using System.Runtime.InteropServices;
22 using Tizen.NUI.Binding;
24 namespace Tizen.NUI.BaseComponents
27 /// View is the base class for all views.
29 /// <since_tizen> 3 </since_tizen>
30 public partial class View
33 /// Perform an action on a visual registered to this view. <br />
34 /// Visuals will have actions. This API is used to perform one of these actions with the given attributes.
36 /// <param name="propertyIndexOfVisual">The Property index of the visual.</param>
37 /// <param name="propertyIndexOfActionId">The action to perform. See Visual to find the supported actions.</param>
38 /// <param name="attributes">Optional attributes for the action.</param>
39 /// <since_tizen> 5 </since_tizen>
40 public void DoAction(int propertyIndexOfVisual, int propertyIndexOfActionId, PropertyValue attributes)
42 Interop.View.View_DoAction(swigCPtr, propertyIndexOfVisual, propertyIndexOfActionId, PropertyValue.getCPtr(attributes));
43 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
47 /// Creates an animation to animate the background color visual. If there is no
48 /// background visual, creates one with transparent black as it's mixColor.
50 /// <since_tizen> 3 </since_tizen>
51 public Animation AnimateBackgroundColor(object destinationValue,
54 AlphaFunction.BuiltinFunctions? alphaFunction = null,
55 object initialValue = null)
57 Tizen.NUI.PropertyMap background = Background;
59 if (background.Empty())
61 // If there is no background yet, ensure there is a transparent
63 BackgroundColor = new Color(0.0f, 0.0f, 0.0f, 0.0f);
64 background = Background;
66 return AnimateColor("background", destinationValue, startTime, endTime, alphaFunction, initialValue);
70 /// Creates an animation to animate the mixColor of the named visual.
72 /// <since_tizen> 3 </since_tizen>
73 public Animation AnimateColor(string targetVisual, object destinationColor, int startTime, int endTime, AlphaFunction.BuiltinFunctions? alphaFunction = null, object initialColor = null)
75 Animation animation = null;
77 PropertyMap _animator = new PropertyMap();
78 if (alphaFunction != null)
80 _animator.Add("alphaFunction", new PropertyValue(AlphaFunction.BuiltinToPropertyKey(alphaFunction)));
83 PropertyMap _timePeriod = new PropertyMap();
84 _timePeriod.Add("duration", new PropertyValue((endTime - startTime) / 1000.0f));
85 _timePeriod.Add("delay", new PropertyValue(startTime / 1000.0f));
86 _animator.Add("timePeriod", new PropertyValue(_timePeriod));
88 PropertyMap _transition = new PropertyMap();
89 _transition.Add("animator", new PropertyValue(_animator));
90 _transition.Add("target", new PropertyValue(targetVisual));
91 _transition.Add("property", new PropertyValue("mixColor"));
93 if (initialColor != null)
95 PropertyValue initValue = PropertyValue.CreateFromObject(initialColor);
96 _transition.Add("initialValue", initValue);
99 PropertyValue destValue = PropertyValue.CreateFromObject(destinationColor);
100 _transition.Add("targetValue", destValue);
101 TransitionData _transitionData = new TransitionData(_transition);
103 animation = new Animation(Interop.View.View_CreateTransition(swigCPtr, TransitionData.getCPtr(_transitionData)), true);
104 if (NDalicPINVOKE.SWIGPendingException.Pending)
105 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
110 // From Container Base class
112 /// Adds a child view to this view.
114 /// <seealso cref="Container.Add" />
115 /// <since_tizen> 4 </since_tizen>
116 public override void Add(View child)
118 bool hasLayout = (_layout != null);
122 Tizen.Log.Fatal("NUI", "Child is null");
126 Container oldParent = child.GetParent();
127 if (oldParent != this)
129 // If child already has a parent then re-parent child
130 if (oldParent != null)
132 if (child.Layout !=null)
134 child.Layout.SetReplaceFlag();
136 oldParent.Remove(child);
138 child.InternalParent = this;
140 Interop.Actor.ActorAdd(swigCPtr, View.getCPtr(child));
142 if (NDalicPINVOKE.SWIGPendingException.Pending)
143 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
146 if (ChildAdded != null)
148 ChildAddedEventArgs e = new ChildAddedEventArgs
154 BindableObject.SetInheritedBindingContext(child, this?.BindingContext);
159 /// Removes a child view from this View. If the view was not a child of this view, this is a no-op.
161 /// <seealso cref="Container.Remove" />
162 /// <since_tizen> 4 </since_tizen>
163 public override void Remove(View child)
165 if (!child || child.GetParent() == null) // Early out if child null.
168 bool hasLayout = (_layout != null);
170 // If View has a layout then do a deferred child removal
171 // Actual child removal is performed by the layouting system so
172 // transitions can be completed.
175 (_layout as LayoutGroup)?.RemoveChildFromLayoutGroup(child);
182 /// Retrieves a child view by index.
184 /// <seealso cref="Container.GetChildAt" />
185 /// <since_tizen> 4 </since_tizen>
186 public override View GetChildAt(uint index)
188 if (index < Children.Count)
190 return Children[Convert.ToInt32(index)];
199 /// Retrieves the number of children held by the view.
201 /// <seealso cref="Container.GetChildCount" />
202 /// <since_tizen> 4 </since_tizen>
203 public override uint GetChildCount()
205 return Convert.ToUInt32(Children.Count);
209 /// Gets the views parent.
211 /// <seealso cref="Container.GetParent()" />
212 /// <since_tizen> 4 </since_tizen>
213 public override Container GetParent()
215 return this.InternalParent as Container;
219 /// Queries whether the view has a focus.
221 /// <returns>True if this view has a focus.</returns>
222 /// <since_tizen> 3 </since_tizen>
223 public bool HasFocus()
226 if (swigCPtr.Handle != global::System.IntPtr.Zero)
228 ret = Interop.View.View_HasKeyInputFocus(swigCPtr);
229 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
233 Tizen.Log.Error("NUI", "swigCPtr of view is aleady disposed.");
239 /// Sets the name of the style to be applied to the view.
241 /// <param name="styleName">A string matching a style described in a stylesheet.</param>
242 /// <since_tizen> 3 </since_tizen>
243 public void SetStyleName(string styleName)
245 Interop.View.View_SetStyleName(swigCPtr, styleName);
246 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
250 /// Retrieves the name of the style to be applied to the view (if any).
252 /// <returns>A string matching a style, or an empty string.</returns>
253 /// <since_tizen> 3 </since_tizen>
254 public string GetStyleName()
256 string ret = Interop.View.View_GetStyleName(swigCPtr);
257 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
262 /// Clears the background.
264 /// <since_tizen> 3 </since_tizen>
265 public void ClearBackground()
267 Interop.View.View_ClearBackground(swigCPtr);
268 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
275 /// This is an asynchronous method.
277 /// <since_tizen> 3 </since_tizen>
287 /// This is an asynchronous method.
288 /// If the view is hidden, then the view and its children will not be rendered.
289 /// This is regardless of the individual visibility of the children, i.e., the view will only be rendered if all of its parents are shown.
291 /// <since_tizen> 3 </since_tizen>
298 /// Raises the view above all other views.
301 /// Sibling order of views within the parent will be updated automatically.
302 /// Once a raise or lower API is used, that view will then have an exclusive sibling order independent of insertion.
304 /// <since_tizen> 3 </since_tizen>
305 public void RaiseToTop()
307 var parentChildren = GetParent()?.Children;
309 if (parentChildren != null)
311 parentChildren.Remove(this);
312 parentChildren.Add(this);
314 LayoutGroup layout = Layout as LayoutGroup;
315 layout?.ChangeLayoutSiblingOrder(parentChildren.Count-1);
317 Interop.NDalic.RaiseToTop(swigCPtr);
318 if (NDalicPINVOKE.SWIGPendingException.Pending)
319 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
325 /// Lowers the view to the bottom of all views.
328 /// The sibling order of views within the parent will be updated automatically.
329 /// Once a raise or lower API is used that view will then have an exclusive sibling order independent of insertion.
331 /// <since_tizen> 3 </since_tizen>
332 public void LowerToBottom()
334 var parentChildren = GetParent()?.Children;
336 if (parentChildren != null)
338 parentChildren.Remove(this);
339 parentChildren.Insert(0, this);
341 LayoutGroup layout = Layout as LayoutGroup;
342 layout?.ChangeLayoutSiblingOrder(0);
344 Interop.NDalic.LowerToBottom(swigCPtr);
345 if (NDalicPINVOKE.SWIGPendingException.Pending)
346 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
351 /// Queries if all resources required by a view are loaded and ready.
353 /// <remarks>Most resources are only loaded when the control is placed on the stage.
355 /// <since_tizen> 3 </since_tizen>
356 public bool IsResourceReady()
358 bool ret = Interop.View.IsResourceReady(swigCPtr);
359 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
364 /// Gets the parent layer of this view.If a view has no parent, this method does not do anything.
366 /// <pre>The view has been initialized. </pre>
367 /// <returns>The parent layer of view </returns>
368 /// <since_tizen> 5 </since_tizen>
369 public Layer GetLayer()
371 //to fix memory leak issue, match the handle count with native side.
372 IntPtr cPtr = Interop.Actor.ActorGetLayer(swigCPtr);
373 Layer ret = this.GetInstanceSafely<Layer>(cPtr);
374 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
379 /// Removes a view from its parent view or layer. If a view has no parent, this method does nothing.
381 /// <pre>The (child) view has been initialized. </pre>
382 /// <since_tizen> 4 </since_tizen>
383 public void Unparent()
385 GetParent()?.Remove(this);
389 /// Search through this view's hierarchy for a view with the given name.
390 /// The view itself is also considered in the search.
392 /// <pre>The view has been initialized.</pre>
393 /// <param name="viewName">The name of the view to find.</param>
394 /// <returns>A handle to the view if found, or an empty handle if not.</returns>
395 /// <since_tizen> 3 </since_tizen>
396 public View FindChildByName(string viewName)
398 //to fix memory leak issue, match the handle count with native side.
399 IntPtr cPtr = Interop.Actor.ActorFindChildByName(swigCPtr, viewName);
400 View ret = this.GetInstanceSafely<View>(cPtr);
401 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
406 /// Converts screen coordinates into the view's coordinate system using the default camera.
408 /// <pre>The view has been initialized.</pre>
409 /// <remarks>The view coordinates are relative to the top-left(0.0, 0.0, 0.5).</remarks>
410 /// <param name="localX">On return, the X-coordinate relative to the view.</param>
411 /// <param name="localY">On return, the Y-coordinate relative to the view.</param>
412 /// <param name="screenX">The screen X-coordinate.</param>
413 /// <param name="screenY">The screen Y-coordinate.</param>
414 /// <returns>True if the conversion succeeded.</returns>
415 /// <since_tizen> 3 </since_tizen>
416 public bool ScreenToLocal(out float localX, out float localY, float screenX, float screenY)
418 bool ret = Interop.Actor.ActorScreenToLocal(swigCPtr, out localX, out localY, screenX, screenY);
419 if (NDalicPINVOKE.SWIGPendingException.Pending)
420 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
425 /// Sets the relative to parent size factor of the view.<br />
426 /// This factor is only used when ResizePolicy is set to either:
427 /// ResizePolicy::SIZE_RELATIVE_TO_PARENT or ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT.<br />
428 /// This view's size is set to the view's size multiplied by or added to this factor, depending on ResizePolicy.<br />
430 /// <pre>The view has been initialized.</pre>
431 /// <param name="factor">A Vector3 representing the relative factor to be applied to each axis.</param>
432 /// <since_tizen> 3 </since_tizen>
433 public void SetSizeModeFactor(Vector3 factor)
435 Interop.Actor.ActorSetSizeModeFactor(swigCPtr, Vector3.getCPtr(factor));
436 if (NDalicPINVOKE.SWIGPendingException.Pending)
437 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
440 /// Calculates the height of the view given a width.<br />
441 /// The natural size is used for default calculation.<br />
442 /// Size 0 is treated as aspect ratio 1:1.<br />
444 /// <param name="width">The width to use.</param>
445 /// <returns>The height based on the width.</returns>
446 /// <since_tizen> 3 </since_tizen>
447 public float GetHeightForWidth(float width)
449 float ret = Interop.Actor.ActorGetHeightForWidth(swigCPtr, width);
450 if (NDalicPINVOKE.SWIGPendingException.Pending)
451 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
456 /// Calculates the width of the view given a height.<br />
457 /// The natural size is used for default calculation.<br />
458 /// Size 0 is treated as aspect ratio 1:1.<br />
460 /// <param name="height">The height to use.</param>
461 /// <returns>The width based on the height.</returns>
462 /// <since_tizen> 3 </since_tizen>
463 public float GetWidthForHeight(float height)
465 float ret = Interop.Actor.ActorGetWidthForHeight(swigCPtr, height);
466 if (NDalicPINVOKE.SWIGPendingException.Pending)
467 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
472 /// Return the amount of size allocated for relayout.
474 /// <param name="dimension">The dimension to retrieve.</param>
475 /// <returns>Return the size.</returns>
476 /// <since_tizen> 3 </since_tizen>
477 public float GetRelayoutSize(DimensionType dimension)
479 float ret = Interop.Actor.ActorGetRelayoutSize(swigCPtr, (int)dimension);
480 if (NDalicPINVOKE.SWIGPendingException.Pending)
481 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
486 /// Set the padding for the view.
488 /// <param name="padding">Padding for the view.</param>
489 /// <since_tizen> 3 </since_tizen>
490 public void SetPadding(PaddingType padding)
492 Interop.Actor.ActorSetPadding(swigCPtr, PaddingType.getCPtr(padding));
493 if (NDalicPINVOKE.SWIGPendingException.Pending)
494 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
498 /// Return the value of padding for the view.
500 /// <param name="paddingOut">the value of padding for the view</param>
501 /// <since_tizen> 3 </since_tizen>
502 public void GetPadding(PaddingType paddingOut)
504 Interop.Actor.ActorGetPadding(swigCPtr, PaddingType.getCPtr(paddingOut));
505 if (NDalicPINVOKE.SWIGPendingException.Pending)
506 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
509 /// <since_tizen> 3 </since_tizen>
510 public uint AddRenderer(Renderer renderer)
512 uint ret = Interop.Actor.ActorAddRenderer(swigCPtr, Renderer.getCPtr(renderer));
513 if (NDalicPINVOKE.SWIGPendingException.Pending)
514 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
518 /// <since_tizen> 3 </since_tizen>
519 public Renderer GetRendererAt(uint index)
521 //to fix memory leak issue, match the handle count with native side.
522 IntPtr cPtr = Interop.Actor.ActorGetRendererAt(swigCPtr, index);
523 HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
524 Renderer ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as Renderer;
525 if (cPtr != null && ret == null)
527 ret = new Renderer(cPtr, false);
528 if (NDalicPINVOKE.SWIGPendingException.Pending)
529 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
532 Interop.BaseHandle.delete_BaseHandle(CPtr);
533 CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
535 if (NDalicPINVOKE.SWIGPendingException.Pending)
536 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
540 /// <since_tizen> 3 </since_tizen>
541 public void RemoveRenderer(Renderer renderer)
543 Interop.Actor.ActorRemoveRenderer(swigCPtr, Renderer.getCPtr(renderer));
544 if (NDalicPINVOKE.SWIGPendingException.Pending)
545 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
548 /// <since_tizen> 3 </since_tizen>
549 public void RemoveRenderer(uint index)
551 Interop.Actor.ActorRemoveRenderer(swigCPtr, index);
552 if (NDalicPINVOKE.SWIGPendingException.Pending)
553 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
556 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
557 [EditorBrowsable(EditorBrowsableState.Never)]
558 public void RotateBy(Degree angle, Vector3 axis)
560 Interop.ActorInternal.ActorRotateByDegree(swigCPtr, Degree.getCPtr(angle), Vector3.getCPtr(axis));
561 if (NDalicPINVOKE.SWIGPendingException.Pending)
562 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
565 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
566 [EditorBrowsable(EditorBrowsableState.Never)]
567 public void RotateBy(Radian angle, Vector3 axis)
569 Interop.ActorInternal.ActorRotateByRadian(swigCPtr, Radian.getCPtr(angle), Vector3.getCPtr(axis));
570 if (NDalicPINVOKE.SWIGPendingException.Pending)
571 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
574 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
575 [EditorBrowsable(EditorBrowsableState.Never)]
576 public void RotateBy(Rotation relativeRotation)
578 Interop.ActorInternal.ActorRotateByQuaternion(swigCPtr, Rotation.getCPtr(relativeRotation));
579 if (NDalicPINVOKE.SWIGPendingException.Pending)
580 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
583 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
584 [EditorBrowsable(EditorBrowsableState.Never)]
585 public void ScaleBy(Vector3 relativeScale)
587 Interop.ActorInternal.ActorScaleBy(swigCPtr, Vector3.getCPtr(relativeScale));
588 if (NDalicPINVOKE.SWIGPendingException.Pending)
589 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
592 /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
593 [EditorBrowsable(EditorBrowsableState.Never)]
594 public void SetColorMode(ColorMode colorMode)
596 Interop.ActorInternal.ActorSetColorMode(swigCPtr, (int)colorMode);
597 if (NDalicPINVOKE.SWIGPendingException.Pending)
598 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
603 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
604 [EditorBrowsable(EditorBrowsableState.Never)]
605 public Transition GetTransition(string transitionName)
607 Transition trans = null;
608 transDictionary.TryGetValue(transitionName, out trans);
612 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
613 [EditorBrowsable(EditorBrowsableState.Never)]
614 public void ObjectDump()
616 if ( 0== Children.Count)
618 Type type = this.GetType();
619 PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
620 foreach(var property in properties)
622 if (null != property && property.CanRead)
624 Tizen.Log.Fatal("NUI", $"{type.Name} {property.Name} ({property.PropertyType.Name}): {property.GetValueString(this, property.PropertyType)}");
630 foreach (View view in Children)