From: Jiyun Yang Date: Mon, 6 Jan 2020 09:23:26 +0000 (+0900) Subject: [NUI] Add Shadow properties to ViewStyle (#1277) X-Git-Tag: submit/tizen/20200114.005334~1^2~7 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e5eb61baf2b0e0123bd8b2866ebb35b7d90f59c4;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [NUI] Add Shadow properties to ViewStyle (#1277) Signed-off-by: Jiyun Yang --- diff --git a/src/Tizen.NUI/src/public/BaseComponents/Style/Selector.cs b/src/Tizen.NUI/src/public/BaseComponents/Style/Selector.cs index 6cef33c..f5d7d32 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/Style/Selector.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/Style/Selector.cs @@ -239,4 +239,56 @@ namespace Tizen.NUI.BaseComponents private View targetView; private BindableProperty targetBindableProperty; } + + internal static class SelectorHelper where T : class, Tizen.NUI.ICloneable + { + /// + /// For the object type of T or Selector T, convert it to Selector T and return the cloned one. + /// Otherwise, return null.
+ ///
+ static internal Selector Clone(object value) + { + var type = value?.GetType(); + + if (type == typeof(Selector)) + { + var result = new Selector(); + result.Clone((Selector)value); + return result; + } + + if (type == typeof(T)) + { + var result = new Selector(); + result.Clone((T)value); + return result; + } + + return null; + } + + /// + /// For the object type of T or Selector T, convert it to T and return the cloned one. + /// Otherwise, return null.
+ ///
+ static internal T Clone(object value, View view) + { + var type = value?.GetType(); + + if (type == typeof(T)) + { + return (T)((T)value).Clone(); + } + + if (type == typeof(Selector) && view != null) + { + Selector selector = (Selector)value; + T valueInState = selector.GetValue(view.ControlState); + + return (T)valueInState?.Clone(); + } + + return null; + } + } } diff --git a/src/Tizen.NUI/src/public/BaseComponents/Style/ViewStyle.cs b/src/Tizen.NUI/src/public/BaseComponents/Style/ViewStyle.cs index b55d46e..92b5929 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/Style/ViewStyle.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/Style/ViewStyle.cs @@ -85,6 +85,10 @@ namespace Tizen.NUI.BaseComponents private Extents margin; private float? weight; + private Selector imageShadow; + + private Selector boxShadow; + static ViewStyle() {} /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. @@ -801,6 +805,32 @@ namespace Tizen.NUI.BaseComponents return viewStyle.backgroundImageBorderSelector; }); + /// A BindableProperty for ImageShadow + [EditorBrowsable(EditorBrowsableState.Never)] + public static readonly BindableProperty ImageShadowProperty = BindableProperty.Create(nameof(ImageShadow), typeof(Selector), typeof(ViewStyle), null, propertyChanged: (bindable, oldValue, newValue) => + { + var viewStyle = (ViewStyle)bindable; + viewStyle.imageShadow = SelectorHelper.Clone(newValue); + }, + defaultValueCreator: (bindable) => + { + var viewStyle = (ViewStyle)bindable; + return viewStyle.imageShadow; + }); + + /// A BindableProperty for BoxShadow + [EditorBrowsable(EditorBrowsableState.Never)] + public static readonly BindableProperty BoxShadowProperty = BindableProperty.Create(nameof(BoxShadow), typeof(Selector), typeof(ViewStyle), null, propertyChanged: (bindable, oldValue, newValue) => + { + var viewStyle = (ViewStyle)bindable; + viewStyle.boxShadow = SelectorHelper.Clone(newValue); + }, + defaultValueCreator: (bindable) => + { + var viewStyle = (ViewStyle)bindable; + return viewStyle.boxShadow; + }); + /// 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 ViewStyle() @@ -1321,5 +1351,33 @@ namespace Tizen.NUI.BaseComponents } set => SetValue(BackgroundImageBorderSelectorProperty, value); } + + /// + /// Describes a shadow as an image for a View. + /// It is null by default. + /// + /// + /// The mutually exclusive with "BoxShadow". + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public Selector ImageShadow + { + get => (Selector)GetValue(ImageShadowProperty); + set => SetValue(ImageShadowProperty, value); + } + + /// + /// Describes a box shaped shadow drawing for a View. + /// It is null by default. + /// + /// + /// The mutually exclusive with "ImageShadow". + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public Selector BoxShadow + { + get => (Selector)GetValue(BoxShadowProperty); + set => SetValue(BoxShadowProperty, value); + } } } diff --git a/src/Tizen.NUI/src/public/BaseComponents/View.cs b/src/Tizen.NUI/src/public/BaseComponents/View.cs index dec6ddb..c513026 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/View.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/View.cs @@ -301,46 +301,44 @@ namespace Tizen.NUI.BaseComponents } /// - /// Describes a shadow as an image for View. + /// Describes a shadow as an image for a View. /// It is null by default. /// /// /// The mutually exclusive with "BoxShadow". - /// If it is not null, the "BoxShadow" property will be ignored. /// [EditorBrowsable(EditorBrowsableState.Never)] public ImageShadow ImageShadow { get { - return (ImageShadow)GetValue(ImageShadowProperty); + var value = (ImageShadow)GetValue(ImageShadowProperty); + return value == null ? null : new ImageShadow(value, OnImageShadowChanged); } set { - value.OnPropertyChanged = OnImageShadowChanged; SetValue(ImageShadowProperty, value); NotifyPropertyChanged(); } } /// - /// Describes a box shaped shadow drawing for View. + /// Describes a box shaped shadow drawing for a View. /// It is null by default. /// /// /// The mutually exclusive with "ImageShadow". - /// If the "ImageShadow" is not null, this property will be ignored. /// [EditorBrowsable(EditorBrowsableState.Never)] public Shadow BoxShadow { get { - return (Shadow)GetValue(BoxShadowProperty); + var value = (Shadow)GetValue(BoxShadowProperty); + return value == null ? null : new Shadow(value, OnBoxShadowChanged); } set { - value.OnPropertyChanged = OnBoxShadowChanged; SetValue(BoxShadowProperty, value); NotifyPropertyChanged(); } diff --git a/src/Tizen.NUI/src/public/BaseComponents/ViewBindableProperty.cs b/src/Tizen.NUI/src/public/BaseComponents/ViewBindableProperty.cs index a185bd6..59d7fe2 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/ViewBindableProperty.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/ViewBindableProperty.cs @@ -1383,7 +1383,7 @@ namespace Tizen.NUI.BaseComponents public static readonly BindableProperty ImageShadowProperty = BindableProperty.Create("ImageShadow", typeof(ImageShadow), typeof(View), null, propertyChanged: (bindable, oldValue, newValue) => { var view = (View)bindable; - view.imageShadow = (ImageShadow)newValue; + view.imageShadow = SelectorHelper.Clone(newValue, view); Tizen.NUI.Object.SetProperty(view.swigCPtr, Interop.ViewProperty.View_Property_SHADOW_get(), ImageShadow.ToPropertyValue(view.imageShadow)); }, defaultValueCreator: (bindable) => @@ -1398,11 +1398,8 @@ namespace Tizen.NUI.BaseComponents public static readonly BindableProperty BoxShadowProperty = BindableProperty.Create("BoxShadow", typeof(Shadow), typeof(View), null, propertyChanged: (bindable, oldValue, newValue) => { var view = (View)bindable; - view.boxShadow = (Shadow)newValue; - if (view.imageShadow == null) - { - Tizen.NUI.Object.SetProperty(view.swigCPtr, Interop.ViewProperty.View_Property_SHADOW_get(), Shadow.ToPropertyValue(view.boxShadow)); - } + view.boxShadow = SelectorHelper.Clone(newValue, view); + Tizen.NUI.Object.SetProperty(view.swigCPtr, Interop.ViewProperty.View_Property_SHADOW_get(), Shadow.ToPropertyValue(view.boxShadow)); }, defaultValueCreator: (bindable) => { diff --git a/src/Tizen.NUI/src/public/ViewProperty/ICloneable.cs b/src/Tizen.NUI/src/public/ViewProperty/ICloneable.cs new file mode 100644 index 0000000..4304e7e --- /dev/null +++ b/src/Tizen.NUI/src/public/ViewProperty/ICloneable.cs @@ -0,0 +1,37 @@ +/* + * 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 class that offer Clone method. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public interface ICloneable + { + /// + /// Clone object + /// + [EditorBrowsable(EditorBrowsableState.Never)] + object Clone(); + } +} + + diff --git a/src/Tizen.NUI/src/public/ViewProperty/ImageShadow.cs b/src/Tizen.NUI/src/public/ViewProperty/ImageShadow.cs index 5bf2d85..9e03c5c 100644 --- a/src/Tizen.NUI/src/public/ViewProperty/ImageShadow.cs +++ b/src/Tizen.NUI/src/public/ViewProperty/ImageShadow.cs @@ -24,7 +24,7 @@ namespace Tizen.NUI /// The Shadow composed of image for View /// [EditorBrowsable(EditorBrowsableState.Never)] - public class ImageShadow : TransformablePropertyMap + public class ImageShadow : TransformablePropertyMap, Tizen.NUI.ICloneable { private string url; @@ -38,11 +38,18 @@ namespace Tizen.NUI { } + internal ImageShadow(ImageShadow other, PropertyChangedCallback callback = null) : base(other) + { + Url = other.Url; + Border = other.Border; + OnPropertyChanged = callback; + } + /// /// Deep copy method /// [EditorBrowsable(EditorBrowsableState.Never)] - override public object Clone() + public object Clone() { return new ImageShadow() { Offset = offset, diff --git a/src/Tizen.NUI/src/public/ViewProperty/Shadow.cs b/src/Tizen.NUI/src/public/ViewProperty/Shadow.cs index 18b6fe7..3bbb610 100644 --- a/src/Tizen.NUI/src/public/ViewProperty/Shadow.cs +++ b/src/Tizen.NUI/src/public/ViewProperty/Shadow.cs @@ -24,7 +24,7 @@ namespace Tizen.NUI /// The platform provided shadow drawing for View /// [EditorBrowsable(EditorBrowsableState.Never)] - public class Shadow : TransformablePropertyMap + public class Shadow : TransformablePropertyMap, Tizen.NUI.ICloneable { private static readonly Color noColor = new Color(0, 0, 0, 0); @@ -43,6 +43,13 @@ namespace Tizen.NUI Color = defaultColor; } + internal Shadow(Shadow other, PropertyChangedCallback callback = null) : base(other) + { + Color = other.Color; + BlurRadius = other.BlurRadius; + OnPropertyChanged = callback; + } + /// /// The boolean conversion /// @@ -60,7 +67,7 @@ namespace Tizen.NUI /// Deep copy method /// [EditorBrowsable(EditorBrowsableState.Never)] - override public object Clone() + public object Clone() { return new Shadow() { Offset = offset, diff --git a/src/Tizen.NUI/src/public/ViewProperty/TransformablePropertyMap.cs b/src/Tizen.NUI/src/public/ViewProperty/TransformablePropertyMap.cs index b5e46d2..84f4ec0 100644 --- a/src/Tizen.NUI/src/public/ViewProperty/TransformablePropertyMap.cs +++ b/src/Tizen.NUI/src/public/ViewProperty/TransformablePropertyMap.cs @@ -186,12 +186,6 @@ namespace Tizen.NUI abstract internal bool IsValid(); - /// - /// Deep copy method - /// - [EditorBrowsable(EditorBrowsableState.Never)] - abstract public object Clone(); - static internal PropertyValue ToPropertyValue(TransformablePropertyMap instance) { return (instance != null && instance.IsValid()) ? new PropertyValue(instance.propertyMap) : new PropertyValue();