[NUI] Enable BackgroundImageBorder in View (#1268)
authorJiyun Yang <ji.yang@samsung.com>
Fri, 3 Jan 2020 08:05:19 +0000 (17:05 +0900)
committerGitHub <noreply@github.com>
Fri, 3 Jan 2020 08:05:19 +0000 (17:05 +0900)
Signed-off-by: Jiyun Yang <ji.yang@samsung.com>
src/Tizen.NUI/src/public/BaseComponents/Style/ViewStyle.cs
src/Tizen.NUI/src/public/BaseComponents/ViewBindableProperty.cs
src/Tizen.NUI/src/public/BaseComponents/ViewEvent.cs
src/Tizen.NUI/src/public/Rectangle.cs

index 89a2dca..b55d46e 100755 (executable)
@@ -792,7 +792,8 @@ namespace Tizen.NUI.BaseComponents
         {
             var viewStyle = (ViewStyle)bindable;
             if (null == viewStyle.backgroundImageBorderSelector) viewStyle.backgroundImageBorderSelector = new Selector<Rectangle>();
-            viewStyle.backgroundImageBorderSelector.Clone((Selector<Rectangle>)newValue);
+
+            viewStyle.backgroundImageBorderSelector.Clone(newValue == null ? new Rectangle() : (Selector<Rectangle>)newValue);
         },
         defaultValueCreator: (bindable) =>
         {
index 616e7b6..a185bd6 100755 (executable)
@@ -81,7 +81,20 @@ namespace Tizen.NUI.BaseComponents
             var view = (View)bindable;
             if (newValue != null)
             {
-                Tizen.NUI.Object.SetProperty(view.swigCPtr, View.Property.BACKGROUND, new Tizen.NUI.PropertyValue((string)newValue));
+                string url = (string)newValue;
+
+                if (Rectangle.IsNullOrZero(view.backgroundImageBorder))
+                {
+                    Tizen.NUI.Object.SetProperty(view.swigCPtr, View.Property.BACKGROUND, new PropertyValue(url));
+                }
+                else
+                {
+                    var visual = new NPatchVisual();
+                    visual.URL = url;
+                    visual.Border = view.backgroundImageBorder;
+                    Tizen.NUI.Object.SetProperty(view.swigCPtr, View.Property.BACKGROUND, new PropertyValue(visual.OutputVisualMap));
+                }
+
                 view.BackgroundImageSynchronosLoading = view._backgroundImageSynchronosLoading;
             }
         },
@@ -93,7 +106,7 @@ namespace Tizen.NUI.BaseComponents
             Tizen.NUI.PropertyMap background = view.Background;
             int visualType = 0;
             background.Find(Visual.Property.Type)?.Get(out visualType);
-            if (visualType == (int)Visual.Type.Image)
+            if ((visualType == (int)Visual.Type.Image) || (visualType == (int)Visual.Type.NPatch))
             {
                 background.Find(ImageVisualProperty.URL)?.Get(out backgroundImage);
             }
@@ -105,15 +118,30 @@ namespace Tizen.NUI.BaseComponents
         public static readonly BindableProperty BackgroundImageBorderProperty = BindableProperty.Create(nameof(BackgroundImageBorder), typeof(Rectangle), typeof(View), default(Rectangle), propertyChanged: (bindable, oldValue, newValue) =>
         {
             var view = (View)bindable;
-            if (null != newValue)
+            string url = view.BackgroundImage;
+            view.backgroundImageBorder = (Rectangle)newValue;
+
+            if (string.IsNullOrEmpty(url))
+            {
+                return;
+            }
+
+            if (Rectangle.IsNullOrZero(view.backgroundImageBorder))
+            {
+                Tizen.NUI.Object.SetProperty(view.swigCPtr, View.Property.BACKGROUND, new PropertyValue(url));
+            }
+            else
             {
-                view.backgroundImageBorder = (Rectangle)newValue;
+                var visual = new NPatchVisual();
+                visual.URL = url;
+                visual.Border = view.backgroundImageBorder;
+                Tizen.NUI.Object.SetProperty(view.swigCPtr, View.Property.BACKGROUND, new PropertyValue(visual.OutputVisualMap));
             }
         },
         defaultValueCreator: (bindable) =>
         {
             var view = (View)bindable;
-            return view.backgroundImageBorder;
+            return view.backgroundImageBorder == null ? new Rectangle(view.OnBackgroundImageBorderChanged) : new Rectangle(view.OnBackgroundImageBorderChanged, view.backgroundImageBorder);
         });
         /// <summary>
         /// BackgroundProperty
index d44e3d0..e586e16 100755 (executable)
@@ -614,6 +614,11 @@ namespace Tizen.NUI.BaseComponents
             BoxShadow = (Shadow)instance;
         }
 
+        private void OnBackgroundImageBorderChanged(int left, int right, int bottom, int top)
+        {
+            BackgroundImageBorder = new Rectangle(left, right, bottom, top);
+        }
+
         private void OnKeyInputFocusGained(IntPtr view)
         {
             if (_keyInputFocusGainedEventHandler != null)
index 903990e..5d992a5 100755 (executable)
@@ -58,6 +58,10 @@ namespace Tizen.NUI
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
+        internal Rectangle(RectangleChangedCallback cb) : this()
+        {
+        }
+
         internal Rectangle(RectangleChangedCallback cb, Rectangle other) : this(cb, other.x, other.y, other.width, other.height)
         {
         }
@@ -449,5 +453,10 @@ namespace Tizen.NUI
         {
             Interop.Rectangle.delete_Rectangle(swigCPtr);
         }
+
+        /// <summary>
+        /// Determines whether the reference is null or the Rectangle has all 0 properties.
+        /// </summary>
+        internal static bool IsNullOrZero(Rectangle rectangle) => (rectangle == null || (rectangle.top == 0 && rectangle.right == 0 && rectangle.bottom == 0 && rectangle.left == 0));
     }
 }
\ No newline at end of file