[NUI] Add SetTextFit, GetTextFit to TextLabel
authorBowon Ryu <bowon.ryu@samsung.com>
Tue, 10 Aug 2021 11:10:38 +0000 (20:10 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Wed, 18 Aug 2021 03:10:44 +0000 (12:10 +0900)
Add a TextFit struct to pass data of DALi TextFit PropertyMap.
The TextFit struct can be used as an argument to
SetTextFit and GetTextFit methods.

// example
var textFit = new Tizen.NUI.Text.TextFit();
textFit.Enable = true;
textFit.MinSize = 10.0f;
textFit.MaxSize = 100.0f;
textFit.StepSize = 5.0f;
textFit.FontSizeType = FontSizeType.PointSize;
label.SetTextFit(textFit);

Signed-off-by: Bowon Ryu <bowon.ryu@samsung.com>
src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs
src/Tizen.NUI/src/public/BaseComponents/TextUtils.cs
src/Tizen.NUI/src/public/Common/NUIConstants.cs

index 872ae7d..4520ce4 100755 (executable)
@@ -1099,6 +1099,48 @@ namespace Tizen.NUI.BaseComponents
         }
 
         /// <summary>
+        /// Set TextFit to TextLabel. <br />
+        /// </summary>
+        /// <param name="textFit">The TextFit</param>
+        /// <remarks>
+        /// SetTextFit specifies the textFit of the text through <see cref="Tizen.NUI.Text.TextFit"/>. <br />
+        /// </remarks>
+        /// <example>
+        /// The following example demonstrates how to use the SetTextFit method.
+        /// <code>
+        /// var textFit = new Tizen.NUI.Text.TextFit();
+        /// textFit.Enable = true;
+        /// textFit.MinSize = 10.0f;
+        /// textFit.MaxSize = 100.0f;
+        /// textFit.StepSize = 5.0f;
+        /// textFit.FontSizeType = FontSizeType.PointSize;
+        /// label.SetTextFit(textFit);
+        /// </code>
+        /// </example>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void SetTextFit(TextFit textFit)
+        {
+            SetProperty(TextLabel.Property.TextFit, new PropertyValue(TextUtils.GetTextFitMap(textFit)));
+        }
+
+        /// <summary>
+        /// Get TextFit from TextLabel. <br />
+        /// </summary>
+        /// <returns>The TextFit</returns>
+        /// <remarks>
+        /// TextFit is always returned based on PointSize. <br />
+        /// If the user sets FontSizeType to PixelSize, then MinSize, MaxSize, and StepSize are converted based on PointSize and returned. <br />
+        /// <see cref="Tizen.NUI.Text.TextFit"/>
+        /// </remarks>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public TextFit GetTextFit()
+        {
+            var map = new PropertyMap();
+            GetProperty(TextLabel.Property.TextFit).Get(map);
+            return TextUtils.GetTextFitStruct(map);
+        }
+
+        /// <summary>
         /// The MinLineSize property.<br />
         /// </summary>
         /// <since_tizen> 8 </since_tizen>
index a165137..b2eefb2 100755 (executable)
@@ -1635,5 +1635,99 @@ namespace Tizen.NUI.BaseComponents
 
             return outline;
         }
+
+        /// <summary>
+        /// It returns a string value according to FontSizeType.
+        /// The returned value can be used for TextFit PropertyMap.
+        /// <param name="fontSizeType">The FontSizeType enum value.</param>
+        /// <returns> A string value for TextFit.FontSizeType property. </returns>
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static string GetFontSizeString(FontSizeType fontSizeType)
+        {
+            string value = "pointSize";
+
+            switch (fontSizeType)
+            {
+                default:
+                case FontSizeType.PointSize:
+                    value = "pointSize";
+                    break;
+                case FontSizeType.PixelSize:
+                    value = "pixelSize";
+                    break;
+            }
+
+            return value;
+        }
+
+        /// <summary>
+        /// It returns a FontSizeType value according to fontSizeString.
+        /// The returned value can be used for FontStyle PropertyMap.
+        /// <param name="fontSizeString">The FontSizeType string value.</param>
+        /// <returns> A FontSizeType value for TextFit.FontSizeType property. </returns>
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static FontSizeType GetFontSizeType(string fontSizeString)
+        {
+            FontSizeType value = FontSizeType.PointSize;
+
+            switch (fontSizeString)
+            {
+                default:
+                case "pointSize":
+                    value = FontSizeType.PointSize;
+                    break;
+                case "pixelSize":
+                    value = FontSizeType.PixelSize;
+                    break;
+            }
+
+            return value;
+        }
+
+        /// <summary>
+        /// This method converts a TextFit struct to a PropertyMap and returns it.
+        /// The returned map can be used for set TextFit PropertyMap in the SetTextFit method.
+        /// <param name="textFit">The TextFit struct value.</param>
+        /// <returns> A PropertyMap for TextFit property. </returns>
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static PropertyMap GetTextFitMap(TextFit textFit)
+        {
+            var map = new PropertyMap();
+            map.Add("enable", new PropertyValue(textFit.Enable));
+            map.Add("minSize", new PropertyValue(textFit.MinSize));
+            map.Add("maxSize", new PropertyValue(textFit.MaxSize));
+            map.Add("stepSize", new PropertyValue(textFit.StepSize));
+            map.Add("fontSizeType", new PropertyValue(GetFontSizeString(textFit.FontSizeType)));
+
+            return map;
+        }
+
+        /// <summary>
+        /// This method converts a TextFit map to a struct and returns it.
+        /// The returned struct can be returned to the user as a TextFit in the GetTextFit method.
+        /// <param name="map">The TextFit PropertyMap.</param>
+        /// <returns> A TextFit struct. </returns>
+        /// </summary>
+        [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);
+
+            var textFit = new TextFit();
+            textFit.Enable = enable;
+            textFit.MinSize = minSize;
+            textFit.MaxSize = maxSize;
+            textFit.StepSize = stepSize;
+            textFit.FontSizeType = GetFontSizeType(fontSizeType);
+
+            return textFit;
+        }
     }
 }
index f57c096..58dc9b4 100755 (executable)
@@ -2008,6 +2008,28 @@ namespace Tizen.NUI
         Reject
     }
 
+    /// <summary>
+    /// Enumeration for the size type of font. <br />
+    /// </summary>
+    /// <remarks>
+    /// The size type of font used as a property of <see cref="Tizen.NUI.Text.TextFit"/>. <br />
+    /// </remarks>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public enum FontSizeType
+    {
+        /// <summary>
+        /// The PointSize.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        PointSize,
+
+        /// <summary>
+        /// The PixelSize.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        PixelSize
+    }
+
     namespace Text
     {
         /// <summary>
@@ -2145,5 +2167,46 @@ namespace Tizen.NUI
             [EditorBrowsable(EditorBrowsableState.Never)]
             public float Width { get; set; }
         }
+
+        /// <summary>
+        /// A struct to pass data of TextFit PropertyMap. <br />
+        /// </summary>
+        /// <remarks>
+        /// The TextFit struct is used as an argument to SetTextFit and GetTextFit methods. <br />
+        /// See <see cref="Tizen.NUI.BaseComponents.TextLabel.SetTextFit"/> and <see cref="Tizen.NUI.BaseComponents.TextLabel.GetTextFit"/>. <br />
+        /// </remarks>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public struct TextFit
+        {
+            /// <summary>
+            /// True to enable the text fit or false to disable (the default value is false).
+            /// </summary>
+            [EditorBrowsable(EditorBrowsableState.Never)]
+            public bool Enable { get; set; }
+
+            /// <summary>
+            /// Minimum Size for text fit.
+            /// </summary>
+            [EditorBrowsable(EditorBrowsableState.Never)]
+            public float MinSize { get; set; }
+
+            /// <summary>
+            /// Maximum Size for text fit.
+            /// </summary>
+            [EditorBrowsable(EditorBrowsableState.Never)]
+            public float MaxSize { get; set; }
+
+            /// <summary>
+            /// Step Size for font increase.
+            /// </summary>
+            [EditorBrowsable(EditorBrowsableState.Never)]
+            public float StepSize { get; set; }
+
+            /// <summary>
+            /// The size type of font, PointSize or PixelSize (the default value is PointSize).
+            /// </summary>
+            [EditorBrowsable(EditorBrowsableState.Never)]
+            public FontSizeType FontSizeType { get; set; }
+        }
     }
 }