From 6d8580b75a2d276b1fe4dbe527f17392139dfe05 Mon Sep 17 00:00:00 2001 From: huayongxu <49056704+huayongxu@users.noreply.github.com> Date: Fri, 3 Apr 2020 11:03:37 +0800 Subject: [PATCH] [NUI] Support text shadow (#1509) * 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 --- .../public/BaseComponents/Style/TextLabelStyle.cs | 21 ++++ .../src/public/BaseComponents/TextLabel.cs | 52 ++++++++++ .../src/public/ViewProperty/TextShadow.cs | 114 +++++++++++++++++++++ .../Tizen.NUI.Samples/Samples/ButtonSample.cs | 1 + 4 files changed, 188 insertions(+) create mode 100755 src/Tizen.NUI/src/public/ViewProperty/TextShadow.cs diff --git a/src/Tizen.NUI/src/public/BaseComponents/Style/TextLabelStyle.cs b/src/Tizen.NUI/src/public/BaseComponents/Style/TextLabelStyle.cs index a5a9aa5..f478ea3 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/Style/TextLabelStyle.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/Style/TextLabelStyle.cs @@ -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), typeof(TextLabelStyle), null, propertyChanged: (bindable, oldValue, newValue) => + { + var textLabelStyle = (TextLabelStyle)bindable; + textLabelStyle.textShadow = SelectorHelper.CopyCloneable(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 textSelector; private Selector textColorSelector; private Selector pointSizeSelector; + private Selector 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 + { + get => (Selector)GetValue(TextShadowProperty); + set => SetValue(TextShadowProperty, value); + } } } diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs b/src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs index 53f7408..76cbce9 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs @@ -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(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; + /// 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 } /// + /// Describes a text shadow for a TextLabel. + /// It is null by default. + /// + [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(); + } + } + + /// /// The Emboss property.
/// The default emboss parameters.
///
@@ -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 index 0000000..fcfcc52 --- /dev/null +++ b/src/Tizen.NUI/src/public/ViewProperty/TextShadow.cs @@ -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 +{ + /// + /// The Text Shadow for TextLabel. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public class TextShadow : Internal.ICloneable + { + private PropertyMap propertyMap = null; + + internal delegate void PropertyChangedCallback(TextShadow instance); + internal PropertyChangedCallback OnPropertyChanged = null; + + /// + /// Constructor + /// + [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); + } + + /// + /// Deep copy method + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public object Clone() + { + return new TextShadow(Color, Offset, BlurRadius); + } + + /// + /// Deep copy method (static) + /// This provides nullity check. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public static object Clone(TextShadow instance) + { + return instance == null ? null : new TextShadow(instance.Color, instance.Offset, instance.BlurRadius); + } + + /// + /// The color for the shadow of text. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public Color Color { get; } = Color.Black; + + /// + /// The offset for the shadow of text. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public Vector2 Offset { get; } = Vector2.Zero; + + /// + /// The blur radius of the shadow of text. + /// + [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); + } + } +} diff --git a/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/ButtonSample.cs b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/ButtonSample.cs index 23713af..b40eb1a 100755 --- a/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/ButtonSample.cs +++ b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/ButtonSample.cs @@ -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); -- 2.7.4