[NUI] Merge master#1199 to API7 (#1205)
authorzhouleonlei <56956725+zhouleonlei@users.noreply.github.com>
Wed, 18 Dec 2019 06:57:04 +0000 (14:57 +0800)
committerJiyun Yang <ji.yang@samsung.com>
Wed, 18 Dec 2019 06:57:04 +0000 (15:57 +0900)
src/Tizen.NUI.Components/Controls/Toast.cs
src/Tizen.NUI.Components/Style/ToastStyle.cs

index 56c8a59..b77a349 100755 (executable)
@@ -37,8 +37,7 @@ namespace Tizen.NUI.Components
             if (newValue != null)
             {
                 instance.strText = (string)(newValue);
-                instance.textLabel.Text = instance.strText;
-                instance.UpdateText();
+                instance.Style.Text.Text = instance.strText;
             }
         },
         defaultValueCreator: (bindable) =>
@@ -75,20 +74,10 @@ namespace Tizen.NUI.Components
         }
 
         private Window window = null;
-               protected TextLabel[] textLabels = null;
-
-        /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        protected TextLabel textLabel = null;
-
+        protected TextLabel[] textLabels = null;
+        private TextLabel textLabel = null;
         private string strText = null;
-        private NPatchVisual toastBackground = null;
         private Timer timer = null;
-        private string[] textArray = null;
-
-        private readonly int maxTextAreaWidth = 808;
-        private readonly int textPaddingLeft = 96;
-        private readonly int textPaddingTop = 38;
         private readonly uint duration = 3000;
 
         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
@@ -134,23 +123,8 @@ namespace Tizen.NUI.Components
         /// <since_tizen> 6 </since_tizen>
         public string[] TextArray
         {
-            get
-            {
-                return textArray;
-            }
-            set
-            {
-                if (null != value)
-                {
-                    textArray = value;
-                    string message = "";
-                    foreach (string text in textArray)
-                    {
-                        message += text + "\n";
-                    }
-                    Message = message;
-                }
-            }
+            get;
+            set;
         }
 
         /// <summary>
@@ -237,6 +211,7 @@ namespace Tizen.NUI.Components
             window.Add(this);
             this.Position.X = (window.Size.Width - this.Size.Width) / 2;
             this.Position.Y = (window.Size.Height - this.Size.Height) / 2;
+            timer.Start();
         }
 
         /// <summary>
@@ -269,28 +244,9 @@ namespace Tizen.NUI.Components
             }
             set
             {
-                if (null != value)
+                if (null != value && null != Style.Text)
                 {
-                    //CreateTextAttributes();
                     Style.Text.Padding.CopyFrom(value);
-
-                    //if (null == textPadding)
-                    //{
-                    //    textPadding = new Extents((ushort start, ushort end, ushort top, ushort bottom) =>
-                    //    {
-                    //        toastAttributes.TextAttributes.Padding.Start = start;
-                    //        toastAttributes.TextAttributes.Padding.End = end;
-                    //        toastAttributes.TextAttributes.Padding.Top = top;
-                    //        toastAttributes.TextAttributes.Padding.Bottom = bottom;
-                    //        RelayoutRequest();
-                    //    }, value.Start, value.End, value.Top, value.Bottom);
-                    //}
-                    //else
-                    //{
-                    //    textPadding.CopyFrom(value);
-                    //}
-
-                    //RelayoutRequest();
                 }
             }
         }
@@ -323,6 +279,24 @@ namespace Tizen.NUI.Components
             }
         }
 
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public override void ApplyStyle(ViewStyle viewStyle)
+        {
+            base.ApplyStyle(viewStyle);
+
+            ToastStyle toastStyle = viewStyle as ToastStyle;
+
+            if (null != toastStyle)
+            {
+                if (null == textLabel)
+                {
+                    textLabel = new TextLabel();
+                    this.Add(textLabel);
+                }
+                textLabel.ApplyStyle(toastStyle.Text);
+            }
+        }
+
         /// <summary>
         /// Dispose ToastPopup.
         /// </summary>
@@ -355,40 +329,6 @@ namespace Tizen.NUI.Components
         }
 
         /// <summary>
-        /// Relayout control's elements
-        /// </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)]
-        private void UpdateText()
-        {
-            if (window == null)
-            {
-                //return;
-            }
-
-            int _textPaddingLeft = Style.Text?.Padding.Start ?? textPaddingLeft;
-            int _textPaddingRight = Style.Text?.Padding.End ?? _textPaddingLeft;
-            int _textPaddingTop = Style.Text?.Padding.Top ?? textPaddingTop;
-            int _textPaddingBottom = Style.Text?.Padding.Bottom ?? _textPaddingTop;
-
-            int _textAreaWidth = (int)Size.Width - _textPaddingLeft - _textPaddingRight;
-            int _textAreaHeight = (int)Size.Height - _textPaddingTop - _textPaddingBottom;
-            _textAreaWidth = _textAreaWidth > maxTextAreaWidth ? maxTextAreaWidth : _textAreaWidth;        
-            if (textLabel != null)
-            {
-                textLabel.Position = new Position(_textPaddingLeft, _textPaddingTop);
-                textLabel.Size = new Size(_textAreaWidth, _textAreaHeight);
-                if (LayoutDirection == ViewLayoutDirectionType.RTL)
-                {
-                    textLabel.ParentOrigin = Tizen.NUI.ParentOrigin.TopRight;
-                    textLabel.PivotPoint = Tizen.NUI.PivotPoint.TopRight;
-                    textLabel.PositionUsesPivotPoint = true;
-                }
-            }
-        }
-
-        /// <summary>
         /// Get Toast attribues.
         /// </summary>
         /// <since_tizen> 6 </since_tizen>
@@ -401,25 +341,15 @@ namespace Tizen.NUI.Components
 
         private void Initialize()
         {
-            toastBackground = new NPatchVisual();
-            if (toastBackground == null)
-            {
-                throw new Exception("Toast background is null.");
-            }
-            SetToastBackground();
-
-            textLabel = new TextLabel();
             if (null == textLabel)
             {
-                throw new Exception("Toast textLabel is null.");
+                textLabel = new TextLabel();
+                this.Add(textLabel);
             }
-            textLabel.TextColor = Color.White;
-            this.Add(textLabel);
 
             this.VisibilityChanged += OnVisibilityChanged;
             timer = new Timer(Style.Duration ?? duration);
             timer.Tick += OnTick;
-            timer.Start();
         }
 
         private bool OnTick(object sender, EventArgs e)
@@ -432,21 +362,13 @@ namespace Tizen.NUI.Components
         {
             if (true == e.Visibility)
             {
+                window?.Add(this);
                 timer.Start();
             }
-        }
-
-        private void SetToastBackground()
-        {
-            if (null != Style?.Background?.ResourceUrl)
-            {
-                toastBackground.URL = Style.Background.ResourceUrl.All;
-            }
-            if (null != Style?.Background?.Border)
+            else
             {
-                toastBackground.Border = Style.Background.Border.All;
+                window?.Remove(this);
             }
-            this.Background = toastBackground.OutputVisualMap;
         }
     }
 }
index ec1ca60..8d47fe9 100755 (executable)
@@ -53,40 +53,24 @@ namespace Tizen.NUI.Components
         }
 
         /// <summary>
-        /// Gets or sets background image 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)]
-        public ImageViewStyle Background
-        {
-            get;
-            set;
-        }
-
-        /// <summary>
-        /// Gets or sets text Style.
+        /// Gets or sets toast show duration time.
         /// </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)]
-        public TextLabelStyle Text
+        public uint? Duration
         {
             get;
             set;
         }
 
         /// <summary>
-        /// Gets or sets toast show duration time.
+        /// Text's 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)]
-        public uint? Duration
-        {
-            get;
-            set;
-        }
+        public TextLabelStyle Text { get; set; }
 
         /// <summary>
         /// Style's clone function.
@@ -100,12 +84,7 @@ namespace Tizen.NUI.Components
             ToastStyle toastStyle = bindableObject as ToastStyle;
             if (toastStyle != null)
             {
-                if (toastStyle.Background!= null)
-                {
-                    Background.CopyFrom(toastStyle.Background);
-                }
-
-                if (toastStyle.Text!= null)
+                if (null != toastStyle.Text)
                 {
                     Text.CopyFrom(toastStyle.Text);
                 }
@@ -115,15 +94,17 @@ namespace Tizen.NUI.Components
 
         private void InitSubStyle()
         {
-            if (Background== null)
+            Text = new TextLabelStyle()
             {
-                Background= new ImageViewStyle();
-            }
-       
-            if (Text== null)
-            {
-                Text= new TextLabelStyle();
-            }
+                PositionUsesPivotPoint = true,
+                ParentOrigin = Tizen.NUI.ParentOrigin.Center,
+                PivotPoint = Tizen.NUI.PivotPoint.Center,
+                WidthResizePolicy = ResizePolicyType.FillToParent,
+                HeightResizePolicy = ResizePolicyType.FillToParent,
+                HorizontalAlignment = HorizontalAlignment.Center,
+                VerticalAlignment = VerticalAlignment.Center,
+                TextColor = Color.White
+            };
         }
     }
 }