[NUI] Rotary Event (Custom Wheel Type) improvement
authorjoogab.yun <joogab.yun@samsung.com>
Tue, 25 Jan 2022 02:20:41 +0000 (11:20 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Tue, 22 Feb 2022 06:15:10 +0000 (15:15 +0900)
Previously, RotaryEvents could always be received only by window.
Now, User can receive Rotary Events in focused View as well.
It is also possible to propagate events to the parent view.

If there is no focused View, the window will receive the event.

This only applies to Rotary Event(CustomWheel type).

src/Tizen.NUI/src/public/BaseComponents/ViewEvent.cs
src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/TouchGestureSample.cs

index 748ad7f..77617bb 100755 (executable)
@@ -391,12 +391,6 @@ namespace Tizen.NUI.BaseComponents
                     signal?.Connect(wheelEventCallback);
                 }
                 wheelEventHandler += value;
-
-                if (WindowWheelEventHandler == null)
-                {
-                    NUIApplication.GetDefaultWindow().WheelEvent += OnWindowWheelEvent;
-                }
-                WindowWheelEventHandler += value;
             }
 
             remove
@@ -414,12 +408,6 @@ namespace Tizen.NUI.BaseComponents
                         }
                     }
                 }
-
-                WindowWheelEventHandler -= value;
-                if (WindowWheelEventHandler == null)
-                {
-                    NUIApplication.GetDefaultWindow().WheelEvent -= OnWindowWheelEvent;
-                }
             }
         }
 
@@ -1368,22 +1356,6 @@ namespace Tizen.NUI.BaseComponents
             public ControlState CurrentState { get; }
         }
 
-        private EventHandlerWithReturnType<object, WheelEventArgs, bool> WindowWheelEventHandler;
-        private void OnWindowWheelEvent(object sender, Window.WheelEventArgs e)
-        {
-            if (e != null)
-            {
-                if (e.Wheel.Type == Wheel.WheelType.CustomWheel)
-                {
-                    var arg = new WheelEventArgs()
-                    {
-                        Wheel = e.Wheel,
-                    };
-                    WindowWheelEventHandler?.Invoke(this, arg);
-                }
-            }
-        }
-
         /// <summary>
         /// The expanded touch area.
         /// TouchArea can expand the view's touchable area.<br/>
index 4a0fdb2..212cea8 100755 (executable)
@@ -1325,14 +1325,6 @@ namespace Tizen.NUI.BaseComponents
                 wheelEventCallback = null;
             }
 
-            if (WindowWheelEventHandler != null)
-            {
-                NUILog.Debug($"[Dispose] WindowWheelEventHandler");
-
-                NUIApplication.GetDefaultWindow().WheelEvent -= OnWindowWheelEvent;
-                WindowWheelEventHandler = null;
-            }
-
             if (hoverEventCallback != null)
             {
                 NUILog.Debug($"[Dispose] hoverEventCallback");
index 08d558c..254e090 100755 (executable)
@@ -19,14 +19,43 @@ namespace Tizen.NUI.Samples
             Window window = NUIApplication.GetDefaultWindow();
             root = new View();
 
+            window.WheelEvent += (s, e) =>
+            {
+                Tizen.Log.Error("NUI", $"window WheelEvent!!!!{e.Wheel.Type}\n");
+            };
 
-           frontView = new View
+            frontView = new View
             {
                 Size = new Size(300, 300),
                 Position = new Position(150, 170),
                 BackgroundColor = new Color(1.0f, 0.0f, 0.0f, 1.0f),
+                Focusable = true,
+                FocusableInTouch = true,
             };
             frontView.TouchEvent += OnFrontTouchEvent;
+            frontView.WheelEvent += (s, e) =>
+            {
+                Tizen.Log.Error("NUI", $"frontView WheelEvent!!!!{e.Wheel.Type}\n");
+                if (e.Wheel.Type == Wheel.WheelType.CustomWheel)
+                {
+                       // rotary event
+                }
+                else if (e.Wheel.Type == Wheel.WheelType.MouseWheel)
+                {
+                      // mouse wheel event
+                }
+                return false;
+            };
+
+            var middleView = new View
+            {
+                Size = new Size(300, 300),
+                Position = new Position(110, 120),
+                BackgroundColor = new Color(0.0f, 1.0f, 0.0f, 1.0f),
+                Focusable = true,
+                FocusableInTouch = true,
+            };
+
 
             // The default the maximum allowed time is 500ms.
             // If you want to change this time, do as below.
@@ -47,8 +76,15 @@ namespace Tizen.NUI.Samples
                 Position = new Position(50, 70),
                 PointSize = 11,
                 BackgroundColor = new Color(1.0f, 1.0f, 0.0f, 1.0f),
+                Focusable = true,
+                FocusableInTouch = true,
             };
             backView.TouchEvent += OnBackTouchEvent;
+            backView.WheelEvent += (s, e) =>
+            {
+                Tizen.Log.Error("NUI", $"backView WheelEvent!!!!{e.Wheel.Type}\n");
+                return true;
+            };
 
             // The default the minimum holding time is 500ms.
             // If you want to change this time, do as below.
@@ -62,6 +98,7 @@ namespace Tizen.NUI.Samples
               Tizen.Log.Error("NUI", $"OnLongPress\n");
             };
 
+            backView.Add(middleView);
             backView.Add(frontView);
             root.Add(backView);
             window.Add(root);