[NUI] introduce CreateViewStyle that is alternative to GetViewStyle (#1681)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Components / Controls / Tab.cs
index b6e206c..d306d30 100755 (executable)
@@ -35,6 +35,7 @@ namespace Tizen.NUI.Components
         private Animation underlineAni = null;
         private bool isNeedAnimation = false;
         private Extents space;
+        static Tab() { }
 
         /// <summary>
         /// Creates a new instance of a Tab.
@@ -49,9 +50,7 @@ namespace Tizen.NUI.Components
         /// Creates a new instance of a Tab with style.
         /// </summary>
         /// <param name="style">Create Tab by special style defined in UX.</param>
-        /// <since_tizen> 6 </since_tizen>
-        /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
-        [EditorBrowsable(EditorBrowsableState.Never)]
+        /// <since_tizen> 8 </since_tizen>
         public Tab(string style) : base(style)
         {
             Initialize();
@@ -60,11 +59,9 @@ namespace Tizen.NUI.Components
         /// <summary>
         /// Creates a new instance of a Tab with style.
         /// </summary>
-        /// <param name="style">Create Tab by style customized by user.</param>
-        /// <since_tizen> 6 </since_tizen>
-        /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public Tab(TabStyle style) : base(style)
+        /// <param name="tabStyle">Create Tab by style customized by user.</param>
+        /// <since_tizen> 8 </since_tizen>
+        public Tab(TabStyle tabStyle) : base(tabStyle)
         {
             Initialize();
         }
@@ -75,10 +72,35 @@ namespace Tizen.NUI.Components
         /// <since_tizen> 6 </since_tizen>
         public event EventHandler<ItemChangedEventArgs> ItemChangedEvent;
 
-        /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
-        [EditorBrowsable(EditorBrowsableState.Never)]
+        /// <summary>
+        /// Get style of tab.
+        /// </summary>
+        /// <since_tizen> 8 </since_tizen>
         public new TabStyle Style => ViewStyle as TabStyle;
 
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public View Underline
+        {
+            get
+            {
+                if (null == underline)
+                {
+                    underline = new View()
+                    {
+                        PositionUsesPivotPoint = true,
+                        ParentOrigin = Tizen.NUI.ParentOrigin.BottomLeft,
+                        PivotPoint = Tizen.NUI.PivotPoint.BottomLeft,
+                    };
+                    Add(underline);
+                }
+                return underline;
+            }
+            internal set
+            {
+                underline = value;
+            }
+        }
+
         /// <summary>
         /// Selected item's index in Tab.
         /// </summary>
@@ -289,6 +311,7 @@ namespace Tizen.NUI.Components
             }
         }
 
+        private ColorSelector textColorSelector = new ColorSelector();
         /// <summary>
         /// Text color selector in Tab.
         /// </summary>
@@ -297,13 +320,18 @@ namespace Tizen.NUI.Components
         {
             get
             {
-                return (ColorSelector)Style?.Text?.TextColor;
+                return textColorSelector;
             }
             set
             {
-                if (null != value && null != Style?.Text)
+                if (value == null || textColorSelector == null)
+                {
+                    Tizen.Log.Fatal("NUI", "[Exception] Tab.TextColorSelector is null");
+                    throw new NullReferenceException("Tab.TextColorSelector is null");
+                }
+                else
                 {
-                    Style.Text.TextColor = value.Clone() as ColorSelector;
+                    textColorSelector.Clone(value);
                 }
             }
         }
@@ -353,8 +381,11 @@ namespace Tizen.NUI.Components
             UpdateItems();
         }
 
-        /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
-        [EditorBrowsable(EditorBrowsableState.Never)]
+        /// <summary>
+        /// Apply style to tab.
+        /// </summary>
+        /// <param name="viewStyle">The style to apply.</param>
+        /// <since_tizen> 8 </since_tizen>
         public override void ApplyStyle(ViewStyle viewStyle)
         {
             base.ApplyStyle(viewStyle);
@@ -363,19 +394,8 @@ namespace Tizen.NUI.Components
 
             if (null != tabStyle)
             {
-                if (null == underline)
-                {
-                    underline = new View()
-                    {
-                        PositionUsesPivotPoint = true,
-                        ParentOrigin = Tizen.NUI.ParentOrigin.BottomLeft,
-                        PivotPoint = Tizen.NUI.PivotPoint.BottomLeft,
-                    };
-                    Add(underline);
-                    CreateUnderLineAnimation();
-                }
-
-                underline.ApplyStyle(Style.UnderLine);
+                Underline.ApplyStyle(tabStyle.UnderLine);
+                CreateUnderLineAnimation();
             }
         }
 
@@ -420,7 +440,7 @@ namespace Tizen.NUI.Components
         }
 
         /// <summary>
-        /// Update Tab by attributes.
+        /// Update Tab.
         /// </summary>
         /// <since_tizen> 6 </since_tizen>
         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
@@ -431,12 +451,11 @@ namespace Tizen.NUI.Components
         }
 
         /// <summary>
-        /// Get Tab attribues.
+        /// Get Tab style.
         /// </summary>
-        /// <since_tizen> 6 </since_tizen>
-        /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        protected override ViewStyle GetViewStyle()
+        /// <returns>The default tab style.</returns>
+        /// <since_tizen> 8 </since_tizen>
+        protected override ViewStyle CreateViewStyle()
         {
             return new TabStyle();
         }
@@ -444,15 +463,15 @@ namespace Tizen.NUI.Components
         /// <summary>
         /// Theme change callback when theme is changed, this callback will be trigger.
         /// </summary>
-        /// <since_tizen> 6 </since_tizen>
-        /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
-        [EditorBrowsable(EditorBrowsableState.Never)]
+        /// <param name="sender">The sender</param>
+        /// <param name="e">The event data</param>
+        /// <since_tizen> 8 </since_tizen>
         protected override void OnThemeChangedEvent(object sender, StyleManager.ThemeChangeEventArgs e)
         {
-            TabStyle tempAttributes = StyleManager.Instance.GetAttributes(style) as TabStyle;
-            if (tempAttributes != null)
+            TabStyle tabStyle = StyleManager.Instance.GetViewStyle(style) as TabStyle;
+            if (tabStyle != null)
             {
-                Style.CopyFrom(tempAttributes);
+                Style.CopyFrom(tabStyle);
             }
         }
 
@@ -485,7 +504,7 @@ namespace Tizen.NUI.Components
                 {
                     for (int i = 0; i < totalNum; i++)
                     {
-                        preW = (itemList[i].NaturalSize2D != null ? itemList[i].NaturalSize2D.Width : 0);
+                        preW = (itemList[i].TextItem.NaturalSize2D != null ? itemList[i].TextItem.NaturalSize2D.Width : 0);
                         itemList[i].Position2D.X = preX;
                         itemList[i].Size2D.Width = preW;
                         preX = itemList[i].Position2D.X + preW + itemSpace;
@@ -546,6 +565,7 @@ namespace Tizen.NUI.Components
 
         private void AddItemByIndex(TabItemData itemData, int index)
         {
+            if (null == itemData) return;
             int h = 0;
             int topSpace = (int)Style.ItemPadding.Top;
             if (Style.UnderLine != null && Style.UnderLine.Size != null)
@@ -591,19 +611,6 @@ namespace Tizen.NUI.Components
             }
         }
 
-        private void CreateUnderLineAttributes()
-        {
-            if (Style.UnderLine == null)
-            {
-                Style.UnderLine = new ViewStyle()
-                {
-                    PositionUsesPivotPoint = true,
-                    ParentOrigin = Tizen.NUI.ParentOrigin.BottomLeft,
-                    PivotPoint = Tizen.NUI.PivotPoint.BottomLeft,
-                };
-            }
-        }
-
         private void CreateUnderLineAnimation()
         {
             if (underlineAni == null)
@@ -696,6 +703,8 @@ namespace Tizen.NUI.Components
                     VerticalAlignment = VerticalAlignment.Center
                 };
                 Add(TextItem);
+
+                EnableControlStatePropagation = true;
             }
 
             internal int Index