[NUI] Add SetUnderline, GetUnderline to Text Components
authorBowon Ryu <bowon.ryu@samsung.com>
Mon, 9 Aug 2021 12:26:37 +0000 (21:26 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Wed, 18 Aug 2021 03:10:44 +0000 (12:10 +0900)
Add a Underline struct to pass data of DALi Underline PropertyMap.
The Underline struct can be used as an argument to
SetUnderline and GetUnderline methods.

// example
var underline = new Tizen.NUI.Text.Underline();
underline.Enable = true;
underline.Color = new Color("#3498DB");
underline.Height = 2.0f;
label.SetUnderline(underline);

Signed-off-by: Bowon Ryu <bowon.ryu@samsung.com>
src/Tizen.NUI/src/public/BaseComponents/TextEditor.cs
src/Tizen.NUI/src/public/BaseComponents/TextField.cs
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 c521def..1404f55 100755 (executable)
@@ -826,6 +826,44 @@ namespace Tizen.NUI.BaseComponents
         }
 
         /// <summary>
+        /// Set Underline to TextEditor. <br />
+        /// </summary>
+        /// <param name="underline">The Underline</param>
+        /// <remarks>
+        /// SetUnderline specifies the underline of the text through <see cref="Tizen.NUI.Text.Underline"/>. <br />
+        /// </remarks>
+        /// <example>
+        /// The following example demonstrates how to use the SetUnderline method.
+        /// <code>
+        /// var underline = new Tizen.NUI.Text.Underline();
+        /// underline.Enable = true;
+        /// underline.Color = new Color("#3498DB");
+        /// underline.Height = 2.0f;
+        /// editor.SetUnderline(underline);
+        /// </code>
+        /// </example>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void SetUnderline(Underline underline)
+        {
+            SetProperty(TextEditor.Property.UNDERLINE, new PropertyValue(TextUtils.GetUnderlineMap(underline)));
+        }
+
+        /// <summary>
+        /// Get Underline from TextEditor. <br />
+        /// </summary>
+        /// <returns>The Underline</returns>
+        /// <remarks>
+        /// <see cref="Tizen.NUI.Text.Underline"/>
+        /// </remarks>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public Underline GetUnderline()
+        {
+            var map = new PropertyMap();
+            GetProperty(TextEditor.Property.UNDERLINE).Get(map);
+            return TextUtils.GetUnderlineStruct(map);
+        }
+
+        /// <summary>
         /// The InputUnderline property.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
index 1585611..4556947 100755 (executable)
@@ -1064,6 +1064,44 @@ namespace Tizen.NUI.BaseComponents
         }
 
         /// <summary>
+        /// Set Underline to TextField. <br />
+        /// </summary>
+        /// <param name="underline">The Underline</param>
+        /// <remarks>
+        /// SetUnderline specifies the underline of the text through <see cref="Tizen.NUI.Text.Underline"/>. <br />
+        /// </remarks>
+        /// <example>
+        /// The following example demonstrates how to use the SetUnderline method.
+        /// <code>
+        /// var underline = new Tizen.NUI.Text.Underline();
+        /// underline.Enable = true;
+        /// underline.Color = new Color("#3498DB");
+        /// underline.Height = 2.0f;
+        /// field.SetUnderline(underline);
+        /// </code>
+        /// </example>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void SetUnderline(Underline underline)
+        {
+            SetProperty(TextField.Property.UNDERLINE, new PropertyValue(TextUtils.GetUnderlineMap(underline)));
+        }
+
+        /// <summary>
+        /// Get Underline from TextField. <br />
+        /// </summary>
+        /// <returns>The Underline</returns>
+        /// <remarks>
+        /// <see cref="Tizen.NUI.Text.Underline"/>
+        /// </remarks>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public Underline GetUnderline()
+        {
+            var map = new PropertyMap();
+            GetProperty(TextField.Property.UNDERLINE).Get(map);
+            return TextUtils.GetUnderlineStruct(map);
+        }
+
+        /// <summary>
         /// The InputUnderline property.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
index ea64f18..0213950 100755 (executable)
@@ -702,6 +702,44 @@ namespace Tizen.NUI.BaseComponents
         }
 
         /// <summary>
+        /// Set Underline to TextLabel. <br />
+        /// </summary>
+        /// <param name="underline">The Underline</param>
+        /// <remarks>
+        /// SetUnderline specifies the underline of the text through <see cref="Tizen.NUI.Text.Underline"/>. <br />
+        /// </remarks>
+        /// <example>
+        /// The following example demonstrates how to use the SetUnderline method.
+        /// <code>
+        /// var underline = new Tizen.NUI.Text.Underline();
+        /// underline.Enable = true;
+        /// underline.Color = new Color("#3498DB");
+        /// underline.Height = 2.0f;
+        /// label.SetUnderline(underline);
+        /// </code>
+        /// </example>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void SetUnderline(Underline underline)
+        {
+            SetProperty(TextLabel.Property.UNDERLINE, new PropertyValue(TextUtils.GetUnderlineMap(underline)));
+        }
+
+        /// <summary>
+        /// Get Underline from TextLabel. <br />
+        /// </summary>
+        /// <returns>The Underline</returns>
+        /// <remarks>
+        /// <see cref="Tizen.NUI.Text.Underline"/>
+        /// </remarks>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public Underline GetUnderline()
+        {
+            var map = new PropertyMap();
+            GetProperty(TextLabel.Property.UNDERLINE).Get(map);
+            return TextUtils.GetUnderlineStruct(map);
+        }
+
+        /// <summary>
         /// The Shadow property.<br />
         /// The default shadow parameters.<br />
         /// The shadow map contains the following keys :<br />
index 3c6ffdb..7e09557 100755 (executable)
@@ -1509,5 +1509,48 @@ namespace Tizen.NUI.BaseComponents
             return inputFilter;
 
         }
+
+        /// <summary>
+        /// This method converts a Underline struct to a PropertyMap and returns it.
+        /// The returned map can be used for set Underline PropertyMap in the SetUnderline method.
+        /// <param name="underline">The Underline struct value.</param>
+        /// <returns> A PropertyMap for Underline property. </returns>
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static PropertyMap GetUnderlineMap(Underline underline)
+        {
+            var map = new PropertyMap();
+
+            if (underline.Color != null)
+                map.Add("color", new PropertyValue(underline.Color));
+
+            map.Add("enable", new PropertyValue(underline.Enable));
+            map.Add("height", new PropertyValue(underline.Height));
+
+            return map;
+        }
+
+        /// <summary>
+        /// This method converts a Underline map to a struct and returns it.
+        /// The returned struct can be returned to the user as a Underline in the GetUnderline method.
+        /// <param name="map">The Underline PropertyMap.</param>
+        /// <returns> A Underline struct. </returns>
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static Underline GetUnderlineStruct(PropertyMap map)
+        {
+            Color color = new Color();
+            map.Find(0, "enable").Get(out bool enable);
+            map.Find(0, "color").Get(color);
+            map.Find(0, "height").Get(out float height);
+
+            var underline = new Underline();
+            underline.Enable = enable;
+            underline.Color = color;
+            underline.Height = height;
+
+            return underline;
+        }
+
     }
 }
index b20db3c..26dd027 100755 (executable)
@@ -2064,5 +2064,34 @@ namespace Tizen.NUI
             [EditorBrowsable(EditorBrowsableState.Never)]
             public FontSlantType Slant { get; set; }
         }
+
+        /// <summary>
+        /// A struct to pass data of Underline PropertyMap. <br />
+        /// </summary>
+        /// <remarks>
+        /// The Underline struct is used as an argument to SetUnderline and GetUnderline methods. <br />
+        /// See <see cref="Tizen.NUI.BaseComponents.TextLabel.SetUnderline"/>, <see cref="Tizen.NUI.BaseComponents.TextLabel.GetUnderline"/>, <see cref="Tizen.NUI.BaseComponents.TextField.SetUnderline"/>, <see cref="Tizen.NUI.BaseComponents.TextField.GetUnderline"/>, <see cref="Tizen.NUI.BaseComponents.TextEditor.SetUnderline"/> and <see cref="Tizen.NUI.BaseComponents.TextEditor.GetUnderline"/>. <br />
+        /// </remarks>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public struct Underline
+        {
+            /// <summary>
+            /// Whether the underline is enabled (the default value is false).
+            /// </summary>
+            [EditorBrowsable(EditorBrowsableState.Never)]
+            public bool Enable { get; set; }
+
+            /// <summary>
+            /// The color of the underline (if not provided then the color of the text is used).
+            /// </summary>
+            [EditorBrowsable(EditorBrowsableState.Never)]
+            public Color Color { get; set; }
+
+            /// <summary>
+            /// The height in pixels of the underline (the default value is 1.0f, value can not be set to 0.0f, if set to 0.0f then the height is set to 1.0f).
+            /// </summary>
+            [EditorBrowsable(EditorBrowsableState.Never)]
+            public float Height { get; set; }
+        }
     }
 }