[NUI] Add SetDefaultGrabTouchAfterLeave api.
authorjoogab.yun <joogab.yun@samsung.com>
Wed, 30 Mar 2022 05:47:00 +0000 (14:47 +0900)
committerJaehyun Cho <jaehyun0cho@gmail.com>
Wed, 20 Apr 2022 08:38:08 +0000 (17:38 +0900)
1. Add SetDefaultGrabTouchAfterLeave(bool enable) in NUIApplication
```c#
   // If this is set to true, all views are created with GrabTouchAfterLeave set to true.
   View.SetDefaultGrabTouchAfterLeave(true);
```

src/Tizen.NUI/src/public/BaseComponents/View.cs
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/DefaultGrabTouchAfterLeaveSample.cs [new file with mode: 0644]

index 1d7a348..16140f2 100755 (executable)
@@ -31,6 +31,7 @@ namespace Tizen.NUI.BaseComponents
         private static HashSet<BindableProperty> positionPropertyGroup = new HashSet<BindableProperty>();
         private static HashSet<BindableProperty> sizePropertyGroup = new HashSet<BindableProperty>();
         private static HashSet<BindableProperty> scalePropertyGroup = new HashSet<BindableProperty>();
+        private static bool defaultGrabTouchAfterLeave = false;
 
         internal BackgroundExtraData backgroundExtraData;
 
@@ -152,6 +153,7 @@ namespace Tizen.NUI.BaseComponents
                 SetVisible(false);
             }
 
+            GrabTouchAfterLeave = defaultGrabTouchAfterLeave;
         }
 
         internal View(ViewImpl implementation, bool shown = true) : this(Interop.View.NewViewInternal(ViewImpl.getCPtr(implementation)), true)
@@ -196,6 +198,16 @@ namespace Tizen.NUI.BaseComponents
         public static bool LayoutingDisabled { get; set; } = true;
 
         /// <summary>
+        /// If set to true, the <see cref="GrabTouchAfterLeave"/> property value is set to true when all Views are created.
+        /// </summary>
+        /// <param name="enable">Sets value of GrabTouchAfterLeave property</param>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static void SetDefaultGrabTouchAfterLeave(bool enable)
+        {
+            defaultGrabTouchAfterLeave = enable;
+        }
+
+        /// <summary>
         /// Deprecate. Please do not use this.
         /// The style instance applied to this view.
         /// Note that please do not modify the ViewStyle.
diff --git a/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/DefaultGrabTouchAfterLeaveSample.cs b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/DefaultGrabTouchAfterLeaveSample.cs
new file mode 100644 (file)
index 0000000..53234cf
--- /dev/null
@@ -0,0 +1,110 @@
+using Tizen.NUI;
+using Tizen.NUI.BaseComponents;
+using Tizen.NUI.Components;
+using Tizen.NUI.Events;
+
+
+namespace Tizen.NUI.Samples
+{
+    public class DefaultGrabTouchAfterLeaveSample : IExample
+    {
+        private View root;
+
+        public void Activate()
+        {
+            Window window = NUIApplication.GetDefaultWindow();
+            // If this is set to true, all views are created with GrabTouchAfterLeave set to true.
+            View.SetDefaultGrabTouchAfterLeave(true);
+
+            root = new View
+            {
+                Layout = new AbsoluteLayout(),
+                WidthResizePolicy = ResizePolicyType.FillToParent,
+                HeightResizePolicy = ResizePolicyType.FillToParent,
+            };
+
+            var textLabel = new TextLabel
+            {
+                Size = new Size(300, 300),
+                MultiLine = true,
+                BackgroundColor = Color.Grey,
+                WidthSpecification = LayoutParamPolicies.MatchParent,
+            };
+
+            // greenView is created with the size 250x250 and GrabTouchAfterLeave=true
+            var greenView = new View()
+            {
+                Size = new Size(300, 300),
+                Position = new Position(50, 320),
+                BackgroundColor = Color.Green,
+            };
+            textLabel.Text ="greenView GrabTouchAfterLeave : "+greenView.GrabTouchAfterLeave;
+
+            greenView.TouchEvent += (s, e) =>
+            {
+                Tizen.Log.Error("NUI", $"greenView {e.Touch.GetState(0)}\n");
+                return true;
+            };
+
+            // If userTheme is applied,
+            Theme userTheme = new Theme();
+            userTheme.AddStyle("Tizen.NUI.BaseComponents.TextLabel",  new TextLabelStyle()
+            {
+                Size = new Size(500, 500),
+            });
+            ThemeManager.ApplyTheme(userTheme);
+
+            // BlueView is created with size 500x500 defined in userTheme and GrabTouchAfterLeave=true
+            var blueView = new TextLabel
+            (new TextLabelStyle
+            {
+                Size = new Size(300, 300),
+                Text = "BlueView",
+            })
+            {
+                Position = new Position(10, 100),
+                BackgroundColor = Color.Blue,
+            };
+            textLabel.Text +="\nblueView GrabTouchAfterLeave : "+blueView.GrabTouchAfterLeave;
+            blueView.TouchEvent += (s, e) =>
+            {
+                Tizen.Log.Error("NUI", $"blueView {e.Touch.GetState(0)}\n");
+                return true;
+            };
+
+            // BlueView is created with size 100x100 defined in userStyle and GrabTouchAfterLeave=true
+            var redView = new TextLabel
+            (new TextLabelStyle
+            {
+                PixelSize = 24,
+                Size = new Size(100, 100),
+            })
+            {
+                Text = "RedView",
+                Position = new Position(50, 120),
+                BackgroundColor = Color.Red,
+            };
+            textLabel.Text +="\redView GrabTouchAfterLeave : "+redView.GrabTouchAfterLeave;
+            redView.TouchEvent += (s, e) =>
+            {
+                Tizen.Log.Error("NUI", $"redView {e.Touch.GetState(0)}\n");
+                return true;
+            };
+
+            greenView.Add(blueView);
+            blueView.Add(redView);
+            root.Add(textLabel);
+            root.Add(greenView);
+            window.Add(root);
+        }
+
+        public void Deactivate()
+        {
+            if (root != null)
+            {
+                NUIApplication.GetDefaultWindow().Remove(root);
+                root.Dispose();
+            }
+        }
+    }
+}