[NUI] Apply TabView UX - TabBar and TabButton Size and BackgroundColor
authorJaehyun Cho <jae_hyun.cho@samsung.com>
Wed, 13 Apr 2022 09:26:52 +0000 (18:26 +0900)
committerJaehyun Cho <jaehyun0cho@gmail.com>
Thu, 21 Apr 2022 10:39:37 +0000 (19:39 +0900)
The latest TabView UX has been applied.
TabBar and TabButton's Size and BackgroundColor have been updated.

src/Tizen.NUI.Components/Controls/TabBar.cs
src/Tizen.NUI.Components/Controls/TabButton.cs
src/Tizen.NUI.Components/Controls/TabView.cs
src/Tizen.NUI.Components/Style/TabButtonStyle.cs
src/Tizen.NUI.Components/Theme/DefaultThemeCommon.cs
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/TabViewSample.cs

index c6a1ced..5daadd1 100755 (executable)
@@ -148,9 +148,6 @@ namespace Tizen.NUI.Components
                     TabButtonSelected(this, args);
                 }
             }
-
-            //TODO: To support non-unified tab button size.
-            CalculateUnifiedTabButtonSize();
         }
 
         /// <summary>
@@ -194,37 +191,6 @@ namespace Tizen.NUI.Components
             {
                 tabButtons[SelectedIndex].IsSelected = true;
             }
-
-            //TODO: To support non-unified tab button size.
-            CalculateUnifiedTabButtonSize();
-        }
-
-        /// <inheritdoc/>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public override void OnRelayout(Vector2 size, RelayoutContainer container)
-        {
-            base.OnRelayout(size, container);
-
-            //TODO: To support non-unified tab button size.
-            CalculateUnifiedTabButtonSize();
-        }
-
-        private void CalculateUnifiedTabButtonSize()
-        {
-            if (tabButtons.Count <= 0)
-            {
-                return;
-            }
-
-            var tabButtonWidth = Size.Width / tabButtons.Count;
-
-            foreach (TabButton tabButton in tabButtons)
-            {
-                if (tabButton.Size.Width != tabButtonWidth)
-                {
-                    tabButton.Size = new Size(tabButtonWidth, tabButton.Size.Height);
-                }
-            }
         }
 
         /// <summary>
index 9ffd875..968e666 100755 (executable)
@@ -14,6 +14,7 @@
  * limitations under the License.
  *
  */
+using System;
 using System.ComponentModel;
 using System.Diagnostics.CodeAnalysis;
 using Tizen.NUI.BaseComponents;
@@ -32,9 +33,6 @@ namespace Tizen.NUI.Components
 
         private bool styleApplied = false;
 
-        private View topLine = null;
-        private View bottomLine = null; // Visible only if TabButton is selected or pressed.
-
         /// <summary>
         /// Creates a new instance of TabButton.
         /// </summary>
@@ -83,18 +81,6 @@ namespace Tizen.NUI.Components
 
             tabButtonStyle = viewStyle as TabButtonStyle;
 
-            //Apply TopLine style.
-            if (tabButtonStyle?.TopLine != null)
-            {
-                topLine?.ApplyStyle(tabButtonStyle.TopLine);
-            }
-
-            //Apply BottomLine style.
-            if (tabButtonStyle?.BottomLine != null)
-            {
-                bottomLine?.ApplyStyle(tabButtonStyle.BottomLine);
-            }
-
             styleApplied = true;
 
             //Calculate children's sizes and positions based on padding sizes.
@@ -151,15 +137,7 @@ namespace Tizen.NUI.Components
 
             if (type == DisposeTypes.Explicit)
             {
-                if (topLine != null)
-                {
-                    Utility.Dispose(topLine);
-                }
-
-                if (bottomLine != null)
-                {
-                    Utility.Dispose(bottomLine);
-                }
+                // Dispose children explicitly
             }
 
             base.Dispose(type);
@@ -233,33 +211,19 @@ namespace Tizen.NUI.Components
         [EditorBrowsable(EditorBrowsableState.Never)]
         protected override void LayoutItems()
         {
-            if ((Icon == null) && (TextLabel == null))
-            {
-                return;
-            }
-
-            // Icon is added in Button.LayoutItems().
-            if ((Icon != null) && (Children.Contains(Icon) == false))
-            {
-                Add(Icon);
-            }
-
-            // TextLabel is added in Button.LayoutItems().
-            if ((TextLabel != null) && (Children.Contains(TextLabel) == false))
-            {
-                Add(TextLabel);
-            }
+            UpdateSizeAndSpacing();
         }
 
         private void Initialize()
         {
-            Layout = new AbsoluteLayout();
-
-            topLine = new View(tabButtonStyle?.TopLine);
-            Add(topLine);
+            Layout = new LinearLayout()
+            {
+                LinearOrientation = LinearLayout.Orientation.Vertical,
+                HorizontalAlignment = HorizontalAlignment.Center,
+                VerticalAlignment = VerticalAlignment.Center,
+            };
 
-            bottomLine = new View(tabButtonStyle?.BottomLine);
-            Add(bottomLine);
+            WidthSpecification = LayoutParamPolicies.MatchParent;
 
             AccessibilityHighlightable = true;
         }
@@ -271,97 +235,75 @@ namespace Tizen.NUI.Components
                 return;
             }
 
-            if ((Icon == null) && (TextLabel == null))
+            bool isEmptyIcon = false;
+            bool isEmptyText = false;
+
+            if (String.IsNullOrEmpty(Icon.ResourceUrl))
             {
-                return;
+                isEmptyIcon = true;
             }
 
-            // FIXME: set Selector<Extents> to padding
-            var padding = new Extents(40, 40, 24, 24);
-            var iconPadding = IconPadding;
-            var textPadding = TextPadding;
+            if (String.IsNullOrEmpty(TextLabel.Text))
+            {
+                isEmptyText = true;
+            }
 
-            // Calculate size of TextLabel.
-            if (TextLabel != null)
+            if (isEmptyIcon)
             {
-                // TODO: Other orientation cases are not implemented yet.
-                if ((IconRelativeOrientation == IconOrientation.Left) || (IconRelativeOrientation == IconOrientation.Right))
+                if (Children.Contains(Icon))
                 {
-                    var naturalWidthSum = (ushort)padding?.Start + (ushort)padding?.End + iconPadding.Start + iconPadding.End + (float)Icon?.SizeWidth + TextLabel.GetNaturalSize().Width;
-                    var naturalWidthDiff = SizeWidth - naturalWidthSum;
-
-                    if (naturalWidthDiff > 0)
-                    {
-                        TextLabel.SizeWidth = TextLabel.GetNaturalSize().Width;
-                    }
-                    else
-                    {
-                        TextLabel.SizeWidth = SizeWidth - (ushort)padding?.Start - (ushort)padding?.End - iconPadding.Start - iconPadding.End - textPadding.Start - textPadding.End - (float)Icon?.SizeWidth;
-                    }
+                    Remove(Icon);
                 }
             }
+            else if (Children.Contains(Icon) == false)
+            {
+                Add(Icon);
+            }
 
-            // Calculate positions of Icon and TextLabel.
-            switch (IconRelativeOrientation)
+            if (isEmptyText)
             {
-                // TODO: Other orientation cases are not implemented yet.
-                case IconOrientation.Left:
-                    if (LayoutDirection == ViewLayoutDirectionType.LTR)
-                    {
-                        if (Icon != null)
-                        {
-                            float iconX = 0;
-                            float iconY = (ushort)padding?.Top + iconPadding.Top;
-
-                            if (string.IsNullOrEmpty(TextLabel?.Text))
-                            {
-                                iconX = (SizeWidth - Icon.SizeWidth) / 2;
-                            }
-                            else
-                            {
-                                var widthSum = (ushort)padding?.Start + (ushort)padding?.End + iconPadding.Start + iconPadding.End + textPadding.Start + textPadding.End + Icon.SizeWidth + (float)TextLabel?.SizeWidth;
-                                var widthDiff = SizeWidth - widthSum;
-
-                                if (widthDiff > 0)
-                                {
-                                    iconX = (ushort)padding?.Start + iconPadding.Start + (widthDiff / 2);
-                                }
-                                else
-                                {
-                                    iconX = (ushort)padding?.Start + iconPadding.Start;
-                                }
-                            }
-
-                            Icon.Position = new Position(iconX, iconY);
-                        }
-
-                        if (TextLabel != null)
-                        {
-                            TextLabel.HorizontalAlignment = HorizontalAlignment.Begin;
-
-                            float textX = 0;
-                            float textY = 0;
-
-                            if (string.IsNullOrEmpty(Icon?.ResourceUrl))
-                            {
-                                textX = (SizeWidth - TextLabel.SizeWidth) / 2;
-                                textY = (ushort)padding?.Top + textPadding.Top;
-                            }
-                            else
-                            {
-                                textX = (float)Icon?.PositionX + (float)Icon?.SizeWidth;
-                                textY = (ushort)padding?.Top + textPadding.Top + (((float)Icon?.SizeHeight - TextLabel.SizeHeight) / 2);
-                            }
-
-                            TextLabel.Position = new Position(textX, textY);
-                        }
-                    }
-                    break;
-                default:
-                    break;
+                if (Children.Contains(TextLabel))
+                {
+                    Remove(TextLabel);
+                }
+            }
+            else if (Children.Contains(TextLabel) == false)
+            {
+                Add(TextLabel);
             }
 
-            padding?.Dispose();
+            // Icon and Text
+            if (!isEmptyIcon && !isEmptyText)
+            {
+                WidthSpecification = (int)tabButtonStyle.Size.Width;
+                HeightSpecification = (int)tabButtonStyle.Size.Height;
+                Padding = tabButtonStyle.Padding;
+            }
+            // Icon only
+            else if (!isEmptyIcon && isEmptyText)
+            {
+                WidthSpecification = (int)tabButtonStyle.SizeWithIconOnly.Width;
+                HeightSpecification = (int)tabButtonStyle.SizeWithIconOnly.Height;
+                Padding = tabButtonStyle.PaddingWithIconOnly;
+                Icon.WidthSpecification = (int)tabButtonStyle.IconSizeWithIconOnly.Width;
+                Icon.HeightSpecification = (int)tabButtonStyle.IconSizeWithIconOnly.Height;
+            }
+            // Text only
+            else if (isEmptyIcon && !isEmptyText)
+            {
+                WidthSpecification = (int)tabButtonStyle.SizeWithTextOnly.Width;
+                HeightSpecification = (int)tabButtonStyle.SizeWithTextOnly.Height;
+                Padding = tabButtonStyle.PaddingWithTextOnly;
+                Icon.WidthSpecification = (int)tabButtonStyle.Icon.Size.Width;
+                Icon.HeightSpecification = (int)tabButtonStyle.Icon.Size.Height;
+            }
+            // Nothing
+            else
+            {
+                WidthSpecification = (int)tabButtonStyle.Size.Width;
+                HeightSpecification = (int)tabButtonStyle.Size.Height;
+                Padding = tabButtonStyle.Padding;
+            }
         }
     }
 }
index ee89c19..ec70f8c 100755 (executable)
@@ -95,8 +95,11 @@ namespace Tizen.NUI.Components
             WidthSpecification = LayoutParamPolicies.MatchParent;
             HeightSpecification = LayoutParamPolicies.MatchParent;
 
-            InitContent();
             InitTabBar();
+            InitContent();
+
+            // To show TabBar's shadow TabBar is raised above Content.
+            TabBar.RaiseAbove(Content);
         }
 
         /// <inheritdoc/>
index 8ca5748..52e72fb 100755 (executable)
@@ -47,16 +47,34 @@ namespace Tizen.NUI.Components
         }
 
         /// <summary>
-        /// Gets or Sets the Line Style at the top of TabButton.
+        /// Gets or sets the size of a view with text only for the width, the height, and the depth.
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public ViewStyle TopLine { get; set; } = new ViewStyle();
+        public Size SizeWithTextOnly { get; set; } = new Size();
 
         /// <summary>
-        /// Gets or Sets the Line Style at the bottom of TabButton.
+        /// Gets or sets the size of a view with icon only for the width, the height, and the depth.
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public ViewStyle BottomLine { get; set; } = new ViewStyle();
+        public Size SizeWithIconOnly { get; set; } = new Size();
+
+        /// <summary>
+        /// Gets or sets the padding with text only for use in layout.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public Extents PaddingWithTextOnly { get; set; } = new Extents();
+
+        /// <summary>
+        /// Gets or sets the padding with icon only for use in layout.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public Extents PaddingWithIconOnly { get; set; } = new Extents();
+
+        /// <summary>
+        /// Gets or sets the size of icon with icon only for the width, the height, and the depth.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public Size IconSizeWithIconOnly { get; set; } = new Size();
 
         /// <inheritdoc/>
         [EditorBrowsable(EditorBrowsableState.Never)]
@@ -66,8 +84,11 @@ namespace Tizen.NUI.Components
 
             if (bindableObject is TabButtonStyle tabButtonStyle)
             {
-                TopLine.CopyFrom(tabButtonStyle.TopLine);
-                BottomLine.CopyFrom(tabButtonStyle.BottomLine);
+                SizeWithTextOnly = new Size(tabButtonStyle.SizeWithTextOnly);
+                SizeWithIconOnly = new Size(tabButtonStyle.SizeWithIconOnly);
+                PaddingWithTextOnly = new Extents(tabButtonStyle.PaddingWithTextOnly);
+                PaddingWithIconOnly = new Extents(tabButtonStyle.PaddingWithIconOnly);
+                IconSizeWithIconOnly = new Size(tabButtonStyle.IconSizeWithIconOnly);
             }
         }
     }
index 88f4246..6d7bc8c 100755 (executable)
@@ -522,22 +522,48 @@ namespace Tizen.NUI.Components
                 StartScrollOffset = new Size(0, 12),
             });
 
+            // TabBar base style
+            theme.AddStyleWithoutClone("Tizen.NUI.Components.TabBar", new ViewStyle()
+            {
+                Size = new Size(-1, -2),
+                Margin = new Extents(16, 16, 0, 0),
+                Padding = new Extents(14, 14, 0, 0),
+                CornerRadius = new Vector4(12.0f, 12.0f, 12.0f, 12.0f),
+                CornerRadiusPolicy = VisualTransformPolicyType.Absolute,
+                BoxShadow = new Shadow(8.0f, new Color(0.0f, 0.0f, 0.0f, 0.16f), new Vector2(0.0f, 2.0f)),
+                BackgroundColor = new Color("#FAFAFA"),
+            });
+
             // TabButton base style
             theme.AddStyleWithoutClone("Tizen.NUI.Components.TabButton", new TabButtonStyle()
             {
-                Size = new Size(-1, 84),
+                Size = new Size(-1, 116),
+                SizeWithTextOnly = new Size(-1, 72),
+                SizeWithIconOnly = new Size(-1, 64),
+                MinimumSize = new Size(100, -1),
+                Padding = new Extents(24, 24, 18, 16),
+                PaddingWithTextOnly = new Extents(24, 24, 20, 20),
+                PaddingWithIconOnly = new Extents(24, 24, 16, 16),
+                ItemSpacing = new Size2D(0, 10),
                 CornerRadius = 0,
-                BackgroundColor = Color.White,
+                IconSizeWithIconOnly = new Size(32, 32),
+                BackgroundColor = new Selector<Color>()
+                {
+                    Normal = new Color("#FAFAFA"),
+                    Selected = new Color("#FFE0CC"),
+                    Pressed = new Color("#FFE0CC"),
+                    Disabled = new Color("#FAFAFA"),
+                },
                 Text = new TextLabelStyle()
                 {
                     PixelSize = 28,
                     Size = new Size(-2, -2),
                     TextColor = new Selector<Color>()
                     {
-                        Normal = new Color("#000C2B"),
-                        Selected = new Color("#000C2B"),
-                        Pressed = new Color("#1473E6"),
-                        Disabled = new Color("#C3CAD2"),
+                        Normal = new Color("#090E21"),
+                        Selected = new Color("#FF6200"),
+                        Pressed = new Color("#FF6200"),
+                        Disabled = new Color("#CACACA"),
                     },
                     ThemeChangeSensitive = false,
                 },
@@ -546,33 +572,10 @@ namespace Tizen.NUI.Components
                     Size = new Size(48, 48),
                     Color = new Selector<Color>()
                     {
-                        Normal = new Color("#000C2B"),
-                        Selected = new Color("#000C2B"),
-                        Pressed = new Color("#1473E6"),
-                        Disabled = new Color("#C3CAD2"),
-                    },
-                },
-                TopLine = new ViewStyle()
-                {
-                    Size = new Size(-1, 1),
-                    BackgroundColor = new Selector<Color>()
-                    {
-                        Normal = new Color("#000C2B"),
-                        Selected = new Color("#000C2B"),
-                        Pressed = new Color("#1473E6"),
-                        Disabled = new Color("#C3CAD2"),
-                    },
-                },
-                BottomLine = new ViewStyle()
-                {
-                    Size = new Size(-1, 8),
-                    Position = new Position(0, 76), // 84 - 8
-                    BackgroundColor = new Selector<Color>()
-                    {
-                        Normal = Color.Transparent,
-                        Selected = new Color("#000C2B"),
-                        Pressed = new Color("#1473E6"),
-                        Disabled = Color.Transparent,
+                        Normal = new Color("#090E21"),
+                        Selected = new Color("#FF6200"),
+                        Pressed = new Color("#FF6200"),
+                        Disabled = new Color("#CACACA"),
                     },
                 },
             });
index 2ad01a4..a11e6f5 100644 (file)
@@ -7,6 +7,9 @@ namespace Tizen.NUI.Samples
 {
     public class TabViewSample : IExample
     {
+        private Window window;
+        private Navigator navigator;
+        private ContentPage contentPage;
         private TabView tabView;
         private TabButton tabButton, tabButton2, tabButton3;
         private View content, content2, content3;
@@ -15,7 +18,18 @@ namespace Tizen.NUI.Samples
 
         public void Activate()
         {
-            var window = NUIApplication.GetDefaultWindow();
+            window = NUIApplication.GetDefaultWindow();
+
+            navigator = window.GetDefaultNavigator();
+
+            contentPage = new ContentPage()
+            {
+                AppBar = new AppBar()
+                {
+                    Title = "TabView Sample",
+                    AutoNavigationContent = false,
+                },
+            };
 
             tabView = new TabView()
             {
@@ -91,7 +105,9 @@ namespace Tizen.NUI.Samples
             tabView.AddTab(tabButton3, content3);
             tabCount++;
 
-            window.Add(tabView);
+            contentPage.Content = tabView;
+
+            navigator.Push(contentPage);
 
             addBtn = new Button()
             {
@@ -102,7 +118,7 @@ namespace Tizen.NUI.Samples
 
             addBtn.Clicked += (object sender, ClickedEventArgs args) =>
             {
-                if (tabCount < 3)
+                if (tabCount < 4)
                 {
                     tabCount++;
 
@@ -166,28 +182,31 @@ namespace Tizen.NUI.Samples
 
         public void Deactivate()
         {
-            var window = NUIApplication.GetDefaultWindow();
 
-            if (tabView != null)
+            if (contentPage != null)
             {
-                window.Remove(tabView);
-                tabView.Dispose();
+                navigator?.Remove(contentPage);
+                contentPage.Dispose();
+                contentPage = null;
                 tabView = null;
             }
 
             if (addBtn != null)
             {
-                window.Remove(addBtn);
+                window?.Remove(addBtn);
                 addBtn.Dispose();
                 addBtn = null;
             }
 
             if (removeBtn != null)
             {
-                window.Remove(removeBtn);
+                window?.Remove(removeBtn);
                 removeBtn.Dispose();
                 removeBtn = null;
             }
+
+            navigator = null;
+            window = null;
         }
     }
 }