/* * Copyright(c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ using System; using System.ComponentModel; using System.Reflection; using System.Runtime.InteropServices; using Tizen.NUI.Binding; namespace Tizen.NUI.BaseComponents { /// /// View is the base class for all views. /// /// 3 public partial class View { /// /// Perform an action on a visual registered to this view.
/// Visuals will have actions. This API is used to perform one of these actions with the given attributes. ///
/// The Property index of the visual. /// The action to perform. See Visual to find the supported actions. /// Optional attributes for the action. /// 5 public void DoAction(int propertyIndexOfVisual, int propertyIndexOfActionId, PropertyValue attributes) { Interop.View.DoAction(SwigCPtr, propertyIndexOfVisual, propertyIndexOfActionId, PropertyValue.getCPtr(attributes)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// /// Creates an animation to animate the background color visual. If there is no /// background visual, creates one with transparent black as it's mixColor. /// /// 3 public Animation AnimateBackgroundColor(object destinationValue, int startTime, int endTime, AlphaFunction.BuiltinFunctions? alphaFunction = null, object initialValue = null) { Tizen.NUI.PropertyMap background = Background; if (background.Empty()) { // If there is no background yet, ensure there is a transparent // color visual BackgroundColor = new Color(0.0f, 0.0f, 0.0f, 0.0f); background = Background; } return AnimateColor("background", destinationValue, startTime, endTime, alphaFunction, initialValue); } /// /// Creates an animation to animate the mixColor of the named visual. /// /// 3 public Animation AnimateColor(string targetVisual, object destinationColor, int startTime, int endTime, AlphaFunction.BuiltinFunctions? alphaFunction = null, object initialColor = null) { Animation animation = null; using (PropertyMap animator = new PropertyMap()) using (PropertyMap timePeriod = new PropertyMap()) using (PropertyValue pvDuration = new PropertyValue((endTime - startTime) / 1000.0f)) using (PropertyValue pvDelay = new PropertyValue(startTime / 1000.0f)) using (PropertyMap transition = new PropertyMap()) using (PropertyValue pvTarget = new PropertyValue(targetVisual)) using (PropertyValue pvProperty = new PropertyValue("mixColor")) using (PropertyValue destValue = PropertyValue.CreateFromObject(destinationColor)) { if (alphaFunction != null) { using (PropertyValue pvAlpha = new PropertyValue(AlphaFunction.BuiltinToPropertyKey(alphaFunction))) { animator.Add("alphaFunction", pvAlpha); } } timePeriod.Add("duration", pvDuration); timePeriod.Add("delay", pvDelay); using (PropertyValue pvTimePeriod = new PropertyValue(timePeriod)) { animator.Add("timePeriod", pvTimePeriod); } using (PropertyValue pvAnimator = new PropertyValue(animator)) { transition.Add("animator", pvAnimator); } transition.Add("target", pvTarget); transition.Add("property", pvProperty); if (initialColor != null) { using (PropertyValue initValue = PropertyValue.CreateFromObject(initialColor)) { transition.Add("initialValue", initValue); } } transition.Add("targetValue", destValue); using (TransitionData transitionData = new TransitionData(transition)) { animation = new Animation(Interop.View.CreateTransition(SwigCPtr, TransitionData.getCPtr(transitionData)), true); } if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } return animation; } // From Container Base class /// /// Adds a child view to this view. /// /// /// 4 public override void Add(View child) { bool hasLayout = (layout != null); if (null == child) { Tizen.Log.Fatal("NUI", "Child is null"); return; } Container oldParent = child.GetParent(); if (oldParent != this) { // If child already has a parent then re-parent child if (oldParent != null) { if (child.Layout != null) { child.Layout.SetReplaceFlag(); } oldParent.Remove(child); } child.InternalParent = this; LayoutCount += child.LayoutCount; Interop.Actor.Add(SwigCPtr, View.getCPtr(child)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); Children.Add(child); if (ChildAdded != null) { ChildAddedEventArgs e = new ChildAddedEventArgs { Added = child }; ChildAdded(this, e); } AddChildBindableObject(child); } } /// /// Removes a child view from this View. If the view was not a child of this view, this is a no-op. /// /// /// 4 /// Thrown when deleting a view that is not a child of this view public override void Remove(View child) { if (child == null || child.GetParent() == null) // Early out if child null. return; if (child.GetParent() != this) { //throw new System.InvalidOperationException("You have deleted a view that is not a child of this view."); Tizen.Log.Error("NUI", "You have deleted a view that is not a child of this view."); return; } bool hasLayout = (layout != null); // If View has a layout then do a deferred child removal // Actual child removal is performed by the layouting system so // transitions can be completed. if (hasLayout) { (layout as LayoutGroup)?.RemoveChildFromLayoutGroup(child); } RemoveChild(child); } /// /// Retrieves a child view by index. /// /// /// 4 public override View GetChildAt(uint index) { if (index < Children.Count) { return Children[Convert.ToInt32(index)]; } else { return null; } } /// /// Retrieves the number of children held by the view. /// /// /// 4 [Obsolete("Deprecated in API9, will be removed in API11. Please use ChildCount property instead!")] public override uint GetChildCount() { return Convert.ToUInt32(Children.Count); } /// /// Gets the views parent. /// /// /// 4 public override Container GetParent() { return InternalParent as Container; } /// /// Queries whether the view has a focus. /// /// True if this view has a focus. /// 3 public bool HasFocus() { bool ret = false; if (SwigCPtr.Handle != global::System.IntPtr.Zero) { ret = Interop.View.HasKeyInputFocus(SwigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } else { Tizen.Log.Error("NUI", "swigCPtr of view is already disposed."); } return ret; } /// /// Sets the name of the style to be applied to the view. /// /// A string matching a style described in a stylesheet. /// 3 [Obsolete("Deprecated in API9, will be removed in API11. Please use StyleName property instead!")] public void SetStyleName(string styleName) { Interop.View.SetStyleName(SwigCPtr, styleName); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// /// Retrieves the name of the style to be applied to the view (if any). /// /// A string matching a style, or an empty string. /// 3 [Obsolete("Deprecated in API9, will be removed in API11. Please use StyleName property instead!")] public string GetStyleName() { string ret = Interop.View.GetStyleName(SwigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Clears the background. /// /// 3 public void ClearBackground() { Interop.View.ClearBackground(SwigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// /// Shows the view. /// /// /// This is an asynchronous method. /// /// 3 public void Show() { SetVisible(true); if (GetAccessibilityStates()[AccessibilityState.Modal]) { RegisterDefaultLabel(); if (Accessibility.Accessibility.IsEnabled) { EmitAccessibilityStateChangedEvent(AccessibilityState.Showing, true); } } } /// /// Hides the view. /// /// /// This is an asynchronous method. /// If the view is hidden, then the view and its children will not be rendered. /// 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. /// /// 3 public void Hide() { SetVisible(false); if (GetAccessibilityStates()[AccessibilityState.Modal]) { UnregisterDefaultLabel(); if (Accessibility.Accessibility.IsEnabled) { EmitAccessibilityStateChangedEvent(AccessibilityState.Showing, false); } } } /// /// Raises the view above all other views. /// /// /// Sibling order of views within the parent will be updated automatically. /// Once a raise or lower API is used, that view will then have an exclusive sibling order independent of insertion. /// /// 3 public void RaiseToTop() { var parentChildren = GetParent()?.Children; if (parentChildren != null) { parentChildren.Remove(this); parentChildren.Add(this); LayoutGroup layout = Layout as LayoutGroup; layout?.ChangeLayoutSiblingOrder(parentChildren.Count - 1); Interop.NDalic.RaiseToTop(SwigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } } /// /// Lowers the view to the bottom of all views. /// /// /// The sibling order of views within the parent will be updated automatically. /// Once a raise or lower API is used that view will then have an exclusive sibling order independent of insertion. /// /// 3 public void LowerToBottom() { var parentChildren = GetParent()?.Children; if (parentChildren != null) { parentChildren.Remove(this); parentChildren.Insert(0, this); LayoutGroup layout = Layout as LayoutGroup; layout?.ChangeLayoutSiblingOrder(0); Interop.NDalic.LowerToBottom(SwigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } } /// /// Queries if all resources required by a view are loaded and ready. /// /// Most resources are only loaded when the control is placed on the stage. /// /// 3 public bool IsResourceReady() { bool ret = Interop.View.IsResourceReady(SwigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Gets the parent layer of this view.If a view has no parent, this method does not do anything. /// ///
The view has been initialized. 
/// The parent layer of view /// 5 public Layer GetLayer() { //to fix memory leak issue, match the handle count with native side. IntPtr cPtr = Interop.Actor.GetLayer(SwigCPtr); Layer ret = this.GetInstanceSafely(cPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Removes a view from its parent view or layer. If a view has no parent, this method does nothing. /// ///
The (child) view has been initialized. 
/// 4 public void Unparent() { GetParent()?.Remove(this); } /// /// Search through this view's hierarchy for a view with the given name. /// The view itself is also considered in the search. /// ///
The view has been initialized.
/// The name of the view to find. /// A handle to the view if found, or an empty handle if not. /// 3 public View FindChildByName(string viewName) { //to fix memory leak issue, match the handle count with native side. IntPtr cPtr = Interop.Actor.FindChildByName(SwigCPtr, viewName); View ret = this.GetInstanceSafely(cPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Converts screen coordinates into the view's coordinate system using the default camera. /// ///
The view has been initialized.
/// The view coordinates are relative to the top-left(0.0, 0.0, 0.5). /// On return, the X-coordinate relative to the view. /// On return, the Y-coordinate relative to the view. /// The screen X-coordinate. /// The screen Y-coordinate. /// True if the conversion succeeded. /// 3 public bool ScreenToLocal(out float localX, out float localY, float screenX, float screenY) { bool ret = Interop.Actor.ScreenToLocal(SwigCPtr, out localX, out localY, screenX, screenY); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Sets the relative to parent size factor of the view.
/// This factor is only used when ResizePolicy is set to either: /// ResizePolicy::SIZE_RELATIVE_TO_PARENT or ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT.
/// This view's size is set to the view's size multiplied by or added to this factor, depending on ResizePolicy.
///
///
The view has been initialized.
/// A Vector3 representing the relative factor to be applied to each axis. /// 3 public void SetSizeModeFactor(Vector3 factor) { Interop.Actor.SetSizeModeFactor(SwigCPtr, Vector3.getCPtr(factor)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// /// Calculates the height of the view given a width.
/// The natural size is used for default calculation.
/// Size 0 is treated as aspect ratio 1:1.
///
/// The width to use. /// The height based on the width. /// 3 public float GetHeightForWidth(float width) { float ret = Interop.Actor.GetHeightForWidth(SwigCPtr, width); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Calculates the width of the view given a height.
/// The natural size is used for default calculation.
/// Size 0 is treated as aspect ratio 1:1.
///
/// The height to use. /// The width based on the height. /// 3 public float GetWidthForHeight(float height) { float ret = Interop.Actor.GetWidthForHeight(SwigCPtr, height); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Return the amount of size allocated for relayout. /// /// The dimension to retrieve. /// Return the size. /// 3 public float GetRelayoutSize(DimensionType dimension) { float ret = Interop.Actor.GetRelayoutSize(SwigCPtr, (int)dimension); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Set the padding for the view. /// /// Padding for the view. /// 3 // [Obsolete("Deprecated in API9, will be removed in API11. Please use Padding property instead!")] public void SetPadding(PaddingType padding) { Interop.Actor.SetPadding(SwigCPtr, PaddingType.getCPtr(padding)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// /// Return the value of padding for the view. /// /// the value of padding for the view /// 3 [Obsolete("Deprecated in API9, will be removed in API11. Please use Padding property instead!")] public void GetPadding(PaddingType paddingOut) { Interop.Actor.GetPadding(SwigCPtr, PaddingType.getCPtr(paddingOut)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// 3 public uint AddRenderer(Renderer renderer) { uint ret = Interop.Actor.AddRenderer(SwigCPtr, Renderer.getCPtr(renderer)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// 3 public Renderer GetRendererAt(uint index) { //to fix memory leak issue, match the handle count with native side. IntPtr cPtr = Interop.Actor.GetRendererAt(SwigCPtr, index); HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); Renderer ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as Renderer; if (cPtr != null && ret == null) { ret = new Renderer(cPtr, false); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } Interop.BaseHandle.DeleteBaseHandle(CPtr); CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// 3 public void RemoveRenderer(Renderer renderer) { Interop.Actor.RemoveRenderer(SwigCPtr, Renderer.getCPtr(renderer)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// 3 public void RemoveRenderer(uint index) { Interop.Actor.RemoveRenderer(SwigCPtr, index); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API. [EditorBrowsable(EditorBrowsableState.Never)] public void RotateBy(Degree angle, Vector3 axis) { Interop.ActorInternal.RotateByDegree(SwigCPtr, Degree.getCPtr(angle), Vector3.getCPtr(axis)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API. [EditorBrowsable(EditorBrowsableState.Never)] public void RotateBy(Radian angle, Vector3 axis) { Interop.ActorInternal.RotateByRadian(SwigCPtr, Radian.getCPtr(angle), Vector3.getCPtr(axis)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API. [EditorBrowsable(EditorBrowsableState.Never)] public void RotateBy(Rotation relativeRotation) { Interop.ActorInternal.RotateByQuaternion(SwigCPtr, Rotation.getCPtr(relativeRotation)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API. [EditorBrowsable(EditorBrowsableState.Never)] public void ScaleBy(Vector3 relativeScale) { Interop.ActorInternal.ScaleBy(SwigCPtr, Vector3.getCPtr(relativeScale)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API. [EditorBrowsable(EditorBrowsableState.Never)] public void SetColorMode(ColorMode colorMode) { Interop.ActorInternal.SetColorMode(SwigCPtr, (int)colorMode); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API. [EditorBrowsable(EditorBrowsableState.Never)] public void ObjectDump() { if (0 == Children.Count) { Type type = this.GetType(); PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (var property in properties) { if (null != property && property.CanRead) { Tizen.Log.Fatal("NUI", $"{type.Name} {property.Name} ({property.PropertyType.Name}): {property.GetValueString(this, property.PropertyType)}"); } } return; } foreach (View view in Children) { view.ObjectDump(); } } /// /// Search through this View's hierarchy for a View with the given unique ID. /// The View itself is also considered in the search. /// /// The ID of the View to find /// A View if found or a null if not [EditorBrowsable(EditorBrowsableState.Never)] [Obsolete("This will be removed at API11! please use FindDescendantByID(uint id) instead!")] public View FindChildByID(uint id) { IntPtr cPtr = Interop.Actor.FindChildById(SwigCPtr, id); View ret = this.GetInstanceSafely(cPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Search through this View's hierarchy for a View with the given unique ID. /// /// The ID of the View to find. /// A handle to the View if found, or an empty handle if not. /// 9 public View FindDescendantByID(uint id) { return FindChildById(id); } /// /// Raise view above the next sibling view. /// /// 9 public void Raise() { var parentChildren = GetParent()?.Children; if (parentChildren != null) { int currentIndex = parentChildren.IndexOf(this); // If the view is not already the last item in the list. if (currentIndex >= 0 && currentIndex < parentChildren.Count - 1) { View temp = parentChildren[currentIndex + 1]; parentChildren[currentIndex + 1] = this; parentChildren[currentIndex] = temp; Interop.NDalic.Raise(SwigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } } } /// /// Lower the view below the previous sibling view. /// /// 9 public void Lower() { var parentChildren = GetParent()?.Children; if (parentChildren != null) { int currentIndex = parentChildren.IndexOf(this); // If the view is not already the first item in the list. if (currentIndex > 0 && currentIndex < parentChildren.Count) { View temp = parentChildren[currentIndex - 1]; parentChildren[currentIndex - 1] = this; parentChildren[currentIndex] = temp; Interop.NDalic.Lower(SwigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } } } /// /// Raises the view to above the target view. /// /// The sibling order of views within the parent will be updated automatically. /// Views on the level above the target view will still be shown above this view. /// Once a raise or lower API is used then that view will have an exclusive sibling order independent of insertion. /// /// Will be raised above this view. /// 9 public void RaiseAbove(View target) { var parentChildren = GetParent()?.Children; if (parentChildren != null) { int currentIndex = parentChildren.IndexOf(this); int targetIndex = parentChildren.IndexOf(target); if (currentIndex < 0 || targetIndex < 0 || currentIndex >= parentChildren.Count || targetIndex >= parentChildren.Count) { NUILog.Error("index should be bigger than 0 and less than children of layer count"); return; } // If the currentIndex is less than the target index and the target has the same parent. if (currentIndex < targetIndex) { parentChildren.Remove(this); parentChildren.Insert(targetIndex, this); Interop.NDalic.RaiseAbove(SwigCPtr, View.getCPtr(target)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } } } /// /// Lowers the view to below the target view. /// /// The sibling order of views within the parent will be updated automatically. /// Once a raise or lower API is used then that view will have an exclusive sibling order independent of insertion. /// /// Will be lowered below this view. /// 9 public void LowerBelow(View target) { var parentChildren = GetParent()?.Children; if (parentChildren != null) { int currentIndex = parentChildren.IndexOf(this); int targetIndex = parentChildren.IndexOf(target); if (currentIndex < 0 || targetIndex < 0 || currentIndex >= parentChildren.Count || targetIndex >= parentChildren.Count) { NUILog.Error("index should be bigger than 0 and less than children of layer count"); return; } // If the currentIndex is not already the 0th index and the target has the same parent. if ((currentIndex != 0) && (targetIndex != -1) && (currentIndex > targetIndex)) { parentChildren.Remove(this); parentChildren.Insert(targetIndex, this); Interop.NDalic.LowerBelow(SwigCPtr, View.getCPtr(target)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } } } } }