From: Bowon Ryu Date: Fri, 12 Jul 2024 10:56:11 +0000 (+0900) Subject: [NUI] Add RequestAsyncNaturalSize to TextLabel X-Git-Tag: submit/tizen/20240821.061804~1^2~13 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b2e08255fe9b9ce378bf1cb6647727434a125e28;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [NUI] Add RequestAsyncNaturalSize to TextLabel RequestAsyncNaturalSize computes the natural size of text asynchronously. The result is received through the AsyncNaturalSizeComputed. Signed-off-by: Bowon Ryu --- diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.TextLabel.cs b/src/Tizen.NUI/src/internal/Interop/Interop.TextLabel.cs index 6a7ec9adb..82288048a 100755 --- a/src/Tizen.NUI/src/internal/Interop/Interop.TextLabel.cs +++ b/src/Tizen.NUI/src/internal/Interop/Interop.TextLabel.cs @@ -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); } } } diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextEvent.cs b/src/Tizen.NUI/src/public/BaseComponents/TextEvent.cs index a2e45a918..7c0c0594a 100644 --- a/src/Tizen.NUI/src/public/BaseComponents/TextEvent.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextEvent.cs @@ -70,4 +70,27 @@ namespace Tizen.NUI.BaseComponents /// public float Height { get; } } + + /// + /// AsyncTextSizeComputedEventArgs is a class to record async text size computed event arguments which will be sent to user. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public class AsyncTextSizeComputedEventArgs : EventArgs + { + public AsyncTextSizeComputedEventArgs(float width, float height) + { + Width = width; + Height = height; + } + + /// + /// The computed width. + /// + public float Width { get; } + + /// + /// The computed height. + /// + public float Height { get; } + } } \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs b/src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs index 47c9f0886..543af9d3f 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs @@ -375,6 +375,16 @@ namespace Tizen.NUI.BaseComponents if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } + /// + /// Requests asynchronous text natural size computation. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public void RequestAsyncNaturalSize() + { + Interop.TextLabel.RequestAsyncNaturalSize(SwigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + /// /// The TranslatableText property.
/// The text can set the SID value.
diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextLabelEvent.cs b/src/Tizen.NUI/src/public/BaseComponents/TextLabelEvent.cs index e3ba6f594..78eb8ff6e 100644 --- a/src/Tizen.NUI/src/public/BaseComponents/TextLabelEvent.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextLabelEvent.cs @@ -38,6 +38,9 @@ namespace Tizen.NUI.BaseComponents private EventHandler textLabelAsyncTextRenderedEventHandler; private AsyncTextRenderedCallbackDelegate textLabelAsyncTextRenderedCallbackDelegate; + private EventHandler 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); + + + /// + /// The AsyncNaturalSizeComputed signal is emitted when the async natural size computed. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler 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); + } + /// /// The AsyncTextRendered signal is emitted when the async text rendered. ///