[NUI] Binding TextFitChanged event
authorjoogab.yun <joogab.yun@samsung.com>
Fri, 19 Nov 2021 04:57:43 +0000 (13:57 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Mon, 22 Nov 2021 10:54:11 +0000 (19:54 +0900)
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
src/Tizen.NUI/src/public/BaseComponents/TextUtils.cs
src/Tizen.NUI/src/public/Common/NUIConstants.cs
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/TextFitChangedSample.cs [new file with mode: 0755]

index 603c73a..0edc832 100755 (executable)
@@ -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();
 
index d095dcb..54f1a1e 100755 (executable)
@@ -1301,6 +1301,14 @@ namespace Tizen.NUI.BaseComponents
                 selectorData?.Reset(this);
             }
 
+            if (this.HasBody())
+            {
+                if (textLabelTextFitChangedCallbackDelegate != null)
+                {
+                    TextFitChangedSignal().Disconnect(textLabelTextFitChangedCallbackDelegate);
+                }
+            }
+
             base.Dispose(type);
         }
 
index 3d57f46..8d9b10e 100644 (file)
@@ -28,12 +28,19 @@ namespace Tizen.NUI.BaseComponents
     /// <since_tizen> 3 </since_tizen>
     public partial class TextLabel
     {
+
         private EventHandler<AnchorClickedEventArgs> 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);
+
         /// <summary>
         /// The AnchorClicked signal is emitted when the anchor is clicked.
         /// </summary>
@@ -77,5 +84,44 @@ namespace Tizen.NUI.BaseComponents
             //here we send all data to user event handlers
             textLabelAnchorClickedEventHandler?.Invoke(this, e);
         }
+
+        /// <summary>
+        /// 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.<br />
+        /// </summary>
+        [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);
+        }
     }
 }
index 0850223..5474db0 100755 (executable)
@@ -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;
index fab327d..3d01873 100755 (executable)
@@ -2139,7 +2139,7 @@ namespace Tizen.NUI
             /// <summary>
             /// The offset in pixels of the shadow (if null, the default value is 0, 0). <br />
             /// If not provided then the shadow is not enabled. <br />
-            ///  
+            ///
             /// </summary>
             [EditorBrowsable(EditorBrowsableState.Never)]
             public Vector2 Offset { get; set; }
@@ -2215,6 +2215,12 @@ namespace Tizen.NUI
             /// </summary>
             [EditorBrowsable(EditorBrowsableState.Never)]
             public FontSizeType FontSizeType { get; set; }
+
+            /// <summary>
+            /// Font Size for text fit
+            /// </summary>
+            [EditorBrowsable(EditorBrowsableState.Never)]
+            public float? FontSize { get; set; }
         }
 
         /// <summary>
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 (executable)
index 0000000..dc6d731
--- /dev/null
@@ -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()
+        {
+        }
+    }
+}