From 98ed15050e2f6e3abeae48d613119e58b3f90f84 Mon Sep 17 00:00:00 2001 From: Jiyun Yang Date: Thu, 8 Apr 2021 16:32:32 +0900 Subject: [PATCH] [NUI] Change CornerRadius type to Vector4 from float (#2863) Note that, only X value of Vector4 will be applied to the view until dali support it. Signed-off-by: Jiyun Yang --- .../src/internal/Common/PropertyHelper.cs | 15 +++++++++++++-- .../src/public/BaseComponents/ImageView.cs | 6 ++++-- .../src/public/BaseComponents/Style/ViewStyle.cs | 9 +++++---- .../Style/ViewStyleBindableProperty.cs | 8 ++++---- src/Tizen.NUI/src/public/BaseComponents/View.cs | 5 +++-- .../public/BaseComponents/ViewBindableProperty.cs | 22 +++++++++++++++++----- .../src/public/BaseComponents/ViewInternal.cs | 8 ++++++-- src/Tizen.NUI/src/public/Common/Vector4.cs | 10 ++++++++++ .../src/public/ViewProperty/BackgroundExtraData.cs | 2 +- .../src/public/ViewProperty/ShadowBase.cs | 8 ++++++-- 10 files changed, 69 insertions(+), 24 deletions(-) diff --git a/src/Tizen.NUI/src/internal/Common/PropertyHelper.cs b/src/Tizen.NUI/src/internal/Common/PropertyHelper.cs index 658464b..4be0347 100755 --- a/src/Tizen.NUI/src/internal/Common/PropertyHelper.cs +++ b/src/Tizen.NUI/src/internal/Common/PropertyHelper.cs @@ -39,8 +39,8 @@ namespace Tizen.NUI { "boxShadow.CornerRadius", new VisualPropertyData(View.Property.SHADOW, Visual.Property.CornerRadius, ObjectIntToFloat) }, { "boxShadow.Offset", new VisualPropertyData(View.Property.SHADOW, (int)VisualTransformPropertyType.Offset) }, { "boxShadow.Opacity", new VisualPropertyData(View.Property.SHADOW, Visual.Property.Opacity, ObjectIntToFloat) }, - { "cornerRadius", new VisualPropertyData(View.Property.BACKGROUND, Visual.Property.CornerRadius, ObjectIntToFloat, null, - new VisualPropertyData(View.Property.SHADOW, Visual.Property.CornerRadius, ObjectIntToFloat)) }, + { "cornerRadius", new VisualPropertyData(View.Property.BACKGROUND, Visual.Property.CornerRadius, ObjectVector4ToFloat, null, + new VisualPropertyData(View.Property.SHADOW, Visual.Property.CornerRadius, ObjectVector4ToFloat)) }, { "imageShadow.Offset", new VisualPropertyData(View.Property.SHADOW, (int)VisualTransformPropertyType.Offset) }, { "shadow.CornerRadius", new VisualPropertyData(View.Property.SHADOW, Visual.Property.CornerRadius, ObjectIntToFloat) }, }; @@ -209,6 +209,17 @@ namespace Tizen.NUI return value; } + private static object ObjectVector4ToFloat(object value) + { + Type type = value.GetType(); + if (type.Equals(typeof(Vector4))) + { + return ((Vector4)value).X; + } + + return value; + } + internal class SearchResult : Disposable { private readonly OOConverter objectConverter; diff --git a/src/Tizen.NUI/src/public/BaseComponents/ImageView.cs b/src/Tizen.NUI/src/public/BaseComponents/ImageView.cs index 1d5b02d..f0a5b1c 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/ImageView.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/ImageView.cs @@ -1227,9 +1227,11 @@ namespace Tizen.NUI.BaseComponents imageMap?.Insert(NpatchImageVisualProperty.SynchronousLoading, synchronosLoading); synchronosLoading?.Dispose(); - if (backgroundExtraData != null && backgroundExtraData.CornerRadius > 0) + if (backgroundExtraData != null && backgroundExtraData.CornerRadius != null) { - using (var cornerRadius = new PropertyValue(backgroundExtraData.CornerRadius)) + // TODO Fix to support Vector4 for corner radius after dali support it. + // Current code only gets first argument of Vector4. + using (var cornerRadius = new PropertyValue(backgroundExtraData.CornerRadius.X)) using (var cornerRadiusPolicy = new PropertyValue((int)backgroundExtraData.CornerRadiusPolicy)) { imageMap.Insert(Visual.Property.CornerRadius, cornerRadius); diff --git a/src/Tizen.NUI/src/public/BaseComponents/Style/ViewStyle.cs b/src/Tizen.NUI/src/public/BaseComponents/Style/ViewStyle.cs index 98eb2de..516c446 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/Style/ViewStyle.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/Style/ViewStyle.cs @@ -48,7 +48,7 @@ namespace Tizen.NUI.BaseComponents private Size size; private Extents margin; private bool? themeChangeSensitive; - private float? cornerRadius; + private Vector4 cornerRadius; private Selector imageShadow; private Selector boxShadow; @@ -352,12 +352,13 @@ namespace Tizen.NUI.BaseComponents } /// - /// The radius for the rounded corners of the View + /// The radius for the rounded corners of the View. + /// The values in Vector4 are used in clockwise order from top-left to bottom-left : Vector4(top-left-corner, top-right-corner, bottom-right-corner, bottom-left-corner). /// [EditorBrowsable(EditorBrowsableState.Never)] - public float? CornerRadius + public Vector4 CornerRadius { - get => (float?)GetValue(CornerRadiusProperty); + get => (Vector4)GetValue(CornerRadiusProperty); set => SetValue(CornerRadiusProperty, value); } diff --git a/src/Tizen.NUI/src/public/BaseComponents/Style/ViewStyleBindableProperty.cs b/src/Tizen.NUI/src/public/BaseComponents/Style/ViewStyleBindableProperty.cs index 8804149..ba2f38e 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/Style/ViewStyleBindableProperty.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/Style/ViewStyleBindableProperty.cs @@ -373,10 +373,10 @@ namespace Tizen.NUI.BaseComponents /// Bindable property of CornerRadius. Please do not open it. [EditorBrowsable(EditorBrowsableState.Never)] - public static readonly BindableProperty CornerRadiusProperty = BindableProperty.Create(nameof(CornerRadius), typeof(float?), typeof(ViewStyle), null, - propertyChanged: (bindable, oldValue, newValue) => ((ViewStyle)bindable).cornerRadius = (float?)newValue, - defaultValueCreator: (bindable) => ((ViewStyle)bindable).cornerRadius - ); + public static readonly BindableProperty CornerRadiusProperty = BindableProperty.Create(nameof(CornerRadius), typeof(Vector4), typeof(ViewStyle), null, propertyChanged: (bindable, oldValue, newValue) => + { + ((ViewStyle)bindable).cornerRadius = (Vector4)newValue; + }, defaultValueCreator: (bindable) => ((ViewStyle)bindable).cornerRadius); /// Bindable property of CornerRadiusPolicy. Please do not open it. [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/Tizen.NUI/src/public/BaseComponents/View.cs b/src/Tizen.NUI/src/public/BaseComponents/View.cs index 17dfed3..12f4ffb 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/View.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/View.cs @@ -465,6 +465,7 @@ namespace Tizen.NUI.BaseComponents /// /// The radius for the rounded corners of the View. /// This will rounds background and shadow edges. + /// The values in Vector4 are used in clockwise order from top-left to bottom-left : Vector4(top-left-corner, top-right-corner, bottom-right-corner, bottom-left-corner). /// Note that, an image background (or shadow) may not have rounded corners if it uses a Border property. /// /// @@ -473,11 +474,11 @@ namespace Tizen.NUI.BaseComponents /// /// [EditorBrowsable(EditorBrowsableState.Never)] - public float CornerRadius + public Vector4 CornerRadius { get { - return (float)GetValue(CornerRadiusProperty); + return (Vector4)GetValue(CornerRadiusProperty); } set { diff --git a/src/Tizen.NUI/src/public/BaseComponents/ViewBindableProperty.cs b/src/Tizen.NUI/src/public/BaseComponents/ViewBindableProperty.cs index e2507d0..32038e7 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/ViewBindableProperty.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/ViewBindableProperty.cs @@ -91,9 +91,13 @@ namespace Tizen.NUI.BaseComponents PropertyMap map = new PropertyMap(); + // TODO Fix to support Vector4 for corner radius after dali support it. + // Current code only gets first argument of Vector4. + float cornerRadius = view.backgroundExtraData.CornerRadius?.X ?? 0.0f; + map.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.Color)) .Add(ColorVisualProperty.MixColor, new PropertyValue((Color)newValue)) - .Add(Visual.Property.CornerRadius, new PropertyValue(view.backgroundExtraData.CornerRadius)) + .Add(Visual.Property.CornerRadius, new PropertyValue(cornerRadius)) .Add(Visual.Property.CornerRadiusPolicy, new PropertyValue((int)(view.backgroundExtraData.CornerRadiusPolicy))); Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)view.SwigCPtr, View.Property.BACKGROUND, new PropertyValue(map)); @@ -165,8 +169,12 @@ namespace Tizen.NUI.BaseComponents PropertyMap map = new PropertyMap(); + // TODO Fix to support Vector4 for corner radius after dali support it. + // Current code only gets first argument of Vector4. + float cornerRadius = view.backgroundExtraData.CornerRadius?.X ?? 0.0f; + map.Add(ImageVisualProperty.URL, new PropertyValue(url)) - .Add(Visual.Property.CornerRadius, new PropertyValue(view.backgroundExtraData.CornerRadius)) + .Add(Visual.Property.CornerRadius, new PropertyValue(cornerRadius)) .Add(Visual.Property.CornerRadiusPolicy, new PropertyValue((int)(view.backgroundExtraData.CornerRadiusPolicy))) .Add(ImageVisualProperty.SynchronousLoading, new PropertyValue(view.backgroundImageSynchronosLoading)); @@ -1573,10 +1581,10 @@ namespace Tizen.NUI.BaseComponents /// CornerRadius Property /// [EditorBrowsable(EditorBrowsableState.Never)] - public static readonly BindableProperty CornerRadiusProperty = BindableProperty.Create(nameof(CornerRadius), typeof(float), typeof(View), default(float), propertyChanged: (bindable, oldValue, newValue) => + public static readonly BindableProperty CornerRadiusProperty = BindableProperty.Create(nameof(CornerRadius), typeof(Vector4), typeof(View), null, propertyChanged: (bindable, oldValue, newValue) => { var view = (View)bindable; - (view.backgroundExtraData ?? (view.backgroundExtraData = new BackgroundExtraData())).CornerRadius = (float)newValue; + (view.backgroundExtraData ?? (view.backgroundExtraData = new BackgroundExtraData())).CornerRadius = (Vector4)newValue; view.ApplyCornerRadius(); }, defaultValueCreator: (bindable) => @@ -1593,7 +1601,11 @@ namespace Tizen.NUI.BaseComponents { var view = (View)bindable; (view.backgroundExtraData ?? (view.backgroundExtraData = new BackgroundExtraData())).CornerRadiusPolicy = (VisualTransformPolicyType)newValue; - if (view.backgroundExtraData.CornerRadius != 0) + + // TODO Fix to support Vector4 for corner radius after dali support it. + // Current code only gets first argument of Vector4. + float cornerRadius = view.backgroundExtraData.CornerRadius?.X ?? 0.0f; + if (cornerRadius != 0) { view.ApplyCornerRadius(); } diff --git a/src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs b/src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs index a448d26..e4b0d75 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs @@ -1052,12 +1052,16 @@ namespace Tizen.NUI.BaseComponents { if (backgroundExtraData == null) return; + // TODO Fix to support Vector4 for corner radius after dali support it. + // Current code only gets first argument of Vector4. + float cornerRadius = backgroundExtraData.CornerRadius?.X ?? 0.0f; + // Apply to the background visual PropertyMap backgroundMap = new PropertyMap(); PropertyValue background = Tizen.NUI.Object.GetProperty(SwigCPtr, View.Property.BACKGROUND); if (background.Get(backgroundMap) && !backgroundMap.Empty()) { - backgroundMap[Visual.Property.CornerRadius] = new PropertyValue(backgroundExtraData.CornerRadius); + backgroundMap[Visual.Property.CornerRadius] = new PropertyValue(cornerRadius); backgroundMap[Visual.Property.CornerRadiusPolicy] = new PropertyValue((int)backgroundExtraData.CornerRadiusPolicy); var temp = new PropertyValue(backgroundMap); Tizen.NUI.Object.SetProperty(SwigCPtr, View.Property.BACKGROUND, temp); @@ -1071,7 +1075,7 @@ namespace Tizen.NUI.BaseComponents PropertyValue shadow = Tizen.NUI.Object.GetProperty(SwigCPtr, View.Property.SHADOW); if (shadow.Get(shadowMap) && !shadowMap.Empty()) { - shadowMap[Visual.Property.CornerRadius] = new PropertyValue(backgroundExtraData.CornerRadius); + shadowMap[Visual.Property.CornerRadius] = new PropertyValue(cornerRadius); shadowMap[Visual.Property.CornerRadiusPolicy] = new PropertyValue((int)backgroundExtraData.CornerRadiusPolicy); var temp = new PropertyValue(shadowMap); Tizen.NUI.Object.SetProperty(SwigCPtr, View.Property.SHADOW, temp); diff --git a/src/Tizen.NUI/src/public/Common/Vector4.cs b/src/Tizen.NUI/src/public/Common/Vector4.cs index 9e4b37a..574c25e 100755 --- a/src/Tizen.NUI/src/public/Common/Vector4.cs +++ b/src/Tizen.NUI/src/public/Common/Vector4.cs @@ -676,6 +676,16 @@ namespace Tizen.NUI } /// + /// Converts the float value to Vector4 class implicitly. + /// + /// A float value to be converted to Vector4 + [EditorBrowsable(EditorBrowsableState.Never)] + public static implicit operator Vector4(float value) + { + return new Vector4(value, value, value, value); + } + + /// /// Determines whether the specified object is equal to the current object. /// /// The object to compare with the current object. diff --git a/src/Tizen.NUI/src/public/ViewProperty/BackgroundExtraData.cs b/src/Tizen.NUI/src/public/ViewProperty/BackgroundExtraData.cs index 79c8264..6eb3fa9 100755 --- a/src/Tizen.NUI/src/public/ViewProperty/BackgroundExtraData.cs +++ b/src/Tizen.NUI/src/public/ViewProperty/BackgroundExtraData.cs @@ -45,7 +45,7 @@ namespace Tizen.NUI } /// - internal float CornerRadius { get; set; } + internal Vector4 CornerRadius { get; set; } /// /// Whether the CornerRadius value is relative (percentage [0.0f to 1.0f] of the view size) or absolute (in world units). diff --git a/src/Tizen.NUI/src/public/ViewProperty/ShadowBase.cs b/src/Tizen.NUI/src/public/ViewProperty/ShadowBase.cs index c6e86d6..3fda8b2 100755 --- a/src/Tizen.NUI/src/public/ViewProperty/ShadowBase.cs +++ b/src/Tizen.NUI/src/public/ViewProperty/ShadowBase.cs @@ -163,9 +163,13 @@ namespace Tizen.NUI var map = GetPropertyMap(); - if (attachedView.CornerRadius > 0) + // TODO Fix to support Vector4 for corner radius after dali support it. + // Current code only gets first argument of Vector4. + float cornerRadius = attachedView.CornerRadius?.X ?? 0.0f; + + if (cornerRadius > 0) { - map[Visual.Property.CornerRadius] = new PropertyValue(attachedView.CornerRadius); + map[Visual.Property.CornerRadius] = new PropertyValue(cornerRadius); map[Visual.Property.CornerRadiusPolicy] = new PropertyValue((int)attachedView.CornerRadiusPolicy); } -- 2.7.4