From f2fea1da199a130b53d3720fef5d5ff2bc3199cf Mon Sep 17 00:00:00 2001 From: "joogab.yun" Date: Fri, 23 Jun 2023 17:10:28 +0900 Subject: [PATCH] [NUI] Add LazyFeedHover api for HoverEvent 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/internal/Interop/Interop.Window.cs | 3 ++ src/Tizen.NUI/src/public/Window/Window.cs | 52 ++++++++++++++++++++++ .../ScrollableFocus/ScrollableFocusSample.cs | 28 +++++++++++- 3 files changed, 81 insertions(+), 2 deletions(-) diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.Window.cs b/src/Tizen.NUI/src/internal/Interop/Interop.Window.cs index b52d364..a453cc6 100755 --- a/src/Tizen.NUI/src/internal/Interop/Interop.Window.cs +++ b/src/Tizen.NUI/src/internal/Interop/Interop.Window.cs @@ -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); diff --git a/src/Tizen.NUI/src/public/Window/Window.cs b/src/Tizen.NUI/src/public/Window/Window.cs index 61eeafd..a6c6c42 100755 --- a/src/Tizen.NUI/src/public/Window/Window.cs +++ b/src/Tizen.NUI/src/public/Window/Window.cs @@ -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 } /// + /// Feeds a hover event into the window.
+ /// This is feed after a default time of 48 ms. You can also set this time. + ///
+ /// The time of how much later it will be feed (default is 48ms) + /// 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.
+ /// and LazyFeedHover called within the set time are ignored. Only the last request becomes a FeedHover. + ///
+ [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(); + } + } + + /// /// Feeds a touch point into the window. /// /// The touch point to feed. @@ -1155,6 +1186,23 @@ namespace Tizen.NUI } /// + /// Feeds a hover event into the window. + /// + /// The touch point to feed hover event. If null is entered, the feed hover event is generated with the last inputed touch point. + [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(); + } + + /// /// Allows at least one more render, even when paused. /// The window should be shown, not minimised. /// @@ -1962,6 +2010,10 @@ namespace Tizen.NUI internalLastKeyEvent = null; internalLastTouchEvent?.Dispose(); internalLastTouchEvent = null; + + internalHoverTimer?.Stop(); + internalHoverTimer?.Dispose(); + internalHoverTimer = null; } diff --git a/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/ScrollableFocus/ScrollableFocusSample.cs b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/ScrollableFocus/ScrollableFocusSample.cs index ac76986..f0a9aed 100755 --- a/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/ScrollableFocus/ScrollableFocusSample.cs +++ b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/ScrollableFocus/ScrollableFocusSample.cs @@ -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) => // { -- 2.7.4