[NUI] Support text shadow (#1509)
authorhuayongxu <49056704+huayongxu@users.noreply.github.com>
Fri, 3 Apr 2020 03:03:37 +0000 (11:03 +0800)
committerGitHub <noreply@github.com>
Fri, 3 Apr 2020 03:03:37 +0000 (12:03 +0900)
* support text shadow

* set shadow property of textlabel

* make properties of textshadow readonly.

* make textshadow readonly

* make textshadow copy constructor work correctly.

* add samples for text shadow of button

src/Tizen.NUI/src/public/BaseComponents/Style/TextLabelStyle.cs
src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs
src/Tizen.NUI/src/public/ViewProperty/TextShadow.cs [new file with mode: 0755]
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/ButtonSample.cs

index a5a9aa5..f478ea3 100755 (executable)
@@ -297,6 +297,18 @@ namespace Tizen.NUI.BaseComponents
             var textLabelStyle = (TextLabelStyle)bindable;
             return textLabelStyle.matchSystemLanguageDirection;
         });
+        /// A BindableProperty for ImageShadow
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static readonly BindableProperty TextShadowProperty = BindableProperty.Create(nameof(TextShadow), typeof(Selector<TextShadow>), typeof(TextLabelStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
+        {
+            var textLabelStyle = (TextLabelStyle)bindable;
+            textLabelStyle.textShadow = SelectorHelper.CopyCloneable<TextShadow>(newValue);
+        },
+        defaultValueCreator: (bindable) =>
+        {
+            var textLabelStyle = (TextLabelStyle)bindable;
+            return textLabelStyle.textShadow;
+        });
 
         private bool? multiLine;
         private HorizontalAlignment? horizontalAlignment;
@@ -320,6 +332,7 @@ namespace Tizen.NUI.BaseComponents
         private Selector<string> textSelector;
         private Selector<Color> textColorSelector;
         private Selector<float?> pointSizeSelector;
+        private Selector<TextShadow> textShadow;
 
         static TextLabelStyle() { }
 
@@ -518,5 +531,13 @@ namespace Tizen.NUI.BaseComponents
             }
             set => SetValue(PointSizeSelectorProperty, value);
         }
+
+        /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public Selector<TextShadow> TextShadow
+        {
+            get => (Selector<TextShadow>)GetValue(TextShadowProperty);
+            set => SetValue(TextShadowProperty, value);
+        }
     }
 }
index 53f7408..76cbce9 100755 (executable)
@@ -337,6 +337,22 @@ namespace Tizen.NUI.BaseComponents
         });
         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
         [EditorBrowsable(EditorBrowsableState.Never)]
+        public static readonly BindableProperty TextShadowProperty = BindableProperty.Create(nameof(TextShadow), typeof(TextShadow), typeof(TextLabel), null, propertyChanged: (bindable, oldValue, newValue) =>
+        {
+            var textLabel = (TextLabel)bindable;
+            if (newValue != null)
+            {
+                (textLabel.textShadow ?? (textLabel.textShadow = new CloneableViewSelector<TextShadow>(textLabel, textLabel.OnControlStateChangedForShadow))).Set(newValue);
+                Object.SetProperty(textLabel.swigCPtr, Property.SHADOW, TextShadow.ToPropertyValue(textLabel.textShadow.GetValue()));
+            }
+        },
+        defaultValueCreator: (bindable) =>
+        {
+            var textLabel = (TextLabel)bindable;
+            return textLabel.textShadow?.GetValue();
+        });
+        /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public static readonly BindableProperty EmbossProperty = BindableProperty.Create(nameof(Emboss), typeof(string), typeof(TextLabel), string.Empty, propertyChanged: (bindable, oldValue, newValue) =>
         {
             var textLabel = (TextLabel)bindable;
@@ -516,6 +532,8 @@ namespace Tizen.NUI.BaseComponents
         private string textLabelSid = null;
         private bool systemlangTextFlag = false;
 
+        private CloneableViewSelector<TextShadow> textShadow;
+
         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
         [EditorBrowsable(EditorBrowsableState.Never)]
         public TextLabelStyle Style => ViewStyle as TextLabelStyle;
@@ -1097,6 +1115,25 @@ namespace Tizen.NUI.BaseComponents
         }
 
         /// <summary>
+        /// Describes a text shadow for a TextLabel.
+        /// It is null by default.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public TextShadow TextShadow
+        {
+            get
+            {
+                var value = (TextShadow)GetValue(TextShadowProperty);
+                return value == null ? null : new TextShadow(value, OnTextShadowChanged);
+            }
+            set
+            {
+                SetValue(TextShadowProperty, value);
+                NotifyPropertyChanged();
+            }
+        }
+
+        /// <summary>
         /// The Emboss property.<br />
         /// The default emboss parameters.<br />
         /// </summary>
@@ -1541,5 +1578,20 @@ namespace Tizen.NUI.BaseComponents
             UnderlineColor = new Vector4(x, y, z, w);
         }
 
+        private void OnTextShadowChanged(TextShadow instance)
+        {
+            TextShadow = instance;
+        }
+
+        private void OnControlStateChangedForShadow(View obj, Components.ControlStates state)
+        {
+            UpdateTextShadowVisual();
+        }
+
+        private void UpdateTextShadowVisual()
+        {
+            TextShadow shadow = (textShadow != null && !textShadow.IsEmpty()) ? textShadow.GetValue() : textShadow?.GetValue();
+            Object.SetProperty(swigCPtr, Property.SHADOW, TextShadow.ToPropertyValue(shadow));
+        }
     }
 }
diff --git a/src/Tizen.NUI/src/public/ViewProperty/TextShadow.cs b/src/Tizen.NUI/src/public/ViewProperty/TextShadow.cs
new file mode 100755 (executable)
index 0000000..fcfcc52
--- /dev/null
@@ -0,0 +1,114 @@
+/*
+ * 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.ComponentModel;
+
+namespace Tizen.NUI
+{
+    /// <summary>
+    /// The Text Shadow for TextLabel.
+    /// </summary>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class TextShadow : Internal.ICloneable
+    {
+        private PropertyMap propertyMap = null;
+
+        internal delegate void PropertyChangedCallback(TextShadow instance);
+        internal PropertyChangedCallback OnPropertyChanged = null;
+
+        /// <summary>
+        /// Constructor
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public TextShadow(Color color, Vector2 offset, float blurRadius)
+        {
+            propertyMap = new PropertyMap();
+
+            Color = color;
+            propertyMap["color"] = PropertyValue.CreateWithGuard(Color);
+
+            Offset = offset;
+            propertyMap["offset"] = PropertyValue.CreateWithGuard(Offset);
+
+            BlurRadius = blurRadius;
+            propertyMap["blurRadius"] = new PropertyValue(BlurRadius);
+        }
+
+        /// <summary>
+        /// Deep copy method
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public object Clone()
+        {
+            return new TextShadow(Color, Offset, BlurRadius);
+        }
+
+        /// <summary>
+        /// Deep copy method (static)
+        /// This provides nullity check.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static object Clone(TextShadow instance)
+        {
+            return instance == null ? null : new TextShadow(instance.Color, instance.Offset, instance.BlurRadius);
+        }
+
+        /// <summary>
+        /// The color for the shadow of text.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public Color Color { get; } = Color.Black;
+
+        /// <summary>
+        /// The offset for the shadow of text.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public Vector2 Offset { get; } = Vector2.Zero;
+
+        /// <summary>
+        /// The blur radius of the shadow of text.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public float BlurRadius { get; } = 0.0f;
+
+        internal TextShadow(TextShadow other, PropertyChangedCallback callback = null)
+        {
+            propertyMap = new PropertyMap();
+
+            Color = other.Color;
+            propertyMap["color"] = PropertyValue.CreateWithGuard(Color);
+
+            Offset = other.Offset;
+            propertyMap["offset"] = PropertyValue.CreateWithGuard(Offset);
+
+            BlurRadius = other.BlurRadius;
+            propertyMap["blurRadius"] = new PropertyValue(BlurRadius);
+
+            OnPropertyChanged = callback;
+        }
+
+        static internal PropertyValue ToPropertyValue(TextShadow instance)
+        {
+            if (instance == null)
+            {
+                return new PropertyValue();
+            }
+
+            return new PropertyValue(instance.propertyMap);
+        }
+    }
+}
index 23713af..b40eb1a 100755 (executable)
@@ -53,6 +53,7 @@ namespace Tizen.NUI.Samples
             textButton.Style.BackgroundImageBorder = new Rectangle(4, 4, 5, 5);
             textButton.Size2D = new Size2D(300, 80);
             textButton.Position2D = new Position2D(100, 100);
+           textButton.Style.Text.TextShadow = new TextShadow(Color.Blue, new Vector2(2.0f, 2.0f), 5.0f);
             textButton.Style.Text.Text = "Button";
             root.Add(textButton);