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.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 if (child.Layout !=null)
133 child.Layout.SetReplaceFlag();
135 oldParent.Remove(child);
137 child.InternalParent = this;
139 Interop.Actor.Actor_Add(swigCPtr, View.getCPtr(child));
141 if (NDalicPINVOKE.SWIGPendingException.Pending)
142 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
145 if (ChildAdded != null)
147 ChildAddedEventArgs e = new ChildAddedEventArgs
153 BindableObject.SetInheritedBindingContext(child, this?.BindingContext);
158 /// Removes a child view from this View. If the view was not a child of this view, this is a no-op.
160 /// <seealso cref="Container.Remove" />
161 /// <since_tizen> 4 </since_tizen>
162 public override void Remove(View child)
164 if (!child || child.GetParent() == null) // Early out if child null.
167 bool hasLayout = (_layout != null);
169 // If View has a layout then do a deferred child removal
170 // Actual child removal is performed by the layouting system so
171 // transitions can be completed.
174 (_layout as LayoutGroup)?.RemoveChildFromLayoutGroup(child);
183 /// Retrieves a child view by index.
185 /// <seealso cref="Container.GetChildAt" />
186 /// <since_tizen> 4 </since_tizen>
187 public override View GetChildAt(uint index)
189 if (index < Children.Count)
191 return Children[Convert.ToInt32(index)];
200 /// Retrieves the number of children held by the view.
202 /// <seealso cref="Container.GetChildCount" />
203 /// <since_tizen> 4 </since_tizen>
204 public override uint GetChildCount()
206 return Convert.ToUInt32(Children.Count);
210 /// Gets the views parent.
212 /// <seealso cref="Container.GetParent()" />
213 /// <since_tizen> 4 </since_tizen>
214 public override Container GetParent()
216 return this.InternalParent as Container;
220 /// Queries whether the view has a focus.
222 /// <returns>True if this view has a focus.</returns>
223 /// <since_tizen> 3 </since_tizen>
224 public bool HasFocus()
227 if (swigCPtr.Handle != global::System.IntPtr.Zero)
229 ret = Interop.View.View_HasKeyInputFocus(swigCPtr);
230 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
234 Tizen.Log.Error("NUI", "swigCPtr of view is aleady disposed.");
240 /// Sets the name of the style to be applied to the view.
242 /// <param name="styleName">A string matching a style described in a stylesheet.</param>
243 /// <since_tizen> 3 </since_tizen>
244 public void SetStyleName(string styleName)
246 Interop.View.View_SetStyleName(swigCPtr, styleName);
247 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
251 /// Retrieves the name of the style to be applied to the view (if any).
253 /// <returns>A string matching a style, or an empty string.</returns>
254 /// <since_tizen> 3 </since_tizen>
255 public string GetStyleName()
257 string ret = Interop.View.View_GetStyleName(swigCPtr);
258 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
263 /// Clears the background.
265 /// <since_tizen> 3 </since_tizen>
266 public void ClearBackground()
268 Interop.View.View_ClearBackground(swigCPtr);
269 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
276 /// This is an asynchronous method.
278 /// <since_tizen> 3 </since_tizen>
288 /// This is an asynchronous method.
289 /// If the view is hidden, then the view and its children will not be rendered.
290 /// 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.
292 /// <since_tizen> 3 </since_tizen>
299 /// Raises the view above all other views.
302 /// Sibling order of views within the parent will be updated automatically.
303 /// Once a raise or lower API is used, that view will then have an exclusive sibling order independent of insertion.
305 /// <since_tizen> 3 </since_tizen>
306 public void RaiseToTop()
308 var parentChildren = GetParent()?.Children;
310 if (parentChildren != null)
312 parentChildren.Remove(this);
313 parentChildren.Add(this);
315 Interop.NDalic.RaiseToTop(swigCPtr);
316 if (NDalicPINVOKE.SWIGPendingException.Pending)
317 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
323 /// Lowers the view to the bottom of all views.
326 /// The sibling order of views within the parent will be updated automatically.
327 /// Once a raise or lower API is used that view will then have an exclusive sibling order independent of insertion.
329 /// <since_tizen> 3 </since_tizen>
330 public void LowerToBottom()
332 var parentChildren = GetParent()?.Children;
334 if (parentChildren != null)
336 parentChildren.Remove(this);
337 parentChildren.Insert(0, this);
339 Interop.NDalic.LowerToBottom(swigCPtr);
340 if (NDalicPINVOKE.SWIGPendingException.Pending)
341 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
346 /// Queries if all resources required by a view are loaded and ready.
348 /// <remarks>Most resources are only loaded when the control is placed on the stage.
350 /// <since_tizen> 3 </since_tizen>
351 public bool IsResourceReady()
353 bool ret = Interop.View.IsResourceReady(swigCPtr);
354 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
359 /// Gets the parent layer of this view.If a view has no parent, this method does not do anything.
361 /// <pre>The view has been initialized. </pre>
362 /// <returns>The parent layer of view </returns>
363 /// <since_tizen> 5 </since_tizen>
364 public Layer GetLayer()
366 //to fix memory leak issue, match the handle count with native side.
367 IntPtr cPtr = Interop.Actor.Actor_GetLayer(swigCPtr);
368 Layer ret = this.GetInstanceSafely<Layer>(cPtr);
369 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
374 /// Removes a view from its parent view or layer. If a view has no parent, this method does nothing.
376 /// <pre>The (child) view has been initialized. </pre>
377 /// <since_tizen> 4 </since_tizen>
378 public void Unparent()
380 GetParent()?.Remove(this);
384 /// Search through this view's hierarchy for a view with the given name.
385 /// The view itself is also considered in the search.
387 /// <pre>The view has been initialized.</pre>
388 /// <param name="viewName">The name of the view to find.</param>
389 /// <returns>A handle to the view if found, or an empty handle if not.</returns>
390 /// <since_tizen> 3 </since_tizen>
391 public View FindChildByName(string viewName)
393 //to fix memory leak issue, match the handle count with native side.
394 IntPtr cPtr = Interop.Actor.Actor_FindChildByName(swigCPtr, viewName);
395 View ret = this.GetInstanceSafely<View>(cPtr);
396 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
401 /// Converts screen coordinates into the view's coordinate system using the default camera.
403 /// <pre>The view has been initialized.</pre>
404 /// <remarks>The view coordinates are relative to the top-left(0.0, 0.0, 0.5).</remarks>
405 /// <param name="localX">On return, the X-coordinate relative to the view.</param>
406 /// <param name="localY">On return, the Y-coordinate relative to the view.</param>
407 /// <param name="screenX">The screen X-coordinate.</param>
408 /// <param name="screenY">The screen Y-coordinate.</param>
409 /// <returns>True if the conversion succeeded.</returns>
410 /// <since_tizen> 3 </since_tizen>
411 public bool ScreenToLocal(out float localX, out float localY, float screenX, float screenY)
413 bool ret = Interop.Actor.Actor_ScreenToLocal(swigCPtr, out localX, out localY, screenX, screenY);
414 if (NDalicPINVOKE.SWIGPendingException.Pending)
415 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
420 /// Sets the relative to parent size factor of the view.<br />
421 /// This factor is only used when ResizePolicy is set to either:
422 /// ResizePolicy::SIZE_RELATIVE_TO_PARENT or ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT.<br />
423 /// This view's size is set to the view's size multiplied by or added to this factor, depending on ResizePolicy.<br />
425 /// <pre>The view has been initialized.</pre>
426 /// <param name="factor">A Vector3 representing the relative factor to be applied to each axis.</param>
427 /// <since_tizen> 3 </since_tizen>
428 public void SetSizeModeFactor(Vector3 factor)
430 Interop.Actor.Actor_SetSizeModeFactor(swigCPtr, Vector3.getCPtr(factor));
431 if (NDalicPINVOKE.SWIGPendingException.Pending)
432 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
435 /// Calculates the height of the view given a width.<br />
436 /// The natural size is used for default calculation.<br />
437 /// Size 0 is treated as aspect ratio 1:1.<br />
439 /// <param name="width">The width to use.</param>
440 /// <returns>The height based on the width.</returns>
441 /// <since_tizen> 3 </since_tizen>
442 public float GetHeightForWidth(float width)
444 float ret = Interop.Actor.Actor_GetHeightForWidth(swigCPtr, width);
445 if (NDalicPINVOKE.SWIGPendingException.Pending)
446 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
451 /// Calculates the width of the view given a height.<br />
452 /// The natural size is used for default calculation.<br />
453 /// Size 0 is treated as aspect ratio 1:1.<br />
455 /// <param name="height">The height to use.</param>
456 /// <returns>The width based on the height.</returns>
457 /// <since_tizen> 3 </since_tizen>
458 public float GetWidthForHeight(float height)
460 float ret = Interop.Actor.Actor_GetWidthForHeight(swigCPtr, height);
461 if (NDalicPINVOKE.SWIGPendingException.Pending)
462 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
467 /// Return the amount of size allocated for relayout.
469 /// <param name="dimension">The dimension to retrieve.</param>
470 /// <returns>Return the size.</returns>
471 /// <since_tizen> 3 </since_tizen>
472 public float GetRelayoutSize(DimensionType dimension)
474 float ret = Interop.Actor.Actor_GetRelayoutSize(swigCPtr, (int)dimension);
475 if (NDalicPINVOKE.SWIGPendingException.Pending)
476 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
481 /// Set the padding for the view.
483 /// <param name="padding">Padding for the view.</param>
484 /// <since_tizen> 3 </since_tizen>
485 public void SetPadding(PaddingType padding)
487 Interop.Actor.Actor_SetPadding(swigCPtr, PaddingType.getCPtr(padding));
488 if (NDalicPINVOKE.SWIGPendingException.Pending)
489 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
493 /// Return the value of padding for the view.
495 /// <param name="paddingOut">the value of padding for the view</param>
496 /// <since_tizen> 3 </since_tizen>
497 public void GetPadding(PaddingType paddingOut)
499 Interop.Actor.Actor_GetPadding(swigCPtr, PaddingType.getCPtr(paddingOut));
500 if (NDalicPINVOKE.SWIGPendingException.Pending)
501 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
504 /// <since_tizen> 3 </since_tizen>
505 public uint AddRenderer(Renderer renderer)
507 uint ret = Interop.Actor.Actor_AddRenderer(swigCPtr, Renderer.getCPtr(renderer));
508 if (NDalicPINVOKE.SWIGPendingException.Pending)
509 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
513 /// <since_tizen> 3 </since_tizen>
514 public Renderer GetRendererAt(uint index)
516 //to fix memory leak issue, match the handle count with native side.
517 IntPtr cPtr = Interop.Actor.Actor_GetRendererAt(swigCPtr, index);
518 HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
519 Renderer ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as Renderer;
520 if (cPtr != null && ret == null)
522 ret = new Renderer(cPtr, false);
523 if (NDalicPINVOKE.SWIGPendingException.Pending)
524 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
527 Interop.BaseHandle.delete_BaseHandle(CPtr);
528 CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
530 if (NDalicPINVOKE.SWIGPendingException.Pending)
531 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
535 /// <since_tizen> 3 </since_tizen>
536 public void RemoveRenderer(Renderer renderer)
538 Interop.Actor.Actor_RemoveRenderer__SWIG_0(swigCPtr, Renderer.getCPtr(renderer));
539 if (NDalicPINVOKE.SWIGPendingException.Pending)
540 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
543 /// <since_tizen> 3 </since_tizen>
544 public void RemoveRenderer(uint index)
546 Interop.Actor.Actor_RemoveRenderer__SWIG_1(swigCPtr, index);
547 if (NDalicPINVOKE.SWIGPendingException.Pending)
548 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
551 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
552 [EditorBrowsable(EditorBrowsableState.Never)]
553 public void RotateBy(Degree angle, Vector3 axis)
555 Interop.ActorInternal.Actor_RotateBy__SWIG_0(swigCPtr, Degree.getCPtr(angle), Vector3.getCPtr(axis));
556 if (NDalicPINVOKE.SWIGPendingException.Pending)
557 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
560 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
561 [EditorBrowsable(EditorBrowsableState.Never)]
562 public void RotateBy(Radian angle, Vector3 axis)
564 Interop.ActorInternal.Actor_RotateBy__SWIG_1(swigCPtr, Radian.getCPtr(angle), Vector3.getCPtr(axis));
565 if (NDalicPINVOKE.SWIGPendingException.Pending)
566 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
569 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
570 [EditorBrowsable(EditorBrowsableState.Never)]
571 public void RotateBy(Rotation relativeRotation)
573 Interop.ActorInternal.Actor_RotateBy__SWIG_2(swigCPtr, Rotation.getCPtr(relativeRotation));
574 if (NDalicPINVOKE.SWIGPendingException.Pending)
575 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
578 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
579 [EditorBrowsable(EditorBrowsableState.Never)]
580 public void ScaleBy(Vector3 relativeScale)
582 Interop.ActorInternal.Actor_ScaleBy(swigCPtr, Vector3.getCPtr(relativeScale));
583 if (NDalicPINVOKE.SWIGPendingException.Pending)
584 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
587 /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
588 [EditorBrowsable(EditorBrowsableState.Never)]
589 public void SetColorMode(ColorMode colorMode)
591 Interop.ActorInternal.Actor_SetColorMode(swigCPtr, (int)colorMode);
592 if (NDalicPINVOKE.SWIGPendingException.Pending)
593 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
598 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
599 [EditorBrowsable(EditorBrowsableState.Never)]
600 public Transition GetTransition(string transitionName)
602 Transition trans = null;
603 transDictionary.TryGetValue(transitionName, out trans);