From 31c3180daa66d39380be89ada461e2bc3adcbb9a Mon Sep 17 00:00:00 2001 From: "joogab.yun" Date: Fri, 19 Nov 2021 13:57:43 +0900 Subject: [PATCH] [NUI] Binding TextFitChanged event --- .../src/internal/Interop/Interop.TextLabel.cs | 3 ++ .../src/public/BaseComponents/TextLabel.cs | 8 ++++ .../src/public/BaseComponents/TextLabelEvent.cs | 46 ++++++++++++++++++++++ .../src/public/BaseComponents/TextUtils.cs | 20 +++++++--- src/Tizen.NUI/src/public/Common/NUIConstants.cs | 8 +++- .../Samples/TextFitChangedSample.cs | 43 ++++++++++++++++++++ 6 files changed, 121 insertions(+), 7 deletions(-) create mode 100755 test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/TextFitChangedSample.cs diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.TextLabel.cs b/src/Tizen.NUI/src/internal/Interop/Interop.TextLabel.cs index 603c73a..0edc832 100755 --- a/src/Tizen.NUI/src/internal/Interop/Interop.TextLabel.cs +++ b/src/Tizen.NUI/src/internal/Interop/Interop.TextLabel.cs @@ -138,6 +138,9 @@ namespace Tizen.NUI [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_TextLabel_Property_TEXT_FIT_get")] public static extern int TextFitGet(); + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_TextLabel_TextFitChangedSignal")] + public static extern global::System.IntPtr TextFitChangedSignal(global::System.Runtime.InteropServices.HandleRef jarg1); + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_TextLabel_Property_MIN_LINE_SIZE_get")] public static extern int MinLineSizeGet(); diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs b/src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs index d095dcb..54f1a1e 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs @@ -1301,6 +1301,14 @@ namespace Tizen.NUI.BaseComponents selectorData?.Reset(this); } + if (this.HasBody()) + { + if (textLabelTextFitChangedCallbackDelegate != null) + { + TextFitChangedSignal().Disconnect(textLabelTextFitChangedCallbackDelegate); + } + } + base.Dispose(type); } diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextLabelEvent.cs b/src/Tizen.NUI/src/public/BaseComponents/TextLabelEvent.cs index 3d57f46..8d9b10e 100644 --- a/src/Tizen.NUI/src/public/BaseComponents/TextLabelEvent.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextLabelEvent.cs @@ -28,12 +28,19 @@ namespace Tizen.NUI.BaseComponents /// 3 public partial class TextLabel { + private EventHandler textLabelAnchorClickedEventHandler; private AnchorClickedCallbackDelegate textLabelAnchorClickedCallbackDelegate; + private EventHandler textLabelTextFitChangedEventHandler; + private TextFitChangedCallbackDelegate textLabelTextFitChangedCallbackDelegate; + [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate void AnchorClickedCallbackDelegate(IntPtr textLabel, IntPtr href, uint hrefLength); + [UnmanagedFunctionPointer(CallingConvention.StdCall)] + private delegate void TextFitChangedCallbackDelegate(IntPtr textLabel); + /// /// The AnchorClicked signal is emitted when the anchor is clicked. /// @@ -77,5 +84,44 @@ namespace Tizen.NUI.BaseComponents //here we send all data to user event handlers textLabelAnchorClickedEventHandler?.Invoke(this, e); } + + /// + /// An event for the TextFitChanged signal which can be used to subscribe or unsubscribe the event handler + /// provided by the user. The TextFitChanged signal is emitted when the text fit properties changes.
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler TextFitChanged + { + add + { + if (textLabelTextFitChangedEventHandler == null) + { + textLabelTextFitChangedCallbackDelegate = (OnTextFitChanged); + TextFitChangedSignal().Connect(textLabelTextFitChangedCallbackDelegate); + } + textLabelTextFitChangedEventHandler += value; + } + remove + { + textLabelTextFitChangedEventHandler -= value; + if (textLabelTextFitChangedEventHandler == null && TextFitChangedSignal().Empty() == false) + { + TextFitChangedSignal().Disconnect(textLabelTextFitChangedCallbackDelegate); + } + } + } + + internal TextLabelSignal TextFitChangedSignal() + { + TextLabelSignal ret = new TextLabelSignal(Interop.TextLabel.TextFitChangedSignal(SwigCPtr), false); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + private void OnTextFitChanged(IntPtr textLabel) + { + // no data to be sent to the user, as in NUI there is no event provide old values. + textLabelTextFitChangedEventHandler?.Invoke(this, EventArgs.Empty); + } } } diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextUtils.cs b/src/Tizen.NUI/src/public/BaseComponents/TextUtils.cs index 0850223..5474db0 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextUtils.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextUtils.cs @@ -1560,17 +1560,25 @@ namespace Tizen.NUI.BaseComponents [EditorBrowsable(EditorBrowsableState.Never)] public static TextFit GetTextFitStruct(PropertyMap map) { - map.Find(0, "enable").Get(out bool enable); - map.Find(0, "minSize").Get(out float minSize); - map.Find(0, "maxSize").Get(out float maxSize); - map.Find(0, "stepSize").Get(out float stepSize); - map.Find(0, "fontSizeType").Get(out string fontSizeType); + bool enable = false; + float minSize = 0.0f; + float maxSize = 0.0f; + float stepSize = 0.0f; + float fontSize = 0.0f; + string fontSizeType = null; + map.Find(0, "enable")?.Get(out enable); + map.Find(0, "minSize")?.Get(out minSize); + map.Find(0, "maxSize")?.Get(out maxSize); + map.Find(0, "stepSize")?.Get(out stepSize); + map.Find(0, "fontSize")?.Get(out fontSize); + map.Find(0, "fontSizeType")?.Get(out fontSizeType); var textFit = new TextFit(); textFit.Enable = enable; textFit.MinSize = minSize; textFit.MaxSize = maxSize; textFit.StepSize = stepSize; + textFit.FontSize = fontSize; textFit.FontSizeType = GetFontSizeType(fontSizeType); return textFit; @@ -1610,7 +1618,7 @@ namespace Tizen.NUI.BaseComponents else if (placeholder.PixelSize != null) map.Add("pixelSize", new PropertyValue((float)placeholder.PixelSize)); - + map.Add("ellipsis", new PropertyValue(placeholder.Ellipsis)); return map; diff --git a/src/Tizen.NUI/src/public/Common/NUIConstants.cs b/src/Tizen.NUI/src/public/Common/NUIConstants.cs index fab327d..3d01873 100755 --- a/src/Tizen.NUI/src/public/Common/NUIConstants.cs +++ b/src/Tizen.NUI/src/public/Common/NUIConstants.cs @@ -2139,7 +2139,7 @@ namespace Tizen.NUI /// /// The offset in pixels of the shadow (if null, the default value is 0, 0).
/// If not provided then the shadow is not enabled.
- /// + /// ///
[EditorBrowsable(EditorBrowsableState.Never)] public Vector2 Offset { get; set; } @@ -2215,6 +2215,12 @@ namespace Tizen.NUI /// [EditorBrowsable(EditorBrowsableState.Never)] public FontSizeType FontSizeType { get; set; } + + /// + /// Font Size for text fit + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public float? FontSize { get; set; } } /// diff --git a/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/TextFitChangedSample.cs b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/TextFitChangedSample.cs new file mode 100755 index 0000000..dc6d731 --- /dev/null +++ b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/TextFitChangedSample.cs @@ -0,0 +1,43 @@ +using Tizen.NUI; +using Tizen.NUI.BaseComponents; +using Tizen.NUI.Components; +using Tizen.NUI.Text; + +namespace Tizen.NUI.Samples +{ + public class TextFitChangedSample : IExample + { + private TextLabel label; + + public void Activate() + { + Window window = NUIApplication.GetDefaultWindow(); + var fit = new TextFit(); + fit.Enable = true; + fit.MinSize = 5.0f; + fit.MaxSize = 50.0f; + + label = new TextLabel() + { + Text = "ABCDE", + Size = new Size(300, 100), + PointSize = 10, + Position = new Position(100, 100), + BackgroundColor = Color.Yellow, + }; + label.SetTextFit(fit); + + window.Add(label); + + label.TextFitChanged +=(s, e) => + { + TextFit textfit = label.GetTextFit(); + Tizen.Log.Error("NUI", $"FontSize : {textfit.FontSize}\n"); + }; + } + + public void Deactivate() + { + } + } +} -- 2.7.4