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.
19 using System.ComponentModel;
20 using System.Runtime.InteropServices;
21 using Tizen.NUI.Binding;
23 namespace Tizen.NUI.BaseComponents
26 /// View is the base class for all views.
28 /// <since_tizen> 3 </since_tizen>
29 public partial class View
32 /// Perform an action on a visual registered to this view. <br />
33 /// Visuals will have actions. This API is used to perform one of these actions with the given attributes.
35 /// <param name="propertyIndexOfVisual">The Property index of the visual.</param>
36 /// <param name="propertyIndexOfActionId">The action to perform. See Visual to find the supported actions.</param>
37 /// <param name="attributes">Optional attributes for the action.</param>
38 /// <since_tizen> 5 </since_tizen>
39 public void DoAction(int propertyIndexOfVisual, int propertyIndexOfActionId, PropertyValue attributes)
41 Interop.View.View_DoAction(swigCPtr, propertyIndexOfVisual, propertyIndexOfActionId, PropertyValue.getCPtr(attributes));
42 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
46 /// Creates an animation to animate the background color visual. If there is no
47 /// background visual, creates one with transparent black as it's mixColor.
49 /// <since_tizen> 3 </since_tizen>
50 public Animation AnimateBackgroundColor(object destinationValue,
53 AlphaFunction.BuiltinFunctions? alphaFunction = null,
54 object initialValue = null)
56 Tizen.NUI.PropertyMap background = Background;
58 if (background.Empty())
60 // If there is no background yet, ensure there is a transparent
62 BackgroundColor = new Color(0.0f, 0.0f, 0.0f, 0.0f);
63 background = Background;
65 return AnimateColor("background", destinationValue, startTime, endTime, alphaFunction, initialValue);
69 /// Creates an animation to animate the mixColor of the named visual.
71 /// <since_tizen> 3 </since_tizen>
72 public Animation AnimateColor(string targetVisual, object destinationColor, int startTime, int endTime, AlphaFunction.BuiltinFunctions? alphaFunction = null, object initialColor = null)
74 Animation animation = null;
76 PropertyMap _animator = new PropertyMap();
77 if (alphaFunction != null)
79 _animator.Add("alphaFunction", new PropertyValue(AlphaFunction.BuiltinToPropertyKey(alphaFunction)));
82 PropertyMap _timePeriod = new PropertyMap();
83 _timePeriod.Add("duration", new PropertyValue((endTime - startTime) / 1000.0f));
84 _timePeriod.Add("delay", new PropertyValue(startTime / 1000.0f));
85 _animator.Add("timePeriod", new PropertyValue(_timePeriod));
87 PropertyMap _transition = new PropertyMap();
88 _transition.Add("animator", new PropertyValue(_animator));
89 _transition.Add("target", new PropertyValue(targetVisual));
90 _transition.Add("property", new PropertyValue("mixColor"));
92 if (initialColor != null)
94 PropertyValue initValue = PropertyValue.CreateFromObject(initialColor);
95 _transition.Add("initialValue", initValue);
98 PropertyValue destValue = PropertyValue.CreateFromObject(destinationColor);
99 _transition.Add("targetValue", destValue);
100 TransitionData _transitionData = new TransitionData(_transition);
102 animation = new Animation(Interop.View.View_CreateTransition(swigCPtr, TransitionData.getCPtr(_transitionData)), true);
103 if (NDalicPINVOKE.SWIGPendingException.Pending)
104 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
109 // From Container Base class
111 /// Adds a child view to this view.
113 /// <seealso cref="Container.Add" />
114 /// <since_tizen> 4 </since_tizen>
115 public override void Add(View child)
117 bool hasLayout = (_layout != null);
121 Tizen.Log.Fatal("NUI", "Child is null");
125 Container oldParent = child.GetParent();
126 if (oldParent != this)
128 // If child already has a parent then re-parent child
129 if (oldParent != null)
131 oldParent.Remove(child);
133 child.InternalParent = this;
135 Interop.Actor.Actor_Add(swigCPtr, View.getCPtr(child));
137 if (NDalicPINVOKE.SWIGPendingException.Pending)
138 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
141 if (ChildAdded != null)
143 ChildAddedEventArgs e = new ChildAddedEventArgs
149 BindableObject.SetInheritedBindingContext(child, this?.BindingContext);
154 /// Removes a child view from this View. If the view was not a child of this view, this is a no-op.
156 /// <seealso cref="Container.Remove" />
157 /// <since_tizen> 4 </since_tizen>
158 public override void Remove(View child)
160 if (!child || child.GetParent() == null) // Early out if child null.
163 bool hasLayout = (_layout != null);
165 // If View has a layout then do a deferred child removal
166 // Actual child removal is performed by the layouting system so
167 // transitions can be completed.
170 (_layout as LayoutGroup)?.RemoveChildFromLayoutGroup(child);
179 /// Retrieves a child view by index.
181 /// <seealso cref="Container.GetChildAt" />
182 /// <since_tizen> 4 </since_tizen>
183 public override View GetChildAt(uint index)
185 if (index < Children.Count)
187 return Children[Convert.ToInt32(index)];
196 /// Retrieves the number of children held by the view.
198 /// <seealso cref="Container.GetChildCount" />
199 /// <since_tizen> 4 </since_tizen>
200 public override uint GetChildCount()
202 return Convert.ToUInt32(Children.Count);
206 /// Gets the views parent.
208 /// <seealso cref="Container.GetParent()" />
209 /// <since_tizen> 4 </since_tizen>
210 public override Container GetParent()
212 return this.InternalParent as Container;
216 /// Queries whether the view has a focus.
218 /// <returns>True if this view has a focus.</returns>
219 /// <since_tizen> 3 </since_tizen>
220 public bool HasFocus()
223 if (swigCPtr.Handle != global::System.IntPtr.Zero)
225 ret = Interop.View.View_HasKeyInputFocus(swigCPtr);
226 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
230 Tizen.Log.Error("NUI", "swigCPtr of view is aleady disposed.");
236 /// Sets the name of the style to be applied to the view.
238 /// <param name="styleName">A string matching a style described in a stylesheet.</param>
239 /// <since_tizen> 3 </since_tizen>
240 public void SetStyleName(string styleName)
242 Interop.View.View_SetStyleName(swigCPtr, styleName);
243 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
247 /// Retrieves the name of the style to be applied to the view (if any).
249 /// <returns>A string matching a style, or an empty string.</returns>
250 /// <since_tizen> 3 </since_tizen>
251 public string GetStyleName()
253 string ret = Interop.View.View_GetStyleName(swigCPtr);
254 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
259 /// Clears the background.
261 /// <since_tizen> 3 </since_tizen>
262 public void ClearBackground()
264 Interop.View.View_ClearBackground(swigCPtr);
265 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
272 /// This is an asynchronous method.
274 /// <since_tizen> 3 </since_tizen>
284 /// This is an asynchronous method.
285 /// If the view is hidden, then the view and its children will not be rendered.
286 /// 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.
288 /// <since_tizen> 3 </since_tizen>
295 /// Raises the view above all other views.
298 /// Sibling order of views within the parent will be updated automatically.
299 /// Once a raise or lower API is used, that view will then have an exclusive sibling order independent of insertion.
301 /// <since_tizen> 3 </since_tizen>
302 public void RaiseToTop()
304 var parentChildren = GetParent()?.Children;
306 if (parentChildren != null)
308 parentChildren.Remove(this);
309 parentChildren.Add(this);
311 Interop.NDalic.RaiseToTop(swigCPtr);
312 if (NDalicPINVOKE.SWIGPendingException.Pending)
313 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
319 /// Lowers the view to the bottom of all views.
322 /// The sibling order of views within the parent will be updated automatically.
323 /// Once a raise or lower API is used that view will then have an exclusive sibling order independent of insertion.
325 /// <since_tizen> 3 </since_tizen>
326 public void LowerToBottom()
328 var parentChildren = GetParent()?.Children;
330 if (parentChildren != null)
332 parentChildren.Remove(this);
333 parentChildren.Insert(0, this);
335 Interop.NDalic.LowerToBottom(swigCPtr);
336 if (NDalicPINVOKE.SWIGPendingException.Pending)
337 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
342 /// Queries if all resources required by a view are loaded and ready.
344 /// <remarks>Most resources are only loaded when the control is placed on the stage.
346 /// <since_tizen> 3 </since_tizen>
347 public bool IsResourceReady()
349 bool ret = Interop.View.IsResourceReady(swigCPtr);
350 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
355 /// Gets the parent layer of this view.If a view has no parent, this method does not do anything.
357 /// <pre>The view has been initialized. </pre>
358 /// <returns>The parent layer of view </returns>
359 /// <since_tizen> 5 </since_tizen>
360 public Layer GetLayer()
362 //to fix memory leak issue, match the handle count with native side.
363 IntPtr cPtr = Interop.Actor.Actor_GetLayer(swigCPtr);
364 Layer ret = this.GetInstanceSafely<Layer>(cPtr);
365 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
370 /// Removes a view from its parent view or layer. If a view has no parent, this method does nothing.
372 /// <pre>The (child) view has been initialized. </pre>
373 /// <since_tizen> 4 </since_tizen>
374 public void Unparent()
376 GetParent()?.Remove(this);
380 /// Search through this view's hierarchy for a view with the given name.
381 /// The view itself is also considered in the search.
383 /// <pre>The view has been initialized.</pre>
384 /// <param name="viewName">The name of the view to find.</param>
385 /// <returns>A handle to the view if found, or an empty handle if not.</returns>
386 /// <since_tizen> 3 </since_tizen>
387 public View FindChildByName(string viewName)
389 //to fix memory leak issue, match the handle count with native side.
390 IntPtr cPtr = Interop.Actor.Actor_FindChildByName(swigCPtr, viewName);
391 View ret = this.GetInstanceSafely<View>(cPtr);
392 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
397 /// Converts screen coordinates into the view's coordinate system using the default camera.
399 /// <pre>The view has been initialized.</pre>
400 /// <remarks>The view coordinates are relative to the top-left(0.0, 0.0, 0.5).</remarks>
401 /// <param name="localX">On return, the X-coordinate relative to the view.</param>
402 /// <param name="localY">On return, the Y-coordinate relative to the view.</param>
403 /// <param name="screenX">The screen X-coordinate.</param>
404 /// <param name="screenY">The screen Y-coordinate.</param>
405 /// <returns>True if the conversion succeeded.</returns>
406 /// <since_tizen> 3 </since_tizen>
407 public bool ScreenToLocal(out float localX, out float localY, float screenX, float screenY)
409 bool ret = Interop.Actor.Actor_ScreenToLocal(swigCPtr, out localX, out localY, screenX, screenY);
410 if (NDalicPINVOKE.SWIGPendingException.Pending)
411 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
416 /// Sets the relative to parent size factor of the view.<br />
417 /// This factor is only used when ResizePolicy is set to either:
418 /// ResizePolicy::SIZE_RELATIVE_TO_PARENT or ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT.<br />
419 /// This view's size is set to the view's size multiplied by or added to this factor, depending on ResizePolicy.<br />
421 /// <pre>The view has been initialized.</pre>
422 /// <param name="factor">A Vector3 representing the relative factor to be applied to each axis.</param>
423 /// <since_tizen> 3 </since_tizen>
424 public void SetSizeModeFactor(Vector3 factor)
426 Interop.Actor.Actor_SetSizeModeFactor(swigCPtr, Vector3.getCPtr(factor));
427 if (NDalicPINVOKE.SWIGPendingException.Pending)
428 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
431 /// Calculates the height of the view given a width.<br />
432 /// The natural size is used for default calculation.<br />
433 /// Size 0 is treated as aspect ratio 1:1.<br />
435 /// <param name="width">The width to use.</param>
436 /// <returns>The height based on the width.</returns>
437 /// <since_tizen> 3 </since_tizen>
438 public float GetHeightForWidth(float width)
440 float ret = Interop.Actor.Actor_GetHeightForWidth(swigCPtr, width);
441 if (NDalicPINVOKE.SWIGPendingException.Pending)
442 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
447 /// Calculates the width of the view given a height.<br />
448 /// The natural size is used for default calculation.<br />
449 /// Size 0 is treated as aspect ratio 1:1.<br />
451 /// <param name="height">The height to use.</param>
452 /// <returns>The width based on the height.</returns>
453 /// <since_tizen> 3 </since_tizen>
454 public float GetWidthForHeight(float height)
456 float ret = Interop.Actor.Actor_GetWidthForHeight(swigCPtr, height);
457 if (NDalicPINVOKE.SWIGPendingException.Pending)
458 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
463 /// Return the amount of size allocated for relayout.
465 /// <param name="dimension">The dimension to retrieve.</param>
466 /// <returns>Return the size.</returns>
467 /// <since_tizen> 3 </since_tizen>
468 public float GetRelayoutSize(DimensionType dimension)
470 float ret = Interop.Actor.Actor_GetRelayoutSize(swigCPtr, (int)dimension);
471 if (NDalicPINVOKE.SWIGPendingException.Pending)
472 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
477 /// Set the padding for the view.
479 /// <param name="padding">Padding for the view.</param>
480 /// <since_tizen> 3 </since_tizen>
481 public void SetPadding(PaddingType padding)
483 Interop.Actor.Actor_SetPadding(swigCPtr, PaddingType.getCPtr(padding));
484 if (NDalicPINVOKE.SWIGPendingException.Pending)
485 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
489 /// Return the value of padding for the view.
491 /// <param name="paddingOut">the value of padding for the view</param>
492 /// <since_tizen> 3 </since_tizen>
493 public void GetPadding(PaddingType paddingOut)
495 Interop.Actor.Actor_GetPadding(swigCPtr, PaddingType.getCPtr(paddingOut));
496 if (NDalicPINVOKE.SWIGPendingException.Pending)
497 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
500 /// <since_tizen> 3 </since_tizen>
501 public uint AddRenderer(Renderer renderer)
503 uint ret = Interop.Actor.Actor_AddRenderer(swigCPtr, Renderer.getCPtr(renderer));
504 if (NDalicPINVOKE.SWIGPendingException.Pending)
505 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
509 /// <since_tizen> 3 </since_tizen>
510 public Renderer GetRendererAt(uint index)
512 //to fix memory leak issue, match the handle count with native side.
513 IntPtr cPtr = Interop.Actor.Actor_GetRendererAt(swigCPtr, index);
514 HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
515 Renderer ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as Renderer;
516 if (cPtr != null && ret == null)
518 ret = new Renderer(cPtr, false);
519 if (NDalicPINVOKE.SWIGPendingException.Pending)
520 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
523 Interop.BaseHandle.delete_BaseHandle(CPtr);
524 CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
526 if (NDalicPINVOKE.SWIGPendingException.Pending)
527 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
531 /// <since_tizen> 3 </since_tizen>
532 public void RemoveRenderer(Renderer renderer)
534 Interop.Actor.Actor_RemoveRenderer__SWIG_0(swigCPtr, Renderer.getCPtr(renderer));
535 if (NDalicPINVOKE.SWIGPendingException.Pending)
536 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
539 /// <since_tizen> 3 </since_tizen>
540 public void RemoveRenderer(uint index)
542 Interop.Actor.Actor_RemoveRenderer__SWIG_1(swigCPtr, index);
543 if (NDalicPINVOKE.SWIGPendingException.Pending)
544 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
547 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
548 [EditorBrowsable(EditorBrowsableState.Never)]
549 public void RotateBy(Degree angle, Vector3 axis)
551 Interop.ActorInternal.Actor_RotateBy__SWIG_0(swigCPtr, Degree.getCPtr(angle), Vector3.getCPtr(axis));
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(Radian angle, Vector3 axis)
560 Interop.ActorInternal.Actor_RotateBy__SWIG_1(swigCPtr, Radian.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(Rotation relativeRotation)
569 Interop.ActorInternal.Actor_RotateBy__SWIG_2(swigCPtr, Rotation.getCPtr(relativeRotation));
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 ScaleBy(Vector3 relativeScale)
578 Interop.ActorInternal.Actor_ScaleBy(swigCPtr, Vector3.getCPtr(relativeScale));
579 if (NDalicPINVOKE.SWIGPendingException.Pending)
580 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
583 /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
584 [EditorBrowsable(EditorBrowsableState.Never)]
585 public void SetColorMode(ColorMode colorMode)
587 Interop.ActorInternal.Actor_SetColorMode(swigCPtr, (int)colorMode);
588 if (NDalicPINVOKE.SWIGPendingException.Pending)
589 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
594 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
595 [EditorBrowsable(EditorBrowsableState.Never)]
596 public Transition GetTransition(string transitionName)
598 Transition trans = null;
599 transDictionary.TryGetValue(transitionName, out trans);