[NUI] Introduce CornerRadiusPolicy to View
authorJiyun Yang <ji.yang@samsung.com>
Mon, 9 Nov 2020 11:50:02 +0000 (20:50 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Tue, 8 Dec 2020 06:23:12 +0000 (15:23 +0900)
The CornerRadiusPolicy indicates whether the CornerRadius value is relative or absolute.
The default policy is absolute, which means the CornerRadius is an absolute float length.
If the policy is relative, the CornerRadius can have percentage value between 0.0f to 1.0f,
that is relative to the smaller of view's width and height.

Signed-off-by: Jiyun Yang <ji.yang@samsung.com>
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/ViewProperty/BackgroundExtraData.cs
src/Tizen.NUI/src/public/ViewProperty/ShadowBase.cs
src/Tizen.NUI/src/public/VisualConstants.cs
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/ControlSample.cs

index d31994a..5cd074a 100755 (executable)
@@ -1028,9 +1028,9 @@ namespace Tizen.NUI.BaseComponents
             return ret;
         }
 
-        internal override void UpdateCornerRadius(float value)
+        internal override void ApplyCornerRadius()
         {
-            base.UpdateCornerRadius(value);
+            base.ApplyCornerRadius();
 
             UpdateImage(0, null);
         }
index d79ecd6..c7e6a6a 100755 (executable)
@@ -84,6 +84,7 @@ namespace Tizen.NUI.BaseComponents
         private Selector<Color> backgroundColorSelector;
         private Selector<Rectangle> backgroundImageBorderSelector;
         private Selector<Color> colorSelector;
+        private VisualTransformPolicyType? cornerRadiusPolicy;
 
         static ViewStyle() { }
 
@@ -677,6 +678,18 @@ namespace Tizen.NUI.BaseComponents
         }
 
         /// <summary>
+        /// Whether the CornerRadius property value is relative (percentage [0.0f to 1.0f] of the view size) or absolute (in world units).
+        /// It is absolute by default.
+        /// When the policy is relative, the corner radius is relative to the smaller of the view's width and height.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public VisualTransformPolicyType? CornerRadiusPolicy
+        {
+            get => (VisualTransformPolicyType?)GetValue(CornerRadiusPolicyProperty);
+            set => SetValue(CornerRadiusPolicyProperty, value);
+        }
+
+        /// <summary>
         /// The EnableControlState value of the View.
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
index b254945..8f0a3ad 100755 (executable)
@@ -868,6 +868,13 @@ namespace Tizen.NUI.BaseComponents
             return viewStyle.cornerRadius;
         });
 
+        /// <summary> A BindableProperty for CornerRadiusPolicy </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static readonly BindableProperty CornerRadiusPolicyProperty = BindableProperty.Create(nameof(CornerRadiusPolicy), typeof(VisualTransformPolicyType?), typeof(ViewStyle), null,
+            propertyChanged: (bindable, oldValue, newValue) => ((ViewStyle)bindable).cornerRadiusPolicy = (VisualTransformPolicyType?)newValue,
+            defaultValueCreator: (bindable) => ((ViewStyle)bindable).cornerRadiusPolicy
+        );
+
         /// <summary>
         /// EnableControlState property
         /// </summary>
index ea8cae1..27cddc5 100755 (executable)
@@ -447,6 +447,18 @@ namespace Tizen.NUI.BaseComponents
         }
 
         /// <summary>
+        /// Whether the CornerRadius property value is relative (percentage [0.0f to 1.0f] of the view size) or absolute (in world units).
+        /// It is absolute by default.
+        /// When the policy is relative, the corner radius is relative to the smaller of the view's width and height.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public VisualTransformPolicyType CornerRadiusPolicy
+        {
+            get => (VisualTransformPolicyType)GetValue(CornerRadiusPolicyProperty);
+            set => SetValue(CornerRadiusPolicyProperty, value);
+        }
+
+        /// <summary>
         /// The current state of the view.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
index 1a76b84..f6f8ade 100755 (executable)
@@ -1567,7 +1567,8 @@ namespace Tizen.NUI.BaseComponents
         public static readonly BindableProperty CornerRadiusProperty = BindableProperty.Create(nameof(CornerRadius), typeof(float), typeof(View), default(float), propertyChanged: (bindable, oldValue, newValue) =>
         {
             var view = (View)bindable;
-            view.UpdateCornerRadius((float)newValue);
+            (view.backgroundExtraData ?? (view.backgroundExtraData = new BackgroundExtraData())).CornerRadius = (float)newValue;
+            view.ApplyCornerRadius();
         },
         defaultValueCreator: (bindable) =>
         {
@@ -1576,6 +1577,25 @@ namespace Tizen.NUI.BaseComponents
         });
 
         /// <summary>
+        /// CornerRadiusPolicy Property
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static readonly BindableProperty CornerRadiusPolicyProperty = BindableProperty.Create(nameof(CornerRadiusPolicy), typeof(VisualTransformPolicyType), typeof(View), VisualTransformPolicyType.Absolute, propertyChanged: (bindable, oldValue, newValue) =>
+        {
+            var view = (View)bindable;
+            (view.backgroundExtraData ?? (view.backgroundExtraData = new BackgroundExtraData())).CornerRadiusPolicy = (VisualTransformPolicyType)newValue;
+            if (view.backgroundExtraData.CornerRadius != 0)
+            {
+                view.ApplyCornerRadius();
+            }
+        },
+        defaultValueCreator: (bindable) =>
+        {
+            var view = (View)bindable;
+            return view.backgroundExtraData == null ? VisualTransformPolicyType.Absolute : view.backgroundExtraData.CornerRadiusPolicy;
+        });
+
+        /// <summary>
         /// EnableControlState property
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
index e7ce022..4c24089 100755 (executable)
@@ -1068,27 +1068,34 @@ namespace Tizen.NUI.BaseComponents
             return (ResourceLoadingStatusType)Interop.View.View_GetVisualResourceStatus(this.swigCPtr, Property.BACKGROUND);
         }
 
-        internal virtual void UpdateCornerRadius(float value)
+        /// TODO open as a protected level
+        internal virtual void ApplyCornerRadius()
         {
-            if (value != 0)
-            {
-                (backgroundExtraData ?? (backgroundExtraData = new BackgroundExtraData())).CornerRadius = value;
-            }
+            if (backgroundExtraData == null) return;
 
-            Tizen.NUI.PropertyMap backgroundMap = new Tizen.NUI.PropertyMap();
+            // Apply to the background visual
+            PropertyMap backgroundMap = new PropertyMap();
             PropertyValue background = Tizen.NUI.Object.GetProperty(swigCPtr, View.Property.BACKGROUND);
-            background?.Get(backgroundMap);
+            if (background.Get(backgroundMap) && !backgroundMap.Empty())
+            {
+                backgroundMap[Visual.Property.CornerRadius] = new PropertyValue(backgroundExtraData.CornerRadius);
+                backgroundMap[Visual.Property.CornerRadiusPolicy] = new PropertyValue((int)backgroundExtraData.CornerRadiusPolicy);
+                Tizen.NUI.Object.SetProperty(swigCPtr, View.Property.BACKGROUND, new PropertyValue(backgroundMap));
+            }
+            backgroundMap.Dispose();
+            background.Dispose();
 
-            if (!backgroundMap.Empty())
+            // Apply to the shadow visual
+            PropertyMap shadowMap = new PropertyMap();
+            PropertyValue shadow = Tizen.NUI.Object.GetProperty(swigCPtr, View.Property.SHADOW);
+            if (shadow.Get(shadowMap) && !shadowMap.Empty())
             {
-                backgroundMap[Visual.Property.CornerRadius] = new PropertyValue(value);
-                PropertyValue setValue = new Tizen.NUI.PropertyValue(backgroundMap);
-                Tizen.NUI.Object.SetProperty(swigCPtr, View.Property.BACKGROUND, setValue);
-                setValue?.Dispose();
+                shadowMap[Visual.Property.CornerRadius] = new PropertyValue(backgroundExtraData.CornerRadius);
+                shadowMap[Visual.Property.CornerRadiusPolicy] = new PropertyValue((int)backgroundExtraData.CornerRadiusPolicy);
+                Tizen.NUI.Object.SetProperty(swigCPtr, View.Property.SHADOW, new PropertyValue(shadowMap));
             }
-            UpdateShadowCornerRadius(value);
-            backgroundMap?.Dispose();
-            background?.Dispose();
+            shadowMap.Dispose();
+            shadow.Dispose();
         }
 
         internal void UpdateStyle()
@@ -1388,24 +1395,6 @@ namespace Tizen.NUI.BaseComponents
             SizeModeFactor = new Vector3(x, y, z);
         }
 
-        private void UpdateShadowCornerRadius(float value)
-        {
-            // TODO Update corner radius property only whe DALi supports visual property update.
-            PropertyMap map = new PropertyMap();
-
-            PropertyValue shadowVal = Tizen.NUI.Object.GetProperty(swigCPtr, View.Property.SHADOW);
-            if (shadowVal.Get(map) && !map.Empty())
-            {
-                map[Visual.Property.CornerRadius] = new PropertyValue(value);
-
-                PropertyValue setValue = new PropertyValue(map);
-                Tizen.NUI.Object.SetProperty(swigCPtr, View.Property.SHADOW, setValue);
-                setValue?.Dispose();
-            }
-            map?.Dispose();
-            shadowVal?.Dispose();
-        }
-
         private bool EmptyOnTouch(object target, TouchEventArgs args)
         {
             return false;
index 621e531..8d95088 100644 (file)
@@ -44,6 +44,11 @@ namespace Tizen.NUI
         /// <summary></summary>
         internal float 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).
+        /// </summary>
+        internal VisualTransformPolicyType CornerRadiusPolicy { get; set; } = VisualTransformPolicyType.Absolute;
+
         internal bool Empty()
         {
             return CornerRadius == 0 && Rectangle.IsNullOrZero(BackgroundImageBorder);
index ee9a8fa..2af8dae 100755 (executable)
@@ -162,10 +162,9 @@ namespace Tizen.NUI
             if (attachedView.CornerRadius > 0)
             {
                 map[Visual.Property.CornerRadius] = new PropertyValue(attachedView.CornerRadius);
+                map[Visual.Property.CornerRadiusPolicy] = new PropertyValue((int)attachedView.CornerRadiusPolicy);
             }
 
-            map[Visual.Property.Transform] = GetTransformMap();
-
             return new PropertyValue(map);
         }
 
@@ -177,6 +176,8 @@ namespace Tizen.NUI
         {
             PropertyMap map = new PropertyMap();
 
+            map[Visual.Property.Transform] = GetTransformMap();
+
             return map;
         }
 
index f70b0b3..81485ba 100755 (executable)
@@ -493,6 +493,12 @@ namespace Tizen.NUI
             /// </summary>
             [EditorBrowsable(EditorBrowsableState.Never)]
             public static readonly int CornerRadius = NDalic.VISUAL_PROPERTY_MIX_COLOR + 3;
+            /// <summary>
+            /// The corner radius policy of the visual.
+            /// Whether the corner radius value is relative (percentage [0.0f to 1.0f] of the visual size) or absolute (in world units).
+            /// </summary>
+            [EditorBrowsable(EditorBrowsableState.Never)]
+            public static readonly int CornerRadiusPolicy = NDalic.VISUAL_PROPERTY_MIX_COLOR + 4;
         }
 
         /// <summary>
index 66cfca0..a799955 100644 (file)
@@ -35,10 +35,17 @@ namespace Tizen.NUI.Samples
                     Color = new Color(0.2f, 0.2f, 0.2f, 0.3f),
                     Offset = new Vector2(5, 5),
                 },
-                CornerRadius = 26f,
+                CornerRadius = 0.5f,
+                CornerRadiusPolicy = VisualTransformPolicyType.Relative,
             };
 
             root.Add(control);
+
+            var animation = new Animation(2000);
+            animation.AnimateTo(control, "SizeWidth", 200, 0, 1000);
+            animation.AnimateTo(control, "SizeWidth", 100, 1000, 2000);
+            animation.Looping = true;
+            animation.Play();
         }
 
         public void Deactivate()