[NUI] Add RequestAsyncHeightForWidth to TextLabel
authorBowon Ryu <bowon.ryu@samsung.com>
Mon, 15 Jul 2024 01:31:45 +0000 (10:31 +0900)
committerJiyun Yang <ji.yang@samsung.com>
Wed, 21 Aug 2024 06:10:37 +0000 (15:10 +0900)
RequestAsyncHeightForWidth computes the hegiht for width of text asynchronously.
The result is received through the AsyncHeightForWidthComputed.

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

index 82288048ad25369ea49a5d6426dfc1f96ee0520d..3e7aee5d10d31dc928e1feef6ddf22973b1401f5 100755 (executable)
@@ -211,11 +211,17 @@ namespace Tizen.NUI
             [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_RequestAsyncHeightForWidth")]
+            public static extern void RequestAsyncHeightForWidth(global::System.Runtime.InteropServices.HandleRef textLabelRef, float width);
+
             [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);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_TextLabel_AsyncHeightForWidthComputedSignal")]
+            public static extern global::System.IntPtr AsyncHeightForWidthComputedSignal(global::System.Runtime.InteropServices.HandleRef jarg1);
         }
     }
 }
index 543af9d3f36b1bf9eebf0cb2cbc342250d39fb0b..0133a50a6a5eddd38564b7efc735245f559e51d0 100755 (executable)
@@ -385,6 +385,17 @@ namespace Tizen.NUI.BaseComponents
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
+        /// <summary>
+        /// Requests asynchronous computation of the height of the text based on the given width.
+        /// </summary>
+        /// <param name="width">The width of text to compute.</param>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void RequestAsyncHeightForWidth(float width)
+        {
+            Interop.TextLabel.RequestAsyncHeightForWidth(SwigCPtr, width);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
         /// <summary>
         /// The TranslatableText property.<br />
         /// The text can set the SID value.<br />
index 78eb8ff6e59afffdf8e5026e77a4df8232a9fccc..5fd377a8b26eacae24c076c076b54df83046582c 100644 (file)
@@ -41,6 +41,9 @@ namespace Tizen.NUI.BaseComponents
         private EventHandler<AsyncTextSizeComputedEventArgs> textLabelAsyncTextNaturalSizeComputedEventHandler;
         private AsyncTextNaturalSizeComputedCallbackDelegate textLabelAsyncTextNaturalSizeComputedCallbackDelegate;
 
+        private EventHandler<AsyncTextSizeComputedEventArgs> textLabelAsyncTextHeightForWidthComputedEventHandler;
+        private AsyncTextHeightForWidthComputedCallbackDelegate textLabelAsyncTextHeightForWidthComputedCallbackDelegate;
+
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
         private delegate void AnchorClickedCallbackDelegate(IntPtr textLabel, IntPtr href, uint hrefLength);
 
@@ -53,6 +56,49 @@ namespace Tizen.NUI.BaseComponents
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
         private delegate void AsyncTextNaturalSizeComputedCallbackDelegate(IntPtr textLabel, float width, float height);
 
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        private delegate void AsyncTextHeightForWidthComputedCallbackDelegate(IntPtr textLabel, float width, float height);
+
+
+        /// <summary>
+        /// The AsyncHeightForWidthComputed signal is emitted when the async natural size computed.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public event EventHandler<AsyncTextSizeComputedEventArgs> AsyncHeightForWidthComputed
+        {
+            add
+            {
+                if (textLabelAsyncTextHeightForWidthComputedEventHandler == null)
+                {
+                    textLabelAsyncTextHeightForWidthComputedCallbackDelegate = (OnAsyncHeightForWidthComputed);
+                    AsyncHeightForWidthComputedSignal().Connect(textLabelAsyncTextHeightForWidthComputedCallbackDelegate);
+                }
+                textLabelAsyncTextHeightForWidthComputedEventHandler += value;
+            }
+            remove
+            {
+                textLabelAsyncTextHeightForWidthComputedEventHandler -= value;
+                if (textLabelAsyncTextHeightForWidthComputedEventHandler == null && AsyncHeightForWidthComputedSignal().Empty() == false)
+                {
+                    AsyncHeightForWidthComputedSignal().Disconnect(textLabelAsyncTextHeightForWidthComputedCallbackDelegate);
+                }
+            }
+        }
+
+        internal TextLabelSignal AsyncHeightForWidthComputedSignal()
+        {
+            TextLabelSignal ret = new TextLabelSignal(Interop.TextLabel.AsyncHeightForWidthComputedSignal(SwigCPtr), false);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
+        private void OnAsyncHeightForWidthComputed(IntPtr textLabel, float width, float height)
+        {
+            AsyncTextSizeComputedEventArgs e = new AsyncTextSizeComputedEventArgs(width, height);
+
+            //here we send all data to user event handlers
+            textLabelAsyncTextHeightForWidthComputedEventHandler?.Invoke(this, e);
+        }
 
         /// <summary>
         /// The AsyncNaturalSizeComputed signal is emitted when the async natural size computed.