2 * Copyright(c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 extern alias TizenSystemSettings;
19 using TizenSystemSettings.Tizen.System;
22 using System.Globalization;
23 using System.ComponentModel;
25 using Tizen.NUI.Binding;
27 namespace Tizen.NUI.BaseComponents
30 /// A control which renders a short text string.<br />
31 /// Text labels are lightweight, non-editable, and do not respond to the user input.<br />
33 /// <since_tizen> 3 </since_tizen>
34 public partial class TextLabel : View
36 private class TextLayout : LayoutItem
38 protected override void OnMeasure(MeasureSpecification widthMeasureSpec, MeasureSpecification heightMeasureSpec)
40 // Padding will be automatically applied by DALi TextLabel.
41 float totalWidth = widthMeasureSpec.Size.AsDecimal();
42 float totalHeight = heightMeasureSpec.Size.AsDecimal();
44 if (widthMeasureSpec.Mode == MeasureSpecification.ModeType.Exactly)
46 if (heightMeasureSpec.Mode != MeasureSpecification.ModeType.Exactly)
48 totalHeight = Owner.GetHeightForWidth(totalWidth);
49 heightMeasureSpec = new MeasureSpecification(new LayoutLength(totalHeight), MeasureSpecification.ModeType.Exactly);
54 var minSize = Owner.MinimumSize;
55 var maxSize = Owner.MaximumSize;
56 var naturalSize = Owner.GetNaturalSize();
58 if (heightMeasureSpec.Mode == MeasureSpecification.ModeType.Exactly)
60 // GetWidthForHeight is not implemented.
61 float width = naturalSize != null ? naturalSize.Width : 0;
62 totalWidth = Math.Min(Math.Max(width, minSize.Width), (maxSize.Width < 0 ? Int32.MaxValue : maxSize.Width));
63 widthMeasureSpec = new MeasureSpecification(new LayoutLength(totalWidth), MeasureSpecification.ModeType.Exactly);
67 float width = naturalSize != null ? naturalSize.Width : 0;
68 float height = naturalSize != null ? naturalSize.Height : 0;
69 totalWidth = Math.Min(Math.Max(width, minSize.Width), (maxSize.Width < 0 ? Int32.MaxValue : maxSize.Width));
70 totalHeight = Math.Min(Math.Max(height, minSize.Height), (maxSize.Height < 0 ? Int32.MaxValue : maxSize.Height));
72 heightMeasureSpec = new MeasureSpecification(new LayoutLength(totalHeight), MeasureSpecification.ModeType.Exactly);
73 widthMeasureSpec = new MeasureSpecification(new LayoutLength(totalWidth), MeasureSpecification.ModeType.Exactly);
77 MeasuredSize.StateType childWidthState = MeasuredSize.StateType.MeasuredSizeOK;
78 MeasuredSize.StateType childHeightState = MeasuredSize.StateType.MeasuredSizeOK;
80 SetMeasuredDimensions(ResolveSizeAndState(new LayoutLength(totalWidth), widthMeasureSpec, childWidthState),
81 ResolveSizeAndState(new LayoutLength(totalHeight), heightMeasureSpec, childHeightState));
85 static TextLabel() { }
87 private static SystemFontTypeChanged systemFontTypeChanged = new SystemFontTypeChanged();
88 private static SystemFontSizeChanged systemFontSizeChanged = new SystemFontSizeChanged();
89 private static SystemLocaleLanguageChanged systemLocaleLanguageChanged = new SystemLocaleLanguageChanged();
90 static private string defaultStyleName = "Tizen.NUI.BaseComponents.TextLabel";
91 static private string defaultFontFamily = "BreezeSans";
92 private string textLabelSid = null;
93 private TextLabelSelectorData selectorData;
94 private string fontFamily = defaultFontFamily;
95 private float fontSizeScale = 1.0f;
96 private bool hasSystemLanguageChanged = false;
97 private bool hasSystemFontSizeChanged = false;
98 private bool hasSystemFontTypeChanged = false;
100 private Color internalTextColor;
103 /// Creates the TextLabel control.
105 /// <since_tizen> 3 </since_tizen>
106 public TextLabel() : this(Interop.TextLabel.New(ThemeManager.GetStyle(defaultStyleName) == null ? false : true), true)
108 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
111 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
112 [EditorBrowsable(EditorBrowsableState.Never)]
113 public TextLabel(TextLabelStyle viewStyle) : this(Interop.TextLabel.New(ThemeManager.GetStyle(defaultStyleName) == null ? false : true), true, viewStyle)
118 /// Creates the TextLabel with setting the status of shown or hidden.
120 /// <param name="shown">false : Not displayed (hidden), true : displayed (shown)</param>
121 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
122 [EditorBrowsable(EditorBrowsableState.Never)]
123 public TextLabel(bool shown) : this(Interop.TextLabel.New(ThemeManager.GetStyle(defaultStyleName) == null ? false : true), true)
125 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
130 /// Creates the TextLabel control.
132 /// <param name="text">The text to display</param>
133 /// <since_tizen> 3 </since_tizen>
134 public TextLabel(string text) : this(Interop.TextLabel.New(text, ThemeManager.GetStyle(defaultStyleName) == null ? false : true), true)
136 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
140 /// Creates the TextLabel with setting the status of shown or hidden.
142 /// <param name="text">The text to display</param>
143 /// <param name="shown">false : Not displayed (hidden), true : displayed (shown)</param>
144 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
145 [EditorBrowsable(EditorBrowsableState.Never)]
146 public TextLabel(string text, bool shown) : this(Interop.TextLabel.New(text, ThemeManager.GetStyle(defaultStyleName) == null ? false : true), true)
148 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
152 internal TextLabel(TextLabel handle, bool shown = true) : this(Interop.TextLabel.NewTextLabel(TextLabel.getCPtr(handle)), true)
154 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
162 internal TextLabel(global::System.IntPtr cPtr, bool cMemoryOwn, ViewStyle viewStyle, bool shown = true) : base(cPtr, cMemoryOwn, viewStyle)
170 internal TextLabel(global::System.IntPtr cPtr, bool cMemoryOwn, bool shown = true) : base(cPtr, cMemoryOwn, null)
178 private bool HasStyle()
180 return ThemeManager.GetStyle(this.GetType()) == null ? false : true;
184 /// The TranslatableText property.<br />
185 /// The text can set the SID value.<br />
187 /// <exception cref='ArgumentNullException'>
188 /// ResourceManager about multilingual is null.
190 /// <since_tizen> 4 </since_tizen>
191 public string TranslatableText
195 return (string)GetValue(TranslatableTextProperty);
199 SetValue(TranslatableTextProperty, value);
202 private string translatableText
210 if (NUIApplication.MultilingualResourceManager == null)
212 throw new ArgumentNullException(null, "ResourceManager about multilingual is null");
214 string translatableText = null;
215 textLabelSid = value;
216 translatableText = NUIApplication.MultilingualResourceManager?.GetString(textLabelSid, new CultureInfo(SystemSettings.LocaleLanguage.Replace("_", "-")));
217 if (translatableText != null)
219 Text = translatableText;
220 if (hasSystemLanguageChanged == false)
222 systemLocaleLanguageChanged.Add(SystemSettingsLocaleLanguageChanged);
223 hasSystemLanguageChanged = true;
230 NotifyPropertyChanged();
235 /// The Text property.<br />
236 /// The text to display in the UTF-8 format.<br />
238 /// <since_tizen> 3 </since_tizen>
243 return (string)GetValue(TextProperty);
247 SetValue(TextProperty, value);
248 NotifyPropertyChanged();
253 /// The FontFamily property.<br />
254 /// The requested font family to use.<br />
256 /// <since_tizen> 3 </since_tizen>
257 public string FontFamily
261 return (string)GetValue(FontFamilyProperty);
265 SetValue(FontFamilyProperty, value);
266 NotifyPropertyChanged();
270 private string InternalFontFamily
277 return Object.InternalGetPropertyString(this.SwigCPtr, TextLabel.Property.FontFamily);
281 string newFontFamily;
283 if (string.Equals(fontFamily, value)) return;
286 if (fontFamily == Tizen.NUI.FontFamily.UseSystemSetting)
290 newFontFamily = SystemSettings.FontType;
294 Console.WriteLine("{0} Exception caught.", e);
295 newFontFamily = defaultFontFamily;
297 AddSystemSettingsFontTypeChanged();
301 newFontFamily = fontFamily;
302 RemoveSystemSettingsFontTypeChanged();
305 SetInternalFontFamily(newFontFamily);
309 private void SetInternalFontFamily(string fontFamily)
311 Object.InternalSetPropertyString(this.SwigCPtr, TextLabel.Property.FontFamily, (string)fontFamily);
316 /// The FontStyle property.<br />
317 /// The requested font style to use.<br />
318 /// The fontStyle map contains the following keys :<br />
319 /// <list type="table">
320 /// <item><term>width (string)</term><description>The width key defines occupied by each glyph. (values: ultraCondensed, extraCondensed, condensed, semiCondensed, normal, semiExpanded, expanded, extraExpanded, ultraExpanded)</description></item>
321 /// <item><term>weight (string)</term><description>The weight key defines the thickness or darkness of the glyphs. (values: thin, ultraLight, extraLight, light, demiLight, semiLight, book, normal, regular, medium, demiBold, semiBold, bold, ultraBold, extraBold, black, heavy, extraBlack)</description></item>
322 /// <item><term>slant (string)</term><description>The slant key defines whether to use italics. (values: normal, roman, italic, oblique)</description></item>
325 /// <since_tizen> 3 </since_tizen>
326 [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1721: Property names should not match get methods")]
327 public PropertyMap FontStyle
331 return (PropertyMap)GetValue(FontStyleProperty);
335 SetValue(FontStyleProperty, value);
336 NotifyPropertyChanged();
341 /// Set FontStyle to TextLabel. <br />
343 /// <param name="fontStyle">The FontStyle</param>
345 /// SetFontStyle specifies the requested font style through <see cref="Tizen.NUI.Text.FontStyle"/>. <br />
348 /// The following example demonstrates how to use the SetFontStyle method.
350 /// var fontStyle = new Tizen.NUI.Text.FontStyle();
351 /// fontStyle.Width = FontWidthType.Expanded;
352 /// fontStyle.Weight = FontWeightType.Bold;
353 /// fontStyle.Slant = FontSlantType.Italic;
354 /// label.SetFontStyle(fontStyle);
357 [EditorBrowsable(EditorBrowsableState.Never)]
358 public void SetFontStyle(FontStyle fontStyle)
360 using (var fontStyleMap = TextMapHelper.GetFontStyleMap(fontStyle))
362 SetValue(FontStyleProperty, fontStyleMap);
367 /// Get FontStyle from TextLabel. <br />
369 /// <returns>The FontStyle</returns>
371 /// <see cref="Tizen.NUI.Text.FontStyle"/>
373 [EditorBrowsable(EditorBrowsableState.Never)]
374 public FontStyle GetFontStyle()
377 using (var fontStyleMap = (PropertyMap)GetValue(FontStyleProperty))
379 fontStyle = TextMapHelper.GetFontStyleStruct(fontStyleMap);
385 /// The PointSize property.<br />
386 /// The size of font in points.<br />
388 /// <since_tizen> 3 </since_tizen>
389 [Binding.TypeConverter(typeof(PointSizeTypeConverter))]
390 public float PointSize
394 return (float)GetValue(PointSizeProperty);
398 SetValue(PointSizeProperty, value);
399 NotifyPropertyChanged();
404 /// The MultiLine property.<br />
405 /// The single-line or multi-line layout option.<br />
407 /// <since_tizen> 3 </since_tizen>
408 public bool MultiLine
412 return (bool)GetValue(MultiLineProperty);
416 SetValue(MultiLineProperty, value);
417 NotifyPropertyChanged();
422 /// The HorizontalAlignment property.<br />
423 /// The line horizontal alignment.<br />
425 /// <since_tizen> 3 </since_tizen>
426 public HorizontalAlignment HorizontalAlignment
430 return (HorizontalAlignment)GetValue(HorizontalAlignmentProperty);
434 SetValue(HorizontalAlignmentProperty, value);
435 NotifyPropertyChanged();
440 /// The VerticalAlignment property.<br />
441 /// The line vertical alignment.<br />
443 /// <since_tizen> 3 </since_tizen>
444 public VerticalAlignment VerticalAlignment
448 return (VerticalAlignment)GetValue(VerticalAlignmentProperty);
452 SetValue(VerticalAlignmentProperty, value);
453 NotifyPropertyChanged();
458 /// The TextColor property.<br />
459 /// The color of the text.<br />
460 /// Animation framework can be used to change the color of the text when not using mark up.<br />
461 /// Cannot animate the color when text is auto scrolling.<br />
464 /// The property cascade chaining set is possible. For example, this (textLabel.TextColor.X = 0.1f;) is possible.
466 /// <since_tizen> 3 </since_tizen>
467 public Color TextColor
471 Color temp = (Color)GetValue(TextColorProperty);
472 return new Color(OnTextColorChanged, temp.R, temp.G, temp.B, temp.A);
476 SetValue(TextColorProperty, value);
477 NotifyPropertyChanged();
482 /// The ShadowOffset property.<br />
483 /// The drop shadow offset 0 indicates no shadow.<br />
485 /// <since_tizen> 3 </since_tizen>
487 /// Deprecated.(API Level 6) Use Shadow instead.
488 /// The property cascade chaining set is possible. For example, this (textLabel.ShadowOffset.X = 0.1f;) is possible.
490 [Obsolete("Do not use this ShadowOffset(Deprecated). Use Shadow instead.")]
491 public Vector2 ShadowOffset
495 return GetValue(ShadowOffsetProperty) as Vector2;
499 SetValue(ShadowOffsetProperty, value);
503 private Vector2 InternalShadowOffset
507 float x = 0.0f, y = 0.0f;
508 using (var propertyValue = Shadow.Find(TextLabel.Property.SHADOW, "offset"))
509 using (var shadowOffset = new Vector2())
511 if (null != propertyValue)
513 propertyValue.Get(shadowOffset);
518 return new Vector2(OnShadowOffsetChanged, x, y);
522 using (var map = new PropertyMap())
524 map.Add("offset", value);
526 var shadowMap = Shadow;
527 shadowMap.Merge(map);
529 SetValue(ShadowProperty, shadowMap);
530 NotifyPropertyChanged();
536 /// The ShadowColor property.<br />
537 /// The color of a drop shadow.<br />
539 /// <since_tizen> 3 </since_tizen>
541 /// Deprecated.(API Level 6) Use Shadow instead.
542 /// The property cascade chaining set is possible. For example, this (textLabel.ShadowColor.X = 0.1f;) is possible.
544 [Obsolete("Do not use this ShadowColor(Deprecated). Use Shadow instead.")]
545 public Vector4 ShadowColor
549 return GetValue(ShadowColorProperty) as Vector4;
553 SetValue(ShadowColorProperty, value);
557 private Vector4 InternalShadowColor
561 float x = 0.0f, y = 0.0f, z = 0.0f, w = 0.0f;
562 using (var propertyValue = Shadow.Find(TextLabel.Property.SHADOW, "color"))
563 using (var shadowColor = new Vector4())
565 if (null != propertyValue)
567 propertyValue.Get(shadowColor);
574 return new Vector4(OnShadowColorChanged, x, y, z, w);
578 using (var map = new PropertyMap())
580 map.Add("color", value);
581 var shadowMap = Shadow;
582 shadowMap.Merge(map);
583 SetValue(ShadowProperty, shadowMap);
584 NotifyPropertyChanged();
590 /// The UnderlineEnabled property.<br />
591 /// The underline enabled flag.<br />
593 /// <since_tizen> 3 </since_tizen>
595 /// Deprecated.(API Level 6) Use Underline instead.
597 [Obsolete("Do not use this UnderlineEnabled(Deprecated). Use Underline instead.")]
598 public bool UnderlineEnabled
602 return (bool)GetValue(UnderlineEnabledProperty);
606 SetValue(UnderlineEnabledProperty, value);
610 private bool InternalUnderlineEnabled
614 bool underlineEnabled = false;
615 using (var propertyValue = Underline.Find(TextLabel.Property.UNDERLINE, "enable"))
617 if (propertyValue != null)
619 propertyValue.Get(out underlineEnabled);
622 return underlineEnabled;
626 using (var map = new PropertyMap())
628 map.Add("enable", value);
629 var undelineMap = Underline;
630 undelineMap.Merge(map);
631 SetValue(UnderlineProperty, undelineMap);
632 NotifyPropertyChanged();
638 /// The UnderlineColor property.<br />
639 /// Overrides the underline height from font metrics.<br />
641 /// <since_tizen> 3 </since_tizen>
643 /// Deprecated.(API Level 6) Use Underline instead.
644 /// The property cascade chaining set is possible. For example, this (textLabel.UnderlineColor.X = 0.1f;) is possible.
646 [Obsolete("Do not use this UnderlineColor(Deprecated). Use Underline instead.")]
647 public Vector4 UnderlineColor
651 return GetValue(UnderlineColorProperty) as Vector4;
655 SetValue(UnderlineColorProperty, value);
659 private Vector4 InternalUnderlineColor
663 float x = 0.0f, y = 0.0f, z = 0.0f, w = 0.0f;
664 using (var propertyValue = Underline.Find(TextLabel.Property.UNDERLINE, "color"))
665 using (var underlineColor = new Vector4())
667 if (null != propertyValue)
669 propertyValue.Get(underlineColor);
670 x = underlineColor.X;
671 y = underlineColor.Y;
672 z = underlineColor.Z;
673 w = underlineColor.W;
676 return new Vector4(OnUnderlineColorChanged, x, y, z, w);
680 using (var map = new PropertyMap())
682 map.Add("color", value);
683 var undelineMap = Underline;
684 undelineMap.Merge(map);
685 SetValue(UnderlineProperty, undelineMap);
686 NotifyPropertyChanged();
692 /// The UnderlineHeight property.<br />
693 /// Overrides the underline height from font metrics.<br />
695 /// <since_tizen> 3 </since_tizen>
697 /// Deprecated.(API Level 6) Use Underline instead.
699 [Obsolete("Do not use this UnderlineHeight(Deprecated). Use Underline instead.")]
700 public float UnderlineHeight
704 return (float)GetValue(UnderlineHeightProperty);
708 SetValue(UnderlineHeightProperty, value);
712 private float InternalUnderlineHeight
716 float underlineHeight = 0.0f;
717 using (var propertyValue = Underline.Find(TextLabel.Property.UNDERLINE, "height"))
719 if (null != propertyValue)
721 propertyValue.Get(out underlineHeight);
724 return underlineHeight;
728 using (var map = new PropertyMap())
730 map.Add("height", value);
731 var undelineMap = Underline;
732 undelineMap.Merge(map);
733 SetValue(UnderlineProperty, undelineMap);
734 NotifyPropertyChanged();
740 /// The EnableMarkup property.<br />
741 /// Whether the mark-up processing is enabled.<br />
743 /// <since_tizen> 3 </since_tizen>
744 public bool EnableMarkup
748 return (bool)GetValue(EnableMarkupProperty);
752 SetValue(EnableMarkupProperty, value);
753 NotifyPropertyChanged();
758 /// The EnableAutoScroll property.<br />
759 /// Starts or stops auto scrolling.<br />
761 /// <since_tizen> 3 </since_tizen>
762 public bool EnableAutoScroll
766 return (bool)GetValue(EnableAutoScrollProperty);
770 SetValue(EnableAutoScrollProperty, value);
771 NotifyPropertyChanged();
776 /// The AutoScrollSpeed property.<br />
777 /// Sets the speed of scrolling in pixels per second.<br />
779 /// <since_tizen> 3 </since_tizen>
780 public int AutoScrollSpeed
784 return (int)GetValue(AutoScrollSpeedProperty);
788 SetValue(AutoScrollSpeedProperty, value);
789 NotifyPropertyChanged();
794 /// The AutoScrollLoopCount property.<br />
795 /// Number of complete loops when scrolling enabled.<br />
797 /// <since_tizen> 3 </since_tizen>
798 public int AutoScrollLoopCount
802 return (int)GetValue(AutoScrollLoopCountProperty);
806 SetValue(AutoScrollLoopCountProperty, value);
807 NotifyPropertyChanged();
812 /// The AutoScrollGap property.<br />
813 /// Gap before scrolling wraps.<br />
815 /// <since_tizen> 3 </since_tizen>
816 public float AutoScrollGap
820 return (float)GetValue(AutoScrollGapProperty);
824 SetValue(AutoScrollGapProperty, value);
825 NotifyPropertyChanged();
830 /// The LineSpacing property.<br />
831 /// The default extra space between lines in points.<br />
833 /// <since_tizen> 3 </since_tizen>
834 public float LineSpacing
838 return (float)GetValue(LineSpacingProperty);
842 SetValue(LineSpacingProperty, value);
843 NotifyPropertyChanged();
848 /// The relative height of the line (a factor that will be multiplied by text height). <br />
849 /// If the value is less than 1, the lines could to be overlapped.
851 [EditorBrowsable(EditorBrowsableState.Never)]
852 public float RelativeLineHeight
856 return (float)GetValue(RelativeLineHeightProperty);
860 SetValue(RelativeLineHeightProperty, value);
861 NotifyPropertyChanged();
866 /// The Underline property.<br />
867 /// The default underline parameters.<br />
868 /// The underline map contains the following keys :<br />
869 /// <list type="table">
870 /// <item><term>enable (bool)</term><description>Whether the underline is enabled (the default value is false)</description></item>
871 /// <item><term>color (Color)</term><description>The color of the underline (If not provided then the color of the text is used)</description></item>
872 /// <item><term>height (float)</term><description>The height in pixels of the underline (the default value is 1.f)</description></item>
875 /// <since_tizen> 3 </since_tizen>
876 [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1721: Property names should not match get methods")]
877 public PropertyMap Underline
881 return (PropertyMap)GetValue(UnderlineProperty);
885 SetValue(UnderlineProperty, value);
886 NotifyPropertyChanged();
891 /// Set Underline to TextLabel. <br />
893 /// <param name="underline">The Underline</param>
895 /// SetUnderline specifies the underline of the text through <see cref="Tizen.NUI.Text.Underline"/>. <br />
898 /// The following example demonstrates how to use the SetUnderline method.
900 /// var underline = new Tizen.NUI.Text.Underline();
901 /// underline.Enable = true;
902 /// underline.Color = new Color("#3498DB");
903 /// underline.Height = 2.0f;
904 /// label.SetUnderline(underline);
907 [EditorBrowsable(EditorBrowsableState.Never)]
908 public void SetUnderline(Underline underline)
910 using (var underlineMap = TextMapHelper.GetUnderlineMap(underline))
912 SetValue(UnderlineProperty, underlineMap);
917 /// Get Underline from TextLabel. <br />
919 /// <returns>The Underline</returns>
921 /// <see cref="Tizen.NUI.Text.Underline"/>
923 [EditorBrowsable(EditorBrowsableState.Never)]
924 public Underline GetUnderline()
927 using (var underlineMap = (PropertyMap)GetValue(UnderlineProperty))
929 underline = TextMapHelper.GetUnderlineStruct(underlineMap);
935 /// The Shadow property.<br />
936 /// The default shadow parameters.<br />
937 /// The shadow map contains the following keys :<br />
938 /// <list type="table">
939 /// <item><term>color (Color)</term><description>The color of the shadow (the default color is Color.Black)</description></item>
940 /// <item><term>offset (Vector2)</term><description>The offset in pixels of the shadow (If not provided then the shadow is not enabled)</description></item>
941 /// <item><term>blurRadius (float)</term><description>The radius of the Gaussian blur for the soft shadow (If not provided then the soft shadow is not enabled)</description></item>
944 /// <since_tizen> 3 </since_tizen>
945 [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1721: Property names should not match get methods")]
946 public PropertyMap Shadow
950 return (PropertyMap)GetValue(ShadowProperty);
954 SetValue(ShadowProperty, value);
955 NotifyPropertyChanged();
960 /// Set Shadow to TextLabel. <br />
962 /// <param name="shadow">The Shadow</param>
964 /// SetShadow specifies the shadow of the text through <see cref="Tizen.NUI.Text.Shadow"/>. <br />
967 /// The following example demonstrates how to use the SetShadow method.
969 /// var shadow = new Tizen.NUI.Text.Shadow();
970 /// shadow.Offset = new Vector2(3, 3);
971 /// shadow.Color = new Color("#F1C40F");
972 /// shadow.BlurRadius = 4.0f;
973 /// label.SetShadow(shadow);
976 [EditorBrowsable(EditorBrowsableState.Never)]
977 public void SetShadow(Tizen.NUI.Text.Shadow shadow)
979 using (var shadowMap = TextMapHelper.GetShadowMap(shadow))
981 SetValue(ShadowProperty, shadowMap);
986 /// Get Shadow from TextLabel. <br />
988 /// <returns>The Shadow</returns>
990 /// <see cref="Tizen.NUI.Text.Shadow"/>
992 [EditorBrowsable(EditorBrowsableState.Never)]
993 public Tizen.NUI.Text.Shadow GetShadow()
995 Tizen.NUI.Text.Shadow shadow;
996 using (var shadowMap = (PropertyMap)GetValue(ShadowProperty))
998 shadow = TextMapHelper.GetShadowStruct(shadowMap);
1004 /// Describes a text shadow for a TextLabel.
1005 /// It is null by default.
1007 [EditorBrowsable(EditorBrowsableState.Never)]
1008 public TextShadow TextShadow
1012 return (TextShadow)GetValue(TextShadowProperty);
1016 SetValue(TextShadowProperty, value);
1017 NotifyPropertyChanged();
1022 /// The Emboss property.<br />
1023 /// The default emboss parameters.<br />
1025 /// <since_tizen> 3 </since_tizen>
1026 public string Emboss
1030 return (string)GetValue(EmbossProperty);
1034 SetValue(EmbossProperty, value);
1035 NotifyPropertyChanged();
1040 /// The Outline property.<br />
1041 /// The default outline parameters.<br />
1042 /// The outline map contains the following keys :<br />
1043 /// <list type="table">
1044 /// <item><term>color (Color)</term><description>The color of the outline (the default color is Color.White)</description></item>
1045 /// <item><term>width (float)</term><description>The width in pixels of the outline (If not provided then the outline is not enabled)</description></item>
1048 /// <since_tizen> 3 </since_tizen>
1049 [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1721: Property names should not match get methods")]
1050 public PropertyMap Outline
1054 return (PropertyMap)GetValue(OutlineProperty);
1058 SetValue(OutlineProperty, value);
1059 NotifyPropertyChanged();
1064 /// Set Outline to TextLabel. <br />
1066 /// <param name="outline">The Outline</param>
1068 /// SetOutline specifies the outline of the text through <see cref="Tizen.NUI.Text.Outline"/>. <br />
1071 /// The following example demonstrates how to use the SetOutline method.
1073 /// var outline = new Tizen.NUI.Text.Outline();
1074 /// outline.Width = 2.0f;
1075 /// outline.Color = new Color("#45B39D");
1076 /// label.SetOutline(outline);
1079 [EditorBrowsable(EditorBrowsableState.Never)]
1080 public void SetOutline(Outline outline)
1082 using (var outlineMap = TextMapHelper.GetOutlineMap(outline))
1084 SetValue(OutlineProperty, outlineMap);
1089 /// Get Outline from TextLabel. <br />
1091 /// <returns>The Outline</returns>
1093 /// <see cref="Tizen.NUI.Text.Outline"/>
1095 [EditorBrowsable(EditorBrowsableState.Never)]
1096 public Outline GetOutline()
1099 using (var outlineMap = (PropertyMap)GetValue(OutlineProperty))
1101 outline = TextMapHelper.GetOutlineStruct(outlineMap);
1107 /// Set Strikethrough to TextLabel. <br />
1109 /// <param name="strikethrough">The Strikethrough</param>
1111 /// SetStrikethrough specifies the strikethrough of the text through <see cref="Tizen.NUI.Text.Strikethrough"/>. <br />
1114 /// The following example demonstrates how to use the SetStrikethrough method.
1116 /// var strikethrough = new Tizen.NUI.Text.Strikethrough();
1117 /// strikethrough.Enable = true;
1118 /// strikethrough.Color = new Color("#3498DB");
1119 /// strikethrough.Height = 2.0f;
1120 /// label.SetStrikethrough(strikethrough);
1123 [EditorBrowsable(EditorBrowsableState.Never)]
1124 public void SetStrikethrough(Strikethrough strikethrough)
1126 using (var map = TextMapHelper.GetStrikethroughMap(strikethrough))
1127 using (var propertyValue = new PropertyValue(map))
1129 SetProperty(TextLabel.Property.Strikethrough, propertyValue);
1134 /// Get Strikethrough from TextLabel. <br />
1136 /// <returns>The Strikethrough</returns>
1138 /// <see cref="Tizen.NUI.Text.Strikethrough"/>
1140 [EditorBrowsable(EditorBrowsableState.Never)]
1141 public Strikethrough GetStrikethrough()
1143 Strikethrough strikethrough;
1144 using (var propertyValue = GetProperty(TextLabel.Property.Strikethrough))
1145 using (var map = new PropertyMap())
1147 propertyValue.Get(map);
1148 strikethrough = TextMapHelper.GetStrikethroughStruct(map);
1150 return strikethrough;
1154 /// The PixelSize property.<br />
1155 /// The size of font in pixels.<br />
1157 /// <since_tizen> 3 </since_tizen>
1158 [Binding.TypeConverter(typeof(FloatGraphicsTypeConverter))]
1159 public float PixelSize
1163 return (float)GetValue(PixelSizeProperty);
1167 SetValue(PixelSizeProperty, value);
1168 NotifyPropertyChanged();
1173 /// The Ellipsis property.<br />
1174 /// Enable or disable the ellipsis.<br />
1176 /// <since_tizen> 3 </since_tizen>
1177 public bool Ellipsis
1181 return (bool)GetValue(EllipsisProperty);
1185 SetValue(EllipsisProperty, value);
1186 NotifyPropertyChanged();
1191 /// The ellipsis position of the text.
1192 /// Specifies which portion of the text should be replaced with an ellipsis when the text size exceeds the layout size.<br />
1194 /// <since_tizen> 9 </since_tizen>
1195 public EllipsisPosition EllipsisPosition
1199 return (EllipsisPosition)GetValue(EllipsisPositionProperty);
1203 SetValue(EllipsisPositionProperty, value);
1204 NotifyPropertyChanged();
1209 /// The AutoScrollLoopDelay property.<br />
1210 /// The amount of time to delay the starting time of auto scrolling and further loops.<br />
1212 /// <since_tizen> 3 </since_tizen>
1213 public float AutoScrollLoopDelay
1217 return (float)GetValue(AutoScrollLoopDelayProperty);
1221 SetValue(AutoScrollLoopDelayProperty, value);
1222 NotifyPropertyChanged();
1227 /// The AutoScrollStopMode property.<br />
1228 /// The auto scrolling stop behaviour.<br />
1229 /// The default value is AutoScrollStopMode.FinishLoop. <br />
1231 /// <since_tizen> 3 </since_tizen>
1232 public AutoScrollStopMode AutoScrollStopMode
1236 return (AutoScrollStopMode)GetValue(AutoScrollStopModeProperty);
1240 SetValue(AutoScrollStopModeProperty, value);
1241 NotifyPropertyChanged();
1246 /// The line count of the text.
1248 /// <since_tizen> 3 </since_tizen>
1249 public int LineCount
1254 using (var propertyValue = GetProperty(TextLabel.Property.LineCount))
1256 propertyValue.Get(out lineCount);
1263 /// The LineWrapMode property.<br />
1264 /// line wrap mode when the text lines over layout width.<br />
1266 /// <since_tizen> 4 </since_tizen>
1267 public LineWrapMode LineWrapMode
1271 return (LineWrapMode)GetValue(LineWrapModeProperty);
1275 SetValue(LineWrapModeProperty, value);
1276 NotifyPropertyChanged();
1281 /// The direction of the text such as left to right or right to left.
1283 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
1284 [EditorBrowsable(EditorBrowsableState.Never)]
1285 public TextDirection TextDirection
1289 int textDirection = 0;
1290 using (var propertyValue = GetProperty(TextLabel.Property.TextDirection))
1292 propertyValue.Get(out textDirection);
1294 return (TextDirection)textDirection;
1299 /// The vertical line alignment of the text.
1301 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
1302 [EditorBrowsable(EditorBrowsableState.Never)]
1303 public VerticalLineAlignment VerticalLineAlignment
1307 return (VerticalLineAlignment)GetValue(VerticalLineAlignmentProperty);
1311 SetValue(VerticalLineAlignmentProperty, value);
1312 NotifyPropertyChanged();
1317 /// The text alignment to match the direction of the system language.
1319 /// <since_tizen> 6 </since_tizen>
1320 public bool MatchSystemLanguageDirection
1324 return (bool)GetValue(MatchSystemLanguageDirectionProperty);
1328 SetValue(MatchSystemLanguageDirectionProperty, value);
1329 NotifyPropertyChanged();
1334 /// The text fit parameters.<br />
1335 /// The textFit map contains the following keys :<br />
1336 /// <list type="table">
1337 /// <item><term>enable (bool)</term><description>True to enable the text fit or false to disable (the default value is false)</description></item>
1338 /// <item><term>minSize (float)</term><description>Minimum Size for text fit (the default value is 10.f)</description></item>
1339 /// <item><term>maxSize (float)</term><description>Maximum Size for text fit (the default value is 100.f)</description></item>
1340 /// <item><term>stepSize (float)</term><description>Step Size for font increase (the default value is 1.f)</description></item>
1341 /// <item><term>fontSize (string)</term><description>The size type of font, You can choose between "pointSize" or "pixelSize". (the default value is "pointSize")</description></item>
1344 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
1345 [EditorBrowsable(EditorBrowsableState.Never)]
1346 [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1721: Property names should not match get methods")]
1347 public PropertyMap TextFit
1351 return (PropertyMap)GetValue(TextFitProperty);
1355 SetValue(TextFitProperty, value);
1356 NotifyPropertyChanged();
1361 /// Set TextFit to TextLabel. <br />
1363 /// <param name="textFit">The TextFit</param>
1365 /// SetTextFit specifies the textFit of the text through <see cref="Tizen.NUI.Text.TextFit"/>. <br />
1368 /// The following example demonstrates how to use the SetTextFit method.
1370 /// var textFit = new Tizen.NUI.Text.TextFit();
1371 /// textFit.Enable = true;
1372 /// textFit.MinSize = 10.0f;
1373 /// textFit.MaxSize = 100.0f;
1374 /// textFit.StepSize = 5.0f;
1375 /// textFit.FontSizeType = FontSizeType.PointSize;
1376 /// label.SetTextFit(textFit);
1379 [EditorBrowsable(EditorBrowsableState.Never)]
1380 public void SetTextFit(TextFit textFit)
1382 using (var textFitMap = TextMapHelper.GetTextFitMap(textFit))
1384 SetValue(TextFitProperty, textFitMap);
1389 /// Get TextFit from TextLabel. <br />
1391 /// <returns>The TextFit</returns>
1393 /// TextFit is always returned based on PointSize. <br />
1394 /// If the user sets FontSizeType to PixelSize, then MinSize, MaxSize, and StepSize are converted based on PointSize and returned. <br />
1395 /// <see cref="Tizen.NUI.Text.TextFit"/>
1397 [EditorBrowsable(EditorBrowsableState.Never)]
1398 public TextFit GetTextFit()
1401 using (var textFitMap = (PropertyMap)GetValue(TextFitProperty))
1403 textFit = TextMapHelper.GetTextFitStruct(textFitMap);
1409 /// The MinLineSize property.<br />
1410 /// The height of the line in points. <br />
1411 /// If the font size is larger than the line size, it works with the font size. <br />
1413 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
1414 [EditorBrowsable(EditorBrowsableState.Never)]
1415 public float MinLineSize
1419 return (float)GetValue(MinLineSizeProperty);
1423 SetValue(MinLineSizeProperty, value);
1424 NotifyPropertyChanged();
1429 /// The spaces between characters in Pixels.
1431 /// A positive value will make the characters far apart (expanded) and a negative value will bring them closer (condensed).<br />
1432 /// The default value is 0.f which does nothing.
1435 [EditorBrowsable(EditorBrowsableState.Never)]
1436 public float CharacterSpacing
1440 return (float)GetValue(CharacterSpacingProperty);
1444 SetValue(CharacterSpacingProperty, value);
1445 NotifyPropertyChanged();
1450 /// The FontSizeScale property for scaling the specified font size up or down. <br />
1451 /// The default value is 1.0. <br />
1452 /// The given font size scale value is used for multiplying the specified font size before querying fonts. <br />
1453 /// If FontSizeScale.UseSystemSetting, will use the SystemSettings.FontSize internally. <br />
1455 /// <since_tizen> 9 </since_tizen>
1456 public float FontSizeScale
1460 return (float)GetValue(FontSizeScaleProperty);
1464 SetValue(FontSizeScaleProperty, value);
1465 NotifyPropertyChanged();
1469 private float InternalFontSizeScale
1473 return fontSizeScale;
1477 float newFontSizeScale;
1479 if (fontSizeScale == value) return;
1481 fontSizeScale = value;
1482 if (fontSizeScale == Tizen.NUI.FontSizeScale.UseSystemSetting)
1484 SystemSettingsFontSize systemSettingsFontSize;
1488 systemSettingsFontSize = SystemSettings.FontSize;
1492 Console.WriteLine("{0} Exception caught.", e);
1493 systemSettingsFontSize = SystemSettingsFontSize.Normal;
1495 newFontSizeScale = TextUtils.GetFontSizeScale(systemSettingsFontSize);
1496 AddSystemSettingsFontSizeChanged();
1500 newFontSizeScale = fontSizeScale;
1501 RemoveSystemSettingsFontSizeChanged();
1504 SetInternalFontSizeScale(newFontSizeScale);
1508 private void SetInternalFontSizeScale(float fontSizeScale)
1511 Object.InternalSetPropertyFloat(this.SwigCPtr, TextLabel.Property.FontSizeScale, (float)fontSizeScale);
1516 /// The EnableFontSizeScale property.<br />
1517 /// Whether the font size scale is enabled. (The default value is true)
1519 [EditorBrowsable(EditorBrowsableState.Never)]
1520 public bool EnableFontSizeScale
1524 return (bool)GetValue(EnableFontSizeScaleProperty);
1528 SetValue(EnableFontSizeScaleProperty, value);
1529 NotifyPropertyChanged();
1533 private TextLabelSelectorData EnsureSelectorData() => selectorData ?? (selectorData = new TextLabelSelectorData());
1536 /// Downcasts a handle to textLabel handle
1538 /// <param name="handle"></param>
1539 /// <returns></returns>
1540 /// <exception cref="ArgumentNullException"> Thrown when handle is null. </exception>
1541 /// <since_tizen> 3 </since_tizen>
1542 /// Do not use this, that will be deprecated. Use as keyword instead.
1543 [Obsolete("Do not use this, that will be deprecated. Use as keyword instead. " +
1545 "BaseHandle handle = new TextLabel(\"Hello World!\"); " +
1546 "TextLabel label = handle as TextLabel")]
1547 [EditorBrowsable(EditorBrowsableState.Never)]
1548 public static TextLabel DownCast(BaseHandle handle)
1552 throw new ArgumentNullException(nameof(handle));
1554 TextLabel ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as TextLabel;
1555 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1560 [EditorBrowsable(EditorBrowsableState.Never)]
1561 protected override void Dispose(DisposeTypes type)
1568 internalTextColor?.Dispose();
1570 if (hasSystemLanguageChanged)
1572 systemLocaleLanguageChanged.Remove(SystemSettingsLocaleLanguageChanged);
1575 RemoveSystemSettingsFontTypeChanged();
1576 RemoveSystemSettingsFontSizeChanged();
1578 if (type == DisposeTypes.Explicit)
1581 //Release your own managed resources here.
1582 //You should release all of your own disposable objects here.
1583 selectorData?.Reset(this);
1588 if (textLabelTextFitChangedCallbackDelegate != null)
1590 TextFitChangedSignal().Disconnect(textLabelTextFitChangedCallbackDelegate);
1597 /// This will not be public opened.
1598 [EditorBrowsable(EditorBrowsableState.Never)]
1599 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
1601 Interop.TextLabel.DeleteTextLabel(swigCPtr);
1605 /// Get attribues, it is abstract function and must be override.
1607 [EditorBrowsable(EditorBrowsableState.Never)]
1608 protected override ViewStyle CreateViewStyle()
1610 return new TextLabelStyle();
1613 internal override LayoutItem CreateDefaultLayout()
1615 return new TextLayout();
1619 /// Invoked whenever the binding context of the textlabel changes. Implement this method to add class handling for this event.
1621 protected override void OnBindingContextChanged()
1623 base.OnBindingContextChanged();
1626 private void SystemSettingsLocaleLanguageChanged(object sender, LocaleLanguageChangedEventArgs e)
1628 Text = NUIApplication.MultilingualResourceManager?.GetString(textLabelSid, new CultureInfo(e.Value.Replace("_", "-")));
1631 private void SystemSettingsFontSizeChanged(object sender, FontSizeChangedEventArgs e)
1633 float newFontSizeScale = TextUtils.GetFontSizeScale(e.Value);
1634 SetInternalFontSizeScale(newFontSizeScale);
1637 private void AddSystemSettingsFontSizeChanged()
1639 if (hasSystemFontSizeChanged != true)
1643 systemFontSizeChanged.Add(SystemSettingsFontSizeChanged);
1644 hasSystemFontSizeChanged = true;
1648 Console.WriteLine("{0} Exception caught.", e);
1649 hasSystemFontSizeChanged = false;
1654 private void RemoveSystemSettingsFontSizeChanged()
1656 if (hasSystemFontSizeChanged == true)
1660 systemFontSizeChanged.Remove(SystemSettingsFontSizeChanged);
1661 hasSystemFontSizeChanged = false;
1665 Console.WriteLine("{0} Exception caught.", e);
1666 hasSystemFontSizeChanged = true;
1671 private void SystemSettingsFontTypeChanged(object sender, FontTypeChangedEventArgs e)
1673 SetInternalFontFamily(e.Value);
1676 private void AddSystemSettingsFontTypeChanged()
1678 if (HasStyle() && !hasSystemFontTypeChanged)
1682 systemFontTypeChanged.Add(SystemSettingsFontTypeChanged);
1683 hasSystemFontTypeChanged = true;
1687 Console.WriteLine("{0} Exception caught.", e);
1688 hasSystemFontTypeChanged = false;
1693 private void RemoveSystemSettingsFontTypeChanged()
1695 if (hasSystemFontTypeChanged)
1699 systemFontTypeChanged.Remove(SystemSettingsFontTypeChanged);
1700 hasSystemFontTypeChanged = false;
1704 Console.WriteLine("{0} Exception caught.", e);
1705 hasSystemFontTypeChanged = true;
1710 private void RequestLayout()
1712 Layout?.RequestLayout();
1715 internal new class Property
1717 internal static readonly int TEXT = Interop.TextLabel.TextGet();
1718 internal static readonly int FontFamily = Interop.TextLabel.FontFamilyGet();
1719 internal static readonly int FontStyle = Interop.TextLabel.FontStyleGet();
1720 internal static readonly int PointSize = Interop.TextLabel.PointSizeGet();
1721 internal static readonly int MultiLine = Interop.TextLabel.MultiLineGet();
1722 internal static readonly int HorizontalAlignment = Interop.TextLabel.HorizontalAlignmentGet();
1723 internal static readonly int VerticalAlignment = Interop.TextLabel.VerticalAlignmentGet();
1724 internal static readonly int TextColor = Interop.TextLabel.TextColorGet();
1725 internal static readonly int EnableMarkup = Interop.TextLabel.EnableMarkupGet();
1726 internal static readonly int EnableAutoScroll = Interop.TextLabel.EnableAutoScrollGet();
1727 internal static readonly int AutoScrollSpeed = Interop.TextLabel.AutoScrollSpeedGet();
1728 internal static readonly int AutoScrollLoopCount = Interop.TextLabel.AutoScrollLoopCountGet();
1729 internal static readonly int AutoScrollGap = Interop.TextLabel.AutoScrollGapGet();
1730 internal static readonly int LineSpacing = Interop.TextLabel.LineSpacingGet();
1731 internal static readonly int RelativeLineHeight = Interop.TextLabel.RelativeLineHeightGet();
1732 internal static readonly int UNDERLINE = Interop.TextLabel.UnderlineGet();
1733 internal static readonly int SHADOW = Interop.TextLabel.ShadowGet();
1734 internal static readonly int EMBOSS = Interop.TextLabel.EmbossGet();
1735 internal static readonly int OUTLINE = Interop.TextLabel.OutlineGet();
1736 internal static readonly int PixelSize = Interop.TextLabel.PixelSizeGet();
1737 internal static readonly int ELLIPSIS = Interop.TextLabel.EllipsisGet();
1738 internal static readonly int AutoScrollStopMode = Interop.TextLabel.AutoScrollStopModeGet();
1739 internal static readonly int AutoScrollLoopDelay = Interop.TextLabel.AutoScrollLoopDelayGet();
1740 internal static readonly int LineCount = Interop.TextLabel.LineCountGet();
1741 internal static readonly int LineWrapMode = Interop.TextLabel.LineWrapModeGet();
1742 internal static readonly int TextDirection = Interop.TextLabel.TextDirectionGet();
1743 internal static readonly int VerticalLineAlignment = Interop.TextLabel.VerticalLineAlignmentGet();
1744 internal static readonly int MatchSystemLanguageDirection = Interop.TextLabel.MatchSystemLanguageDirectionGet();
1745 internal static readonly int TextFit = Interop.TextLabel.TextFitGet();
1746 internal static readonly int MinLineSize = Interop.TextLabel.MinLineSizeGet();
1747 internal static readonly int FontSizeScale = Interop.TextLabel.FontSizeScaleGet();
1748 internal static readonly int EnableFontSizeScale = Interop.TextLabel.EnableFontSizeScaleGet();
1749 internal static readonly int EllipsisPosition = Interop.TextLabel.EllipsisPositionGet();
1750 internal static readonly int Strikethrough = Interop.TextLabel.StrikethroughGet();
1751 internal static readonly int CharacterSpacing = Interop.TextLabel.CharacterSpacingGet();
1754 private void OnShadowColorChanged(float x, float y, float z, float w)
1756 ShadowColor = new Vector4(x, y, z, w);
1758 private void OnShadowOffsetChanged(float x, float y)
1760 ShadowOffset = new Vector2(x, y);
1762 private void OnTextColorChanged(float r, float g, float b, float a)
1764 TextColor = new Color(r, g, b, a);
1766 private void OnUnderlineColorChanged(float x, float y, float z, float w)
1768 UnderlineColor = new Vector4(x, y, z, w);