[NUI] Add LazyFeedHover api for HoverEvent
authorjoogab.yun <joogab.yun@samsung.com>
Fri, 23 Jun 2023 08:10:28 +0000 (17:10 +0900)
committerBowon Ryu <wonrst22@naver.com>
Wed, 5 Jul 2023 07:42:04 +0000 (16:42 +0900)
This api feeds a hover event into the window.

refer :
https://review.tizen.org/gerrit/#/c/platform/core/uifw/dali-adaptor/+/294676/
https://review.tizen.org/gerrit/#/c/platform/core/uifw/dali-csharp-binder/+/294689/

src/Tizen.NUI/src/internal/Interop/Interop.Window.cs
src/Tizen.NUI/src/public/Window/Window.cs
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/ScrollableFocus/ScrollableFocusSample.cs

index b52d364..a453cc6 100755 (executable)
@@ -191,6 +191,9 @@ namespace Tizen.NUI
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Window_FeedWheel")]
             public static extern void FeedWheelEvent(global::System.Runtime.InteropServices.HandleRef window, global::System.Runtime.InteropServices.HandleRef wheelEvent);
 
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Window_FeedHover")]
+            public static extern void FeedHoverEvent(global::System.Runtime.InteropServices.HandleRef window, global::System.Runtime.InteropServices.HandleRef touchPoint);
+
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Adaptor_RenderOnce")]
             public static extern void RenderOnce(global::System.Runtime.InteropServices.HandleRef jarg1);
 
index 61eeafd..a6c6c42 100755 (executable)
@@ -43,6 +43,7 @@ namespace Tizen.NUI
         private LayoutController localController;
         private Key internalLastKeyEvent;
         private Touch internalLastTouchEvent;
+        private Timer internalHoverTimer;
 
         static internal bool IsSupportedMultiWindow()
         {
@@ -1134,6 +1135,36 @@ namespace Tizen.NUI
         }
 
         /// <summary>
+        /// Feeds a hover event into the window. <br />
+        /// This is feed after a default time of 48 ms. You can also set this time.
+        /// </summary>
+        /// <param name="time">The time of how much later it will be feed (default is 48ms)</param>
+        /// <remarks>If you want to do FeedHover after the UI is updated, it is recommended to set the time to at least 16ms. This will be a good time waiting for the UI to update.<br />
+        /// and LazyFeedHover called within the set time are ignored. Only the last request becomes a FeedHover.
+        /// </remarks>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void LazyFeedHover(uint time = 48)
+        {
+            if (internalHoverTimer == null)
+            {
+                internalHoverTimer = new Timer(time);
+                internalHoverTimer.Tick += (s, e) =>
+                {
+                    FeedHover();
+                    internalHoverTimer?.Stop();
+                    internalHoverTimer?.Dispose();
+                    internalHoverTimer = null;
+                    return false;
+                };
+                internalHoverTimer.Start();
+            }
+            else
+            {
+                internalHoverTimer.Start();
+            }
+        }
+
+        /// <summary>
         /// Feeds a touch point into the window.
         /// </summary>
         /// <param name="touchPoint">The touch point to feed.</param>
@@ -1155,6 +1186,23 @@ namespace Tizen.NUI
         }
 
         /// <summary>
+        /// Feeds a hover event into the window.
+        /// </summary>
+        /// <param name="touchPoint">The touch point to feed hover event. If null is entered, the feed hover event is generated with the last inputed touch point.</param>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        internal void FeedHover(TouchPoint touchPoint = null)
+        {
+            if (touchPoint == null)
+            {
+                using Touch touch = GetLastTouchEvent();
+                using Vector2 screenPosition = touch.GetScreenPosition(0);
+                touchPoint = new TouchPoint(touch.GetDeviceId(0), TouchPoint.StateType.Motion, screenPosition.X, screenPosition.Y);
+            }
+            Interop.Window.FeedHoverEvent(SwigCPtr, TouchPoint.getCPtr(touchPoint));
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+        /// <summary>
         /// Allows at least one more render, even when paused.
         /// The window should be shown, not minimised.
         /// </summary>
@@ -1962,6 +2010,10 @@ namespace Tizen.NUI
                 internalLastKeyEvent = null;
                 internalLastTouchEvent?.Dispose();
                 internalLastTouchEvent = null;
+
+                internalHoverTimer?.Stop();
+                internalHoverTimer?.Dispose();
+                internalHoverTimer = null;
             }
 
 
index ac76986..f0a9aed 100755 (executable)
@@ -9,6 +9,16 @@ namespace Tizen.NUI.Samples
     public class ScrollableFocusSample : IExample
     {
         public View root;
+        public class CustomScrollableBase : ScrollableBase
+        {
+            public override bool OnWheel(Wheel wheel)
+            {
+                base.OnWheel(wheel);
+                Window window = NUIApplication.GetDefaultWindow();
+                window.LazyFeedHover();
+                return true;
+            }
+        }
 
         public void Activate()
         {
@@ -38,7 +48,7 @@ namespace Tizen.NUI.Samples
             };
             root.Add(topbtn);
 
-            var scrollview = new ScrollableBase
+            var scrollview = new CustomScrollableBase
             {
                 ScrollingDirection = ScrollableBase.Direction.Vertical,
                 WidthSpecification = LayoutParamPolicies.MatchParent,
@@ -62,7 +72,7 @@ namespace Tizen.NUI.Samples
             };
             root.Add(middle);
 
-            var myscrollview = new ScrollableBase
+            var myscrollview = new CustomScrollableBase
             {
                 ScrollingDirection = ScrollableBase.Direction.Vertical,
                 WidthSpecification = LayoutParamPolicies.MatchParent,
@@ -97,6 +107,20 @@ namespace Tizen.NUI.Samples
                 Focusable = true,
                 FocusableInTouch = true,
                 Text = $"Item {index}",
+                LeaveRequired = true,
+                BackgroundColor = Color.DarkOrange,
+            };
+            btn.HoverEvent += (s, e) =>
+            {
+                if(e.Hover.GetState(0) == PointStateType.Started)
+                {
+                    btn.BackgroundColor = Color.Red;
+                }
+                else if (e.Hover.GetState(0) == PointStateType.Leave)
+                {
+                    btn.BackgroundColor = Color.DarkOrange;
+                }
+                return true;
             };
             // btn.FocusGained += (s, e) =>
             // {