Revert "Revert "[NUI] Add AlertDialogStyle class with the latest AlertDialog UX""
authorJaehyun Cho <jae_hyun.cho@samsung.com>
Wed, 14 Apr 2021 07:57:24 +0000 (16:57 +0900)
committerbshsqa <32317749+bshsqa@users.noreply.github.com>
Wed, 14 Apr 2021 11:53:58 +0000 (20:53 +0900)
This reverts commit 18a2050cf2890d02668449571e5950ef3c3faf42.

src/Tizen.NUI.Components/Controls/AlertDialog.cs
src/Tizen.NUI.Components/Style/AlertDialogStyle.cs [new file with mode: 0755]
src/Tizen.NUI.Components/Theme/DefaultTheme.cs
src/Tizen.NUI.Components/Theme/DefaultThemeCommon.cs

index 988e95a..b1b3ee5 100755 (executable)
@@ -39,6 +39,13 @@ namespace Tizen.NUI.Components
         private View defaultTitleContent = null;
         private View defaultContent = null;
         private View defaultActionContent = null;
+        // FIXME: Now AlertDialog.Padding Top and Bottom increases AlertDialog size incorrectly.
+        //        Until the bug is fixed, padding view is added after action content.
+        private View defaultActionContentPadding = null;
+
+        private AlertDialogStyle alertDialogStyle => ViewStyle as AlertDialogStyle;
+
+        private bool styleApplied = false;
 
         /// <summary>
         /// Creates a new instance of AlertDialog.
@@ -77,12 +84,54 @@ namespace Tizen.NUI.Components
                 {
                     Utility.Dispose(actionContent);
                 }
+
+                // FIXME: Now AlertDialog.Padding Top and Bottom increases AlertDialog size incorrectly.
+                //        Until the bug is fixed, padding view is added after action content.
+                if (defaultActionContentPadding != null)
+                {
+                    Utility.Dispose(defaultActionContentPadding);
+                }
             }
 
             base.Dispose(type);
         }
 
         /// <summary>
+        /// Applies style to AlertDialog.
+        /// </summary>
+        /// <param name="viewStyle">The style to apply.</param>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public override void ApplyStyle(ViewStyle viewStyle)
+        {
+            styleApplied = false;
+
+            base.ApplyStyle(viewStyle);
+
+            // Apply Title style.
+            if ((alertDialogStyle?.TitleTextLabel != null) && (DefaultTitleContent is TextLabel))
+            {
+                ((TextLabel)DefaultTitleContent)?.ApplyStyle(alertDialogStyle.TitleTextLabel);
+            }
+
+            // Apply Message style.
+            if ((alertDialogStyle?.MessageTextLabel != null) && (DefaultContent is TextLabel))
+            {
+                ((TextLabel)DefaultContent)?.ApplyStyle(alertDialogStyle.MessageTextLabel);
+            }
+
+            // Apply ActionContent style.
+            if (alertDialogStyle?.ActionContent != null)
+            {
+                DefaultActionContent?.ApplyStyle(alertDialogStyle.ActionContent);
+            }
+
+            styleApplied = true;
+
+            // Calculate dialog position and children's positions based on padding sizes.
+            CalculatePosition();
+        }
+
+        /// <summary>
         /// Title text of AlertDialog.
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
@@ -362,6 +411,13 @@ namespace Tizen.NUI.Components
                     defaultActionContent = CreateDefaultActionContent();
                 }
 
+                // FIXME: Now AlertDialog.Padding Top and Bottom increases AlertDialog size incorrectly.
+                //        Until the bug is fixed, padding view is added after action content.
+                if (defaultActionContentPadding == null)
+                {
+                    defaultActionContentPadding = CreateDefaultActionContentPadding();
+                }
+
                 return defaultActionContent;
             }
         }
@@ -414,57 +470,89 @@ namespace Tizen.NUI.Components
             if (actionContent != null)
             {
                 Add(actionContent);
+
+                // FIXME: Now AlertDialog.Padding Top and Bottom increases AlertDialog size incorrectly.
+                //        Until the bug is fixed, padding view is added after action content.
+                if (actionContent == defaultActionContent)
+                {
+                    if (defaultActionContentPadding != null)
+                    {
+                        Add(defaultActionContentPadding);
+                    }
+                }
             }
         }
 
         private TextLabel CreateDefaultTitleContent()
         {
-            //FIXME: Needs to separate GUI implementation codes to style cs file.
-            return new TextLabel()
-            {
-                HorizontalAlignment = HorizontalAlignment.Center,
-                VerticalAlignment = VerticalAlignment.Center,
-                BackgroundColor = new Color(1.0f, 1.0f, 1.0f, 1.0f),
-                Size = new Size(360, 80),
-            };
+            return new TextLabel();
         }
 
         private TextLabel CreateDefaultContent()
         {
-            //FIXME: Needs to separate GUI implementation codes to style cs file.
-            return new TextLabel()
-            {
-                HorizontalAlignment = HorizontalAlignment.Center,
-                VerticalAlignment = VerticalAlignment.Center,
-                BackgroundColor = new Color(1.0f, 1.0f, 1.0f, 1.0f),
-                Size = new Size(360, 200),
-            };
+            return new TextLabel();
         }
 
         private View CreateDefaultActionContent()
         {
-            //FIXME: Needs to separate GUI implementation codes to style cs file.
-            return new Control()
+            return new View()
             {
-                BackgroundColor = new Color(1.0f, 1.0f, 1.0f, 1.0f),
-                Size = new Size(360, 80),
                 Layout = new LinearLayout()
                 {
                     LinearOrientation = LinearLayout.Orientation.Horizontal,
-                    LinearAlignment = LinearLayout.Alignment.CenterHorizontal,
-                    CellPadding = new Size2D(10, 0),
                 },
             };
         }
 
+        // FIXME: Now AlertDialog.Padding Top and Bottom increases AlertDialog size incorrectly.
+        //        Until the bug is fixed, padding view is added after action content.
+        private View CreateDefaultActionContentPadding()
+        {
+            var layout = Layout as LinearLayout;
+
+            if ((layout == null) || (defaultActionContent == null))
+            {
+                return null;
+            }
+
+            View paddingView = null;
+
+            using (Size2D size = new Size2D(defaultActionContent.Size2D.Width, defaultActionContent.Size2D.Height))
+            {
+                if (layout.LinearOrientation == LinearLayout.Orientation.Horizontal)
+                {
+                    size.Width = 40;
+                }
+                else
+                {
+                    size.Height = 40;
+                }
+
+                paddingView = new View()
+                {
+                    Size2D = new Size2D(size.Width, size.Height),
+                };
+            }
+
+            return paddingView;
+        }
+
         private void OnRelayout(object sender, EventArgs e)
         {
-            //FIXME: Needs to separate GUI implementation codes to style cs file.
+            // Calculate dialog position and children's positions based on padding sizes.
             CalculatePosition();
         }
 
+        // Calculate dialog position and children's positions based on padding sizes.
         private void CalculatePosition()
         {
+            if (styleApplied == false)
+            {
+                return;
+            }
+
+            CalculateActionsCellPadding();
+
             var size = Size2D;
             var parent = GetParent();
             Size2D parentSize;
@@ -480,5 +568,58 @@ namespace Tizen.NUI.Components
 
             Position2D = new Position2D((parentSize.Width - size.Width) / 2, (parentSize.Height - size.Height) / 2);
         }
+
+        // Calculate CellPadding among Actions if ActionContent is LinearLayout.
+        private void CalculateActionsCellPadding()
+        {
+            if ((ActionContent != DefaultActionContent) || (ActionContent.Layout is LinearLayout == false))
+            {
+                return;
+            }
+
+            if (Actions == null)
+            {
+                return;
+            }
+
+            var size = Size2D;
+            var layout = ActionContent.Layout as LinearLayout;
+            int count = 0;
+
+            if (layout.LinearOrientation == LinearLayout.Orientation.Horizontal)
+            {
+                int actionsWidth = 0;
+
+                foreach (var action in Actions)
+                {
+                    actionsWidth += ((View)action).Size2D.Width + ((((View)action).Margin?.Start + ((View)action).Margin?.End) ?? 0);
+                    count++;
+                }
+
+                if (count > 1)
+                {
+                    actionsWidth += (Padding?.Start + Padding?.End) ?? 0;
+                    var cellPaddingWidth = (size.Width - actionsWidth) / (count - 1);
+                    layout.CellPadding = new Size2D(cellPaddingWidth , 0);
+                }
+            }
+            else
+            {
+                int actionsHeight = 0;
+
+                foreach (var action in Actions)
+                {
+                    actionsHeight += ((View)action).Size2D.Height + ((((View)action).Margin?.Top + ((View)action).Margin?.Bottom) ?? 0);
+                    count++;
+                }
+
+                if (count > 1)
+                {
+                    actionsHeight += (Padding?.Top + Padding?.Bottom) ?? 0;
+                    var cellPaddingHeight = (size.Height - actionsHeight) / (count - 1);
+                    layout.CellPadding = new Size2D(0, cellPaddingHeight);
+                }
+            }
+        }
     }
 }
diff --git a/src/Tizen.NUI.Components/Style/AlertDialogStyle.cs b/src/Tizen.NUI.Components/Style/AlertDialogStyle.cs
new file mode 100755 (executable)
index 0000000..0cc8ed8
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * Copyright(c) 2021 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.ComponentModel;
+using Tizen.NUI.BaseComponents;
+using Tizen.NUI.Binding;
+
+namespace Tizen.NUI.Components
+{
+    /// <summary>
+    /// AlertDialogStyle is a class which saves AlertDialog's ux data.
+    /// </summary>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class AlertDialogStyle : ButtonStyle
+    {
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        static AlertDialogStyle() { }
+
+        /// <summary>
+        /// Creates a new instance of a AlertDialogStyle.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public AlertDialogStyle() : base()
+        {
+        }
+
+        /// <summary>
+        /// Creates a new instance of a AlertDialogStyle with style.
+        /// </summary>
+        /// <param name="style">Create AlertDialogStyle by style customized by user.</param>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public AlertDialogStyle(AlertDialogStyle style) : base(style)
+        {
+        }
+
+        /// <summary>
+        /// Gets or sets the AlertDialog Title TextLabel style.
+        /// This style is applied if AlertDialog TitleContent is a TextLabel.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public TextLabelStyle TitleTextLabel { get; set; } = new TextLabelStyle();
+
+        /// <summary>
+        /// Gets or sets the AlertDialog Message TextLabel style.
+        /// This style is applied if AlertDialog Content is a TextLabel.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public TextLabelStyle MessageTextLabel { get; set; } = new TextLabelStyle();
+
+        /// <summary>
+        /// Gets or sets the AlertDialog ActionContent style.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public ViewStyle ActionContent { get; set; } = new ViewStyle();
+
+        /// <summary>
+        /// Style's clone function.
+        /// </summary>
+        /// <param name="bindableObject">The style that need to copy.</param>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public override void CopyFrom(BindableObject bindableObject)
+        {
+            base.CopyFrom(bindableObject);
+
+            if (bindableObject is AlertDialogStyle alertDialogStyle)
+            {
+                TitleTextLabel.CopyFrom(alertDialogStyle.TitleTextLabel);
+                MessageTextLabel.CopyFrom(alertDialogStyle.MessageTextLabel);
+                ActionContent.CopyFrom(alertDialogStyle.ActionContent);
+            }
+        }
+    }
+}
index fe5683a..3ec7e9a 100755 (executable)
@@ -128,6 +128,26 @@ namespace Tizen.NUI.Components
                     .Add<Size>("/BottomLine/Size", (ViewStyle style, Size value) => ((TabButtonStyle)style).BottomLine.Size = value)
                     .Add<Position>("/BottomLine/Position", (ViewStyle style, Position value) => ((TabButtonStyle)style).BottomLine.Position = value)
                     .AddSelector<Color>("/BottomLine/BackgroundColor", (ViewStyle style, Selector<Color> value) => ((TabButtonStyle)style).BottomLine.BackgroundColor = value, ControlState.Selected),
+
+                // AlertDialog
+                (new ExternalThemeKeyList(typeof(AlertDialog), typeof(AlertDialogStyle)))
+                    .Add<Size>("/Size", (ViewStyle style, Size value) => ((ViewStyle)style).Size = value)
+                    .Add<Extents>("/Padding", (ViewStyle style, Extents value) => ((ViewStyle)style).Padding = value)
+                    .Add<string>("/BackgroundImage", (ViewStyle style, string value) => ((ViewStyle)style).BackgroundImage = value)
+                    .Add<Size>("/TitleTextLabel/Size", (ViewStyle style, Size value) => ((AlertDialogStyle)style).TitleTextLabel.Size = value)
+                    .Add<Extents>("/TitleTextLabel/Margin", (ViewStyle style, Extents value) => ((AlertDialogStyle)style).TitleTextLabel.Margin = value)
+                    .Add<float?>("/TitleTextLabel/PixelSize", (ViewStyle style, float? value) => ((AlertDialogStyle)style).TitleTextLabel.PixelSize = value)
+                    .Add<HorizontalAlignment?>("/TitleTextLabel/HorizontalAlignment", (ViewStyle style, HorizontalAlignment? value) => ((AlertDialogStyle)style).TitleTextLabel.HorizontalAlignment = value)
+                    .Add<VerticalAlignment?>("/TitleTextLabel/VerticalAlignment", (ViewStyle style, VerticalAlignment? value) => ((AlertDialogStyle)style).TitleTextLabel.VerticalAlignment = value)
+                    .AddSelector<Color>("/TitleTextLabel/TextColor", (ViewStyle style, Selector<Color> value) => ((AlertDialogStyle)style).TitleTextLabel.TextColor = value)
+                    .Add<Size>("/MessageTextLabel/Size", (ViewStyle style, Size value) => ((AlertDialogStyle)style).MessageTextLabel.Size = value)
+                    .Add<Extents>("/MessageTextLabel/Margin", (ViewStyle style, Extents value) => ((AlertDialogStyle)style).MessageTextLabel.Margin = value)
+                    .Add<float?>("/MessageTextLabel/PixelSize", (ViewStyle style, float? value) => ((AlertDialogStyle)style).MessageTextLabel.PixelSize = value)
+                    .Add<bool?>("/MessageTextLabel/MultiLine", (ViewStyle style, bool? value) => ((AlertDialogStyle)style).MessageTextLabel.MultiLine = value)
+                    .Add<HorizontalAlignment?>("/MessageTextLabel/HorizontalAlignment", (ViewStyle style, HorizontalAlignment? value) => ((AlertDialogStyle)style).MessageTextLabel.HorizontalAlignment = value)
+                    .Add<VerticalAlignment?>("/MessageTextLabel/VerticalAlignment", (ViewStyle style, VerticalAlignment? value) => ((AlertDialogStyle)style).MessageTextLabel.VerticalAlignment = value)
+                    .AddSelector<Color>("/MessageTextLabel/TextColor", (ViewStyle style, Selector<Color> value) => ((AlertDialogStyle)style).MessageTextLabel.TextColor = value)
+                    .Add<Size>("/ActionContent/Size", (ViewStyle style, Size value) => ((AlertDialogStyle)style).ActionContent.Size = value),
             };
 
             return actionSet;
index d444f66..3039d08 100755 (executable)
@@ -503,6 +503,42 @@ namespace Tizen.NUI.Components
                 PositionY = 120,
             });
 
+            theme.AddStyleWithoutClone("Tizen.NUI.Components.AlertDialog", new AlertDialogStyle()
+            {
+                Size = new Size(-2, -2),
+                Padding = new Extents(80, 80, 0, 0),
+                BackgroundImage = FrameworkInformation.ResourcePath + "nui_component_default_dialog_bg.#.png",
+                TitleTextLabel = new TextLabelStyle()
+                {
+                    Size = new Size(1024, -2),
+                    Margin = new Extents(0, 0, 40, 40),
+                    PixelSize = 40,
+                    HorizontalAlignment = HorizontalAlignment.Center,
+                    VerticalAlignment = VerticalAlignment.Center,
+                    TextColor = new Selector<Color>()
+                    {
+                        Normal = new Color("#000C2BFF"),
+                    },
+                },
+                MessageTextLabel = new TextLabelStyle()
+                {
+                    Size = new Size(1024, -2),
+                    Margin = new Extents(0, 0, 0, 64),
+                    PixelSize = 32,
+                    MultiLine = true,
+                    HorizontalAlignment = HorizontalAlignment.Center,
+                    VerticalAlignment = VerticalAlignment.Center,
+                    TextColor = new Selector<Color>()
+                    {
+                        Normal = new Color("#000C2BFF"),
+                    },
+                },
+                ActionContent = new ViewStyle()
+                {
+                    Size = new Size(1024, -2),
+                },
+            });
+
             return theme;
         }
     }