[NUI] Add RequestAsyncNaturalSize to TextLabel
authorBowon Ryu <bowon.ryu@samsung.com>
Fri, 12 Jul 2024 10:56:11 +0000 (19:56 +0900)
committerJiyun Yang <ji.yang@samsung.com>
Wed, 21 Aug 2024 06:10:37 +0000 (15:10 +0900)
RequestAsyncNaturalSize computes the natural size of text asynchronously.
The result is received through the AsyncNaturalSizeComputed.

Signed-off-by: Bowon Ryu <bowon.ryu@samsung.com>
src/Tizen.NUI/src/internal/Interop/Interop.TextLabel.cs
src/Tizen.NUI/src/public/BaseComponents/TextEvent.cs
src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs
src/Tizen.NUI/src/public/BaseComponents/TextLabelEvent.cs

index 6a7ec9adba9bce5762ea5acaf069eaa7d005ffce..82288048ad25369ea49a5d6426dfc1f96ee0520d 100755 (executable)
@@ -208,8 +208,14 @@ namespace Tizen.NUI
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_TextLabel_RequestAsyncRenderWithConstraint")]
             public static extern void RequestAsyncRenderWithConstraint(global::System.Runtime.InteropServices.HandleRef textLabelRef, float widthConstraint, float heightConstraint);
 
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_TextLabel_RequestAsyncNaturalSize")]
+            public static extern void RequestAsyncNaturalSize(global::System.Runtime.InteropServices.HandleRef textLabelRef);
+
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_TextLabel_AsyncTextRenderedSignal")]
             public static extern global::System.IntPtr AsyncTextRenderedSignal(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_TextLabel_AsyncNaturalSizeComputedSignal")]
+            public static extern global::System.IntPtr AsyncNaturalSizeComputedSignal(global::System.Runtime.InteropServices.HandleRef jarg1);
         }
     }
 }
index a2e45a918e5ae233e97d1c5686910dd45cc90285..7c0c0594a2c584ca702d0ce2111d59fcc82188b8 100644 (file)
@@ -70,4 +70,27 @@ namespace Tizen.NUI.BaseComponents
         /// </summary>
         public float Height { get; }
     }
+
+    /// <summary>
+    /// AsyncTextSizeComputedEventArgs is a class to record async text size computed event arguments which will be sent to user.
+    /// </summary>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class AsyncTextSizeComputedEventArgs : EventArgs
+    {
+        public AsyncTextSizeComputedEventArgs(float width, float height)
+        {
+            Width = width;
+            Height = height;
+        }
+
+        /// <summary>
+        /// The computed width.
+        /// </summary>
+        public float Width { get; }
+
+        /// <summary>
+        /// The computed height.
+        /// </summary>
+        public float Height { get; }
+    }
 }
\ No newline at end of file
index 47c9f08861bb559a596eb25c76e5bb4f0a185099..543af9d3f36b1bf9eebf0cb2cbc342250d39fb0b 100755 (executable)
@@ -375,6 +375,16 @@ namespace Tizen.NUI.BaseComponents
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
+        /// <summary>
+        /// Requests asynchronous text natural size computation.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void RequestAsyncNaturalSize()
+        {
+            Interop.TextLabel.RequestAsyncNaturalSize(SwigCPtr);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
         /// <summary>
         /// The TranslatableText property.<br />
         /// The text can set the SID value.<br />
index e3ba6f594d7234233fe6914f33b55ee1a8c0186c..78eb8ff6e59afffdf8e5026e77a4df8232a9fccc 100644 (file)
@@ -38,6 +38,9 @@ namespace Tizen.NUI.BaseComponents
         private EventHandler<AsyncTextRenderedEventArgs> textLabelAsyncTextRenderedEventHandler;
         private AsyncTextRenderedCallbackDelegate textLabelAsyncTextRenderedCallbackDelegate;
 
+        private EventHandler<AsyncTextSizeComputedEventArgs> textLabelAsyncTextNaturalSizeComputedEventHandler;
+        private AsyncTextNaturalSizeComputedCallbackDelegate textLabelAsyncTextNaturalSizeComputedCallbackDelegate;
+
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
         private delegate void AnchorClickedCallbackDelegate(IntPtr textLabel, IntPtr href, uint hrefLength);
 
@@ -47,6 +50,50 @@ namespace Tizen.NUI.BaseComponents
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
         private delegate void AsyncTextRenderedCallbackDelegate(IntPtr textLabel, float width, float height);
 
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        private delegate void AsyncTextNaturalSizeComputedCallbackDelegate(IntPtr textLabel, float width, float height);
+
+
+        /// <summary>
+        /// The AsyncNaturalSizeComputed signal is emitted when the async natural size computed.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public event EventHandler<AsyncTextSizeComputedEventArgs> AsyncNaturalSizeComputed
+        {
+            add
+            {
+                if (textLabelAsyncTextNaturalSizeComputedEventHandler == null)
+                {
+                    textLabelAsyncTextNaturalSizeComputedCallbackDelegate = (OnAsyncNaturalSizeComputed);
+                    AsyncNaturalSizeComputedSignal().Connect(textLabelAsyncTextNaturalSizeComputedCallbackDelegate);
+                }
+                textLabelAsyncTextNaturalSizeComputedEventHandler += value;
+            }
+            remove
+            {
+                textLabelAsyncTextNaturalSizeComputedEventHandler -= value;
+                if (textLabelAsyncTextNaturalSizeComputedEventHandler == null && AsyncNaturalSizeComputedSignal().Empty() == false)
+                {
+                    AsyncNaturalSizeComputedSignal().Disconnect(textLabelAsyncTextNaturalSizeComputedCallbackDelegate);
+                }
+            }
+        }
+
+        internal TextLabelSignal AsyncNaturalSizeComputedSignal()
+        {
+            TextLabelSignal ret = new TextLabelSignal(Interop.TextLabel.AsyncNaturalSizeComputedSignal(SwigCPtr), false);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
+        private void OnAsyncNaturalSizeComputed(IntPtr textLabel, float width, float height)
+        {
+            AsyncTextSizeComputedEventArgs e = new AsyncTextSizeComputedEventArgs(width, height);
+
+            //here we send all data to user event handlers
+            textLabelAsyncTextNaturalSizeComputedEventHandler?.Invoke(this, e);
+        }
+
         /// <summary>
         /// The AsyncTextRendered signal is emitted when the async text rendered.
         /// </summary>