[NUI] Change CornerRadius type to Vector4 from float (#2863)
authorJiyun Yang <ji.yang@samsung.com>
Thu, 8 Apr 2021 07:32:32 +0000 (16:32 +0900)
committerbshsqa <32317749+bshsqa@users.noreply.github.com>
Wed, 14 Apr 2021 11:53:58 +0000 (20:53 +0900)
Note that, only X value of Vector4 will be applied to the view until dali support it.

Signed-off-by: Jiyun Yang <ji.yang@samsung.com>
src/Tizen.NUI/src/internal/Common/PropertyHelper.cs
src/Tizen.NUI/src/public/BaseComponents/ImageView.cs
src/Tizen.NUI/src/public/BaseComponents/Style/ViewStyle.cs
src/Tizen.NUI/src/public/BaseComponents/Style/ViewStyleBindableProperty.cs
src/Tizen.NUI/src/public/BaseComponents/View.cs
src/Tizen.NUI/src/public/BaseComponents/ViewBindableProperty.cs
src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs
src/Tizen.NUI/src/public/Common/Vector4.cs
src/Tizen.NUI/src/public/ViewProperty/BackgroundExtraData.cs
src/Tizen.NUI/src/public/ViewProperty/ShadowBase.cs

index 658464b..4be0347 100755 (executable)
@@ -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;
index 1d5b02d..f0a5b1c 100755 (executable)
@@ -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);
index 98eb2de..516c446 100755 (executable)
@@ -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> imageShadow;
         private Selector<Shadow> boxShadow;
@@ -352,12 +352,13 @@ namespace Tizen.NUI.BaseComponents
         }
 
         /// <summary>
-        /// 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).
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public float? CornerRadius
+        public Vector4 CornerRadius
         {
-            get => (float?)GetValue(CornerRadiusProperty);
+            get => (Vector4)GetValue(CornerRadiusProperty);
             set => SetValue(CornerRadiusProperty, value);
         }
 
index 8804149..ba2f38e 100755 (executable)
@@ -373,10 +373,10 @@ namespace Tizen.NUI.BaseComponents
 
         /// <summary> Bindable property of CornerRadius. Please do not open it. </summary>
         [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);
 
         /// <summary> Bindable property of CornerRadiusPolicy. Please do not open it. </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
index 17dfed3..12f4ffb 100755 (executable)
@@ -465,6 +465,7 @@ namespace Tizen.NUI.BaseComponents
         /// <summary>
         /// 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.
         /// </summary>
         /// <remarks>
@@ -473,11 +474,11 @@ namespace Tizen.NUI.BaseComponents
         /// </para>
         /// </remarks>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public float CornerRadius
+        public Vector4 CornerRadius
         {
             get
             {
-                return (float)GetValue(CornerRadiusProperty);
+                return (Vector4)GetValue(CornerRadiusProperty);
             }
             set
             {
index e2507d0..32038e7 100755 (executable)
@@ -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
         /// </summary>
         [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();
             }
index a448d26..e4b0d75 100755 (executable)
@@ -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);
index 9e4b37a..574c25e 100755 (executable)
@@ -676,6 +676,16 @@ namespace Tizen.NUI
         }
 
         /// <summary>
+        /// Converts the float value to Vector4 class implicitly.
+        /// </summary>
+        /// <param name="value">A float value to be converted to Vector4</param>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static implicit operator Vector4(float value)
+        {
+            return new Vector4(value, value, value, value);
+        }
+
+        /// <summary>
         /// Determines whether the specified object is equal to the current object.
         /// </summary>
         /// <param name="obj">The object to compare with the current object.</param>
index 79c8264..6eb3fa9 100755 (executable)
@@ -45,7 +45,7 @@ namespace Tizen.NUI
         }
 
         /// <summary></summary>
-        internal float CornerRadius { get; set; }
+        internal Vector4 CornerRadius { get; set; }
 
         /// <summary>
         /// Whether the CornerRadius value is relative (percentage [0.0f to 1.0f] of the view size) or absolute (in world units).
index c6e86d6..3fda8b2 100755 (executable)
@@ -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);
             }