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 SystemLocaleLanguageChanged systemLocaleLanguageChanged = new SystemLocaleLanguageChanged();
89 static private string defaultStyleName = "Tizen.NUI.BaseComponents.TextLabel";
90 static private string defaultFontFamily = "BreezeSans";
91 private string textLabelSid = null;
92 private TextLabelSelectorData selectorData;
93 private string fontFamily = defaultFontFamily;
94 private float fontSizeScale = 1.0f;
95 private bool hasSystemLanguageChanged = false;
96 private bool hasSystemFontSizeChanged = false;
97 private bool hasSystemFontTypeChanged = false;
99 private Color internalTextColor;
102 /// Creates the TextLabel control.
104 /// <since_tizen> 3 </since_tizen>
105 public TextLabel() : this(Interop.TextLabel.New(ThemeManager.GetStyle(defaultStyleName) == null ? false : true), true)
107 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
110 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
111 [EditorBrowsable(EditorBrowsableState.Never)]
112 public TextLabel(TextLabelStyle viewStyle) : this(Interop.TextLabel.New(ThemeManager.GetStyle(defaultStyleName) == null ? false : true), true, viewStyle)
117 /// Creates the TextLabel with setting the status of shown or hidden.
119 /// <param name="shown">false : Not displayed (hidden), true : displayed (shown)</param>
120 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
121 [EditorBrowsable(EditorBrowsableState.Never)]
122 public TextLabel(bool shown) : this(Interop.TextLabel.New(ThemeManager.GetStyle(defaultStyleName) == null ? false : true), true)
124 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
129 /// Creates the TextLabel control.
131 /// <param name="text">The text to display</param>
132 /// <since_tizen> 3 </since_tizen>
133 public TextLabel(string text) : this(Interop.TextLabel.New(text, ThemeManager.GetStyle(defaultStyleName) == null ? false : true), true)
135 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
139 /// Creates the TextLabel with setting the status of shown or hidden.
141 /// <param name="text">The text to display</param>
142 /// <param name="shown">false : Not displayed (hidden), true : displayed (shown)</param>
143 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
144 [EditorBrowsable(EditorBrowsableState.Never)]
145 public TextLabel(string text, bool shown) : this(Interop.TextLabel.New(text, ThemeManager.GetStyle(defaultStyleName) == null ? false : true), true)
147 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
151 internal TextLabel(TextLabel handle, bool shown = true) : this(Interop.TextLabel.NewTextLabel(TextLabel.getCPtr(handle)), true)
153 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
161 internal TextLabel(global::System.IntPtr cPtr, bool cMemoryOwn, ViewStyle viewStyle, bool shown = true) : base(cPtr, cMemoryOwn, viewStyle)
169 internal TextLabel(global::System.IntPtr cPtr, bool cMemoryOwn, bool shown = true) : base(cPtr, cMemoryOwn, null)
177 private bool HasStyle()
179 return ThemeManager.GetStyle(this.GetType()) == null ? false : true;
183 /// The TranslatableText property.<br />
184 /// The text can set the SID value.<br />
186 /// <exception cref='ArgumentNullException'>
187 /// ResourceManager about multilingual is null.
189 /// <since_tizen> 4 </since_tizen>
190 public string TranslatableText
194 return (string)GetValue(TranslatableTextProperty);
198 SetValue(TranslatableTextProperty, value);
201 private string translatableText
209 if (NUIApplication.MultilingualResourceManager == null)
211 throw new ArgumentNullException(null, "ResourceManager about multilingual is null");
213 string translatableText = null;
214 textLabelSid = value;
215 translatableText = NUIApplication.MultilingualResourceManager?.GetString(textLabelSid, new CultureInfo(SystemSettings.LocaleLanguage.Replace("_", "-")));
216 if (translatableText != null)
218 Text = translatableText;
219 if (hasSystemLanguageChanged == false)
221 systemLocaleLanguageChanged.Add(SystemSettingsLocaleLanguageChanged);
222 hasSystemLanguageChanged = true;
229 NotifyPropertyChanged();
234 /// The Text property.<br />
235 /// The text to display in the UTF-8 format.<br />
237 /// <since_tizen> 3 </since_tizen>
242 return (string)GetValue(TextProperty);
246 SetValue(TextProperty, value);
247 NotifyPropertyChanged();
252 /// The FontFamily property.<br />
253 /// The requested font family to use.<br />
255 /// <since_tizen> 3 </since_tizen>
256 public string FontFamily
260 return (string)GetValue(FontFamilyProperty);
264 SetValue(FontFamilyProperty, value);
265 NotifyPropertyChanged();
269 private string InternalFontFamily
276 return Object.InternalGetPropertyString(this.SwigCPtr, TextLabel.Property.FontFamily);
280 string newFontFamily;
282 if (string.Equals(fontFamily, value)) return;
285 if (fontFamily == Tizen.NUI.FontFamily.UseSystemSetting)
289 newFontFamily = SystemSettings.FontType;
293 Console.WriteLine("{0} Exception caught.", e);
294 newFontFamily = defaultFontFamily;
296 AddSystemSettingsFontTypeChanged();
300 newFontFamily = fontFamily;
301 RemoveSystemSettingsFontTypeChanged();
304 SetInternalFontFamily(newFontFamily);
308 private void SetInternalFontFamily(string fontFamily)
310 Object.InternalSetPropertyString(this.SwigCPtr, TextLabel.Property.FontFamily, (string)fontFamily);
315 /// The FontStyle property.<br />
316 /// The requested font style to use.<br />
317 /// The fontStyle map contains the following keys :<br />
318 /// <list type="table">
319 /// <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>
320 /// <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>
321 /// <item><term>slant (string)</term><description>The slant key defines whether to use italics. (values: normal, roman, italic, oblique)</description></item>
324 /// <since_tizen> 3 </since_tizen>
325 [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1721: Property names should not match get methods")]
326 public PropertyMap FontStyle
330 return (PropertyMap)GetValue(FontStyleProperty);
334 SetValue(FontStyleProperty, value);
335 NotifyPropertyChanged();
340 /// Set FontStyle to TextLabel. <br />
342 /// <param name="fontStyle">The FontStyle</param>
344 /// SetFontStyle specifies the requested font style through <see cref="Tizen.NUI.Text.FontStyle"/>. <br />
347 /// The following example demonstrates how to use the SetFontStyle method.
349 /// var fontStyle = new Tizen.NUI.Text.FontStyle();
350 /// fontStyle.Width = FontWidthType.Expanded;
351 /// fontStyle.Weight = FontWeightType.Bold;
352 /// fontStyle.Slant = FontSlantType.Italic;
353 /// label.SetFontStyle(fontStyle);
356 [EditorBrowsable(EditorBrowsableState.Never)]
357 public void SetFontStyle(FontStyle fontStyle)
359 using (var fontStyleMap = TextMapHelper.GetFontStyleMap(fontStyle))
361 SetValue(FontStyleProperty, fontStyleMap);
366 /// Get FontStyle from TextLabel. <br />
368 /// <returns>The FontStyle</returns>
370 /// <see cref="Tizen.NUI.Text.FontStyle"/>
372 [EditorBrowsable(EditorBrowsableState.Never)]
373 public FontStyle GetFontStyle()
376 using (var fontStyleMap = (PropertyMap)GetValue(FontStyleProperty))
378 fontStyle = TextMapHelper.GetFontStyleStruct(fontStyleMap);
384 /// The PointSize property.<br />
385 /// The size of font in points.<br />
387 /// <since_tizen> 3 </since_tizen>
388 [Binding.TypeConverter(typeof(PointSizeTypeConverter))]
389 public float PointSize
393 return (float)GetValue(PointSizeProperty);
397 SetValue(PointSizeProperty, value);
398 NotifyPropertyChanged();
403 /// The MultiLine property.<br />
404 /// The single-line or multi-line layout option.<br />
406 /// <since_tizen> 3 </since_tizen>
407 public bool MultiLine
411 return (bool)GetValue(MultiLineProperty);
415 SetValue(MultiLineProperty, value);
416 NotifyPropertyChanged();
421 /// The HorizontalAlignment property.<br />
422 /// The line horizontal alignment.<br />
424 /// <since_tizen> 3 </since_tizen>
425 public HorizontalAlignment HorizontalAlignment
429 return (HorizontalAlignment)GetValue(HorizontalAlignmentProperty);
433 SetValue(HorizontalAlignmentProperty, value);
434 NotifyPropertyChanged();
439 /// The VerticalAlignment property.<br />
440 /// The line vertical alignment.<br />
442 /// <since_tizen> 3 </since_tizen>
443 public VerticalAlignment VerticalAlignment
447 return (VerticalAlignment)GetValue(VerticalAlignmentProperty);
451 SetValue(VerticalAlignmentProperty, value);
452 NotifyPropertyChanged();
457 /// The TextColor property.<br />
458 /// The color of the text.<br />
459 /// Animation framework can be used to change the color of the text when not using mark up.<br />
460 /// Cannot animate the color when text is auto scrolling.<br />
463 /// The property cascade chaining set is possible. For example, this (textLabel.TextColor.X = 0.1f;) is possible.
465 /// <since_tizen> 3 </since_tizen>
466 public Color TextColor
470 Color temp = (Color)GetValue(TextColorProperty);
471 return new Color(OnTextColorChanged, temp.R, temp.G, temp.B, temp.A);
475 SetValue(TextColorProperty, value);
476 NotifyPropertyChanged();
481 /// The ShadowOffset property.<br />
482 /// The drop shadow offset 0 indicates no shadow.<br />
484 /// <since_tizen> 3 </since_tizen>
486 /// Deprecated.(API Level 6) Use Shadow instead.
487 /// The property cascade chaining set is possible. For example, this (textLabel.ShadowOffset.X = 0.1f;) is possible.
489 [Obsolete("Do not use this ShadowOffset(Deprecated). Use Shadow instead.")]
490 public Vector2 ShadowOffset
494 return GetValue(ShadowOffsetProperty) as Vector2;
498 SetValue(ShadowOffsetProperty, value);
502 private Vector2 InternalShadowOffset
506 float x = 0.0f, y = 0.0f;
507 using (var propertyValue = Shadow.Find(TextLabel.Property.SHADOW, "offset"))
508 using (var shadowOffset = new Vector2())
510 if (null != propertyValue)
512 propertyValue.Get(shadowOffset);
517 return new Vector2(OnShadowOffsetChanged, x, y);
521 using (var map = new PropertyMap())
523 map.Add("offset", value);
525 var shadowMap = Shadow;
526 shadowMap.Merge(map);
528 SetValue(ShadowProperty, shadowMap);
529 NotifyPropertyChanged();
535 /// The ShadowColor property.<br />
536 /// The color of a drop shadow.<br />
538 /// <since_tizen> 3 </since_tizen>
540 /// Deprecated.(API Level 6) Use Shadow instead.
541 /// The property cascade chaining set is possible. For example, this (textLabel.ShadowColor.X = 0.1f;) is possible.
543 [Obsolete("Do not use this ShadowColor(Deprecated). Use Shadow instead.")]
544 public Vector4 ShadowColor
548 return GetValue(ShadowColorProperty) as Vector4;
552 SetValue(ShadowColorProperty, value);
556 private Vector4 InternalShadowColor
560 float x = 0.0f, y = 0.0f, z = 0.0f, w = 0.0f;
561 using (var propertyValue = Shadow.Find(TextLabel.Property.SHADOW, "color"))
562 using (var shadowColor = new Vector4())
564 if (null != propertyValue)
566 propertyValue.Get(shadowColor);
573 return new Vector4(OnShadowColorChanged, x, y, z, w);
577 using (var map = new PropertyMap())
579 map.Add("color", value);
580 var shadowMap = Shadow;
581 shadowMap.Merge(map);
582 SetValue(ShadowProperty, shadowMap);
583 NotifyPropertyChanged();
589 /// The UnderlineEnabled property.<br />
590 /// The underline enabled flag.<br />
592 /// <since_tizen> 3 </since_tizen>
594 /// Deprecated.(API Level 6) Use Underline instead.
596 [Obsolete("Do not use this UnderlineEnabled(Deprecated). Use Underline instead.")]
597 public bool UnderlineEnabled
601 return (bool)GetValue(UnderlineEnabledProperty);
605 SetValue(UnderlineEnabledProperty, value);
609 private bool InternalUnderlineEnabled
613 bool underlineEnabled = false;
614 using (var propertyValue = Underline.Find(TextLabel.Property.UNDERLINE, "enable"))
616 if (propertyValue != null)
618 propertyValue.Get(out underlineEnabled);
621 return underlineEnabled;
625 using (var map = new PropertyMap())
627 map.Add("enable", value);
628 var undelineMap = Underline;
629 undelineMap.Merge(map);
630 SetValue(UnderlineProperty, undelineMap);
631 NotifyPropertyChanged();
637 /// The UnderlineColor property.<br />
638 /// Overrides the underline height from font metrics.<br />
640 /// <since_tizen> 3 </since_tizen>
642 /// Deprecated.(API Level 6) Use Underline instead.
643 /// The property cascade chaining set is possible. For example, this (textLabel.UnderlineColor.X = 0.1f;) is possible.
645 [Obsolete("Do not use this UnderlineColor(Deprecated). Use Underline instead.")]
646 public Vector4 UnderlineColor
650 return GetValue(UnderlineColorProperty) as Vector4;
654 SetValue(UnderlineColorProperty, value);
658 private Vector4 InternalUnderlineColor
662 float x = 0.0f, y = 0.0f, z = 0.0f, w = 0.0f;
663 using (var propertyValue = Underline.Find(TextLabel.Property.UNDERLINE, "color"))
664 using (var underlineColor = new Vector4())
666 if (null != propertyValue)
668 propertyValue.Get(underlineColor);
669 x = underlineColor.X;
670 y = underlineColor.Y;
671 z = underlineColor.Z;
672 w = underlineColor.W;
675 return new Vector4(OnUnderlineColorChanged, x, y, z, w);
679 using (var map = new PropertyMap())
681 map.Add("color", value);
682 var undelineMap = Underline;
683 undelineMap.Merge(map);
684 SetValue(UnderlineProperty, undelineMap);
685 NotifyPropertyChanged();
691 /// The UnderlineHeight property.<br />
692 /// Overrides the underline height from font metrics.<br />
694 /// <since_tizen> 3 </since_tizen>
696 /// Deprecated.(API Level 6) Use Underline instead.
698 [Obsolete("Do not use this UnderlineHeight(Deprecated). Use Underline instead.")]
699 public float UnderlineHeight
703 return (float)GetValue(UnderlineHeightProperty);
707 SetValue(UnderlineHeightProperty, value);
711 private float InternalUnderlineHeight
715 float underlineHeight = 0.0f;
716 using (var propertyValue = Underline.Find(TextLabel.Property.UNDERLINE, "height"))
718 if (null != propertyValue)
720 propertyValue.Get(out underlineHeight);
723 return underlineHeight;
727 using (var map = new PropertyMap())
729 map.Add("height", value);
730 var undelineMap = Underline;
731 undelineMap.Merge(map);
732 SetValue(UnderlineProperty, undelineMap);
733 NotifyPropertyChanged();
739 /// The EnableMarkup property.<br />
740 /// Whether the mark-up processing is enabled.<br />
742 /// <since_tizen> 3 </since_tizen>
743 public bool EnableMarkup
747 return (bool)GetValue(EnableMarkupProperty);
751 SetValue(EnableMarkupProperty, value);
752 NotifyPropertyChanged();
757 /// The EnableAutoScroll property.<br />
758 /// Starts or stops auto scrolling.<br />
760 /// <since_tizen> 3 </since_tizen>
761 public bool EnableAutoScroll
765 return (bool)GetValue(EnableAutoScrollProperty);
769 SetValue(EnableAutoScrollProperty, value);
770 NotifyPropertyChanged();
775 /// The AutoScrollSpeed property.<br />
776 /// Sets the speed of scrolling in pixels per second.<br />
778 /// <since_tizen> 3 </since_tizen>
779 public int AutoScrollSpeed
783 return (int)GetValue(AutoScrollSpeedProperty);
787 SetValue(AutoScrollSpeedProperty, value);
788 NotifyPropertyChanged();
793 /// The AutoScrollLoopCount property.<br />
794 /// Number of complete loops when scrolling enabled.<br />
796 /// <since_tizen> 3 </since_tizen>
797 public int AutoScrollLoopCount
801 return (int)GetValue(AutoScrollLoopCountProperty);
805 SetValue(AutoScrollLoopCountProperty, value);
806 NotifyPropertyChanged();
811 /// The AutoScrollGap property.<br />
812 /// Gap before scrolling wraps.<br />
814 /// <since_tizen> 3 </since_tizen>
815 public float AutoScrollGap
819 return (float)GetValue(AutoScrollGapProperty);
823 SetValue(AutoScrollGapProperty, value);
824 NotifyPropertyChanged();
829 /// The LineSpacing property.<br />
830 /// The default extra space between lines in points.<br />
832 /// <since_tizen> 3 </since_tizen>
833 public float LineSpacing
837 return (float)GetValue(LineSpacingProperty);
841 SetValue(LineSpacingProperty, value);
842 NotifyPropertyChanged();
847 /// The relative height of the line (a factor that will be multiplied by text height). <br />
848 /// If the value is less than 1, the lines could to be overlapped.
850 [EditorBrowsable(EditorBrowsableState.Never)]
851 public float RelativeLineHeight
855 return (float)GetValue(RelativeLineHeightProperty);
859 SetValue(RelativeLineHeightProperty, value);
860 NotifyPropertyChanged();
865 /// The Underline property.<br />
866 /// The default underline parameters.<br />
867 /// The underline map contains the following keys :<br />
868 /// <list type="table">
869 /// <item><term>enable (bool)</term><description>Whether the underline is enabled (the default value is false)</description></item>
870 /// <item><term>color (Color)</term><description>The color of the underline (If not provided then the color of the text is used)</description></item>
871 /// <item><term>height (float)</term><description>The height in pixels of the underline (the default value is 1.f)</description></item>
874 /// <since_tizen> 3 </since_tizen>
875 [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1721: Property names should not match get methods")]
876 public PropertyMap Underline
880 return (PropertyMap)GetValue(UnderlineProperty);
884 SetValue(UnderlineProperty, value);
885 NotifyPropertyChanged();
890 /// Set Underline to TextLabel. <br />
892 /// <param name="underline">The Underline</param>
894 /// SetUnderline specifies the underline of the text through <see cref="Tizen.NUI.Text.Underline"/>. <br />
897 /// The following example demonstrates how to use the SetUnderline method.
899 /// var underline = new Tizen.NUI.Text.Underline();
900 /// underline.Enable = true;
901 /// underline.Color = new Color("#3498DB");
902 /// underline.Height = 2.0f;
903 /// label.SetUnderline(underline);
906 [EditorBrowsable(EditorBrowsableState.Never)]
907 public void SetUnderline(Underline underline)
909 using (var underlineMap = TextMapHelper.GetUnderlineMap(underline))
911 SetValue(UnderlineProperty, underlineMap);
916 /// Get Underline from TextLabel. <br />
918 /// <returns>The Underline</returns>
920 /// <see cref="Tizen.NUI.Text.Underline"/>
922 [EditorBrowsable(EditorBrowsableState.Never)]
923 public Underline GetUnderline()
926 using (var underlineMap = (PropertyMap)GetValue(UnderlineProperty))
928 underline = TextMapHelper.GetUnderlineStruct(underlineMap);
934 /// The Shadow property.<br />
935 /// The default shadow parameters.<br />
936 /// The shadow map contains the following keys :<br />
937 /// <list type="table">
938 /// <item><term>color (Color)</term><description>The color of the shadow (the default color is Color.Black)</description></item>
939 /// <item><term>offset (Vector2)</term><description>The offset in pixels of the shadow (If not provided then the shadow is not enabled)</description></item>
940 /// <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>
943 /// <since_tizen> 3 </since_tizen>
944 [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1721: Property names should not match get methods")]
945 public PropertyMap Shadow
949 return (PropertyMap)GetValue(ShadowProperty);
953 SetValue(ShadowProperty, value);
954 NotifyPropertyChanged();
959 /// Set Shadow to TextLabel. <br />
961 /// <param name="shadow">The Shadow</param>
963 /// SetShadow specifies the shadow of the text through <see cref="Tizen.NUI.Text.Shadow"/>. <br />
966 /// The following example demonstrates how to use the SetShadow method.
968 /// var shadow = new Tizen.NUI.Text.Shadow();
969 /// shadow.Offset = new Vector2(3, 3);
970 /// shadow.Color = new Color("#F1C40F");
971 /// shadow.BlurRadius = 4.0f;
972 /// label.SetShadow(shadow);
975 [EditorBrowsable(EditorBrowsableState.Never)]
976 public void SetShadow(Tizen.NUI.Text.Shadow shadow)
978 using (var shadowMap = TextMapHelper.GetShadowMap(shadow))
980 SetValue(ShadowProperty, shadowMap);
985 /// Get Shadow from TextLabel. <br />
987 /// <returns>The Shadow</returns>
989 /// <see cref="Tizen.NUI.Text.Shadow"/>
991 [EditorBrowsable(EditorBrowsableState.Never)]
992 public Tizen.NUI.Text.Shadow GetShadow()
994 Tizen.NUI.Text.Shadow shadow;
995 using (var shadowMap = (PropertyMap)GetValue(ShadowProperty))
997 shadow = TextMapHelper.GetShadowStruct(shadowMap);
1003 /// Describes a text shadow for a TextLabel.
1004 /// It is null by default.
1006 [EditorBrowsable(EditorBrowsableState.Never)]
1007 public TextShadow TextShadow
1011 return (TextShadow)GetValue(TextShadowProperty);
1015 SetValue(TextShadowProperty, value);
1016 NotifyPropertyChanged();
1021 /// The Emboss property.<br />
1022 /// The default emboss parameters.<br />
1024 /// <since_tizen> 3 </since_tizen>
1025 public string Emboss
1029 return (string)GetValue(EmbossProperty);
1033 SetValue(EmbossProperty, value);
1034 NotifyPropertyChanged();
1039 /// The Outline property.<br />
1040 /// The default outline parameters.<br />
1041 /// The outline map contains the following keys :<br />
1042 /// <list type="table">
1043 /// <item><term>color (Color)</term><description>The color of the outline (the default color is Color.White)</description></item>
1044 /// <item><term>width (float)</term><description>The width in pixels of the outline (If not provided then the outline is not enabled)</description></item>
1047 /// <since_tizen> 3 </since_tizen>
1048 [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1721: Property names should not match get methods")]
1049 public PropertyMap Outline
1053 return (PropertyMap)GetValue(OutlineProperty);
1057 SetValue(OutlineProperty, value);
1058 NotifyPropertyChanged();
1063 /// Set Outline to TextLabel. <br />
1065 /// <param name="outline">The Outline</param>
1067 /// SetOutline specifies the outline of the text through <see cref="Tizen.NUI.Text.Outline"/>. <br />
1070 /// The following example demonstrates how to use the SetOutline method.
1072 /// var outline = new Tizen.NUI.Text.Outline();
1073 /// outline.Width = 2.0f;
1074 /// outline.Color = new Color("#45B39D");
1075 /// label.SetOutline(outline);
1078 [EditorBrowsable(EditorBrowsableState.Never)]
1079 public void SetOutline(Outline outline)
1081 using (var outlineMap = TextMapHelper.GetOutlineMap(outline))
1083 SetValue(OutlineProperty, outlineMap);
1088 /// Get Outline from TextLabel. <br />
1090 /// <returns>The Outline</returns>
1092 /// <see cref="Tizen.NUI.Text.Outline"/>
1094 [EditorBrowsable(EditorBrowsableState.Never)]
1095 public Outline GetOutline()
1098 using (var outlineMap = (PropertyMap)GetValue(OutlineProperty))
1100 outline = TextMapHelper.GetOutlineStruct(outlineMap);
1106 /// Set Strikethrough to TextLabel. <br />
1108 /// <param name="strikethrough">The Strikethrough</param>
1110 /// SetStrikethrough specifies the strikethrough of the text through <see cref="Tizen.NUI.Text.Strikethrough"/>. <br />
1113 /// The following example demonstrates how to use the SetStrikethrough method.
1115 /// var strikethrough = new Tizen.NUI.Text.Strikethrough();
1116 /// strikethrough.Enable = true;
1117 /// strikethrough.Color = new Color("#3498DB");
1118 /// strikethrough.Height = 2.0f;
1119 /// label.SetStrikethrough(strikethrough);
1122 [EditorBrowsable(EditorBrowsableState.Never)]
1123 public void SetStrikethrough(Strikethrough strikethrough)
1125 using (var map = TextMapHelper.GetStrikethroughMap(strikethrough))
1126 using (var propertyValue = new PropertyValue(map))
1128 SetProperty(TextLabel.Property.Strikethrough, propertyValue);
1133 /// Get Strikethrough from TextLabel. <br />
1135 /// <returns>The Strikethrough</returns>
1137 /// <see cref="Tizen.NUI.Text.Strikethrough"/>
1139 [EditorBrowsable(EditorBrowsableState.Never)]
1140 public Strikethrough GetStrikethrough()
1142 Strikethrough strikethrough;
1143 using (var propertyValue = GetProperty(TextLabel.Property.Strikethrough))
1144 using (var map = new PropertyMap())
1146 propertyValue.Get(map);
1147 strikethrough = TextMapHelper.GetStrikethroughStruct(map);
1149 return strikethrough;
1153 /// The PixelSize property.<br />
1154 /// The size of font in pixels.<br />
1156 /// <since_tizen> 3 </since_tizen>
1157 [Binding.TypeConverter(typeof(FloatGraphicsTypeConverter))]
1158 public float PixelSize
1162 return (float)GetValue(PixelSizeProperty);
1166 SetValue(PixelSizeProperty, value);
1167 NotifyPropertyChanged();
1172 /// The Ellipsis property.<br />
1173 /// Enable or disable the ellipsis.<br />
1175 /// <since_tizen> 3 </since_tizen>
1176 public bool Ellipsis
1180 return (bool)GetValue(EllipsisProperty);
1184 SetValue(EllipsisProperty, value);
1185 NotifyPropertyChanged();
1190 /// The ellipsis position of the text.
1191 /// Specifies which portion of the text should be replaced with an ellipsis when the text size exceeds the layout size.<br />
1193 /// <since_tizen> 9 </since_tizen>
1194 public EllipsisPosition EllipsisPosition
1198 return (EllipsisPosition)GetValue(EllipsisPositionProperty);
1202 SetValue(EllipsisPositionProperty, value);
1203 NotifyPropertyChanged();
1208 /// The AutoScrollLoopDelay property.<br />
1209 /// The amount of time to delay the starting time of auto scrolling and further loops.<br />
1211 /// <since_tizen> 3 </since_tizen>
1212 public float AutoScrollLoopDelay
1216 return (float)GetValue(AutoScrollLoopDelayProperty);
1220 SetValue(AutoScrollLoopDelayProperty, value);
1221 NotifyPropertyChanged();
1226 /// The AutoScrollStopMode property.<br />
1227 /// The auto scrolling stop behaviour.<br />
1228 /// The default value is AutoScrollStopMode.FinishLoop. <br />
1230 /// <since_tizen> 3 </since_tizen>
1231 public AutoScrollStopMode AutoScrollStopMode
1235 return (AutoScrollStopMode)GetValue(AutoScrollStopModeProperty);
1239 SetValue(AutoScrollStopModeProperty, value);
1240 NotifyPropertyChanged();
1245 /// The line count of the text.
1247 /// <since_tizen> 3 </since_tizen>
1248 public int LineCount
1253 using (var propertyValue = GetProperty(TextLabel.Property.LineCount))
1255 propertyValue.Get(out lineCount);
1262 /// The LineWrapMode property.<br />
1263 /// line wrap mode when the text lines over layout width.<br />
1265 /// <since_tizen> 4 </since_tizen>
1266 public LineWrapMode LineWrapMode
1270 return (LineWrapMode)GetValue(LineWrapModeProperty);
1274 SetValue(LineWrapModeProperty, value);
1275 NotifyPropertyChanged();
1280 /// The direction of the text such as left to right or right to left.
1282 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
1283 [EditorBrowsable(EditorBrowsableState.Never)]
1284 public TextDirection TextDirection
1288 int textDirection = 0;
1289 using (var propertyValue = GetProperty(TextLabel.Property.TextDirection))
1291 propertyValue.Get(out textDirection);
1293 return (TextDirection)textDirection;
1298 /// The vertical line alignment of the text.
1300 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
1301 [EditorBrowsable(EditorBrowsableState.Never)]
1302 public VerticalLineAlignment VerticalLineAlignment
1306 return (VerticalLineAlignment)GetValue(VerticalLineAlignmentProperty);
1310 SetValue(VerticalLineAlignmentProperty, value);
1311 NotifyPropertyChanged();
1316 /// The text alignment to match the direction of the system language.
1318 /// <since_tizen> 6 </since_tizen>
1319 public bool MatchSystemLanguageDirection
1323 return (bool)GetValue(MatchSystemLanguageDirectionProperty);
1327 SetValue(MatchSystemLanguageDirectionProperty, value);
1328 NotifyPropertyChanged();
1333 /// The text fit parameters.<br />
1334 /// The textFit map contains the following keys :<br />
1335 /// <list type="table">
1336 /// <item><term>enable (bool)</term><description>True to enable the text fit or false to disable (the default value is false)</description></item>
1337 /// <item><term>minSize (float)</term><description>Minimum Size for text fit (the default value is 10.f)</description></item>
1338 /// <item><term>maxSize (float)</term><description>Maximum Size for text fit (the default value is 100.f)</description></item>
1339 /// <item><term>stepSize (float)</term><description>Step Size for font increase (the default value is 1.f)</description></item>
1340 /// <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>
1343 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
1344 [EditorBrowsable(EditorBrowsableState.Never)]
1345 [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1721: Property names should not match get methods")]
1346 public PropertyMap TextFit
1350 return (PropertyMap)GetValue(TextFitProperty);
1354 SetValue(TextFitProperty, value);
1355 NotifyPropertyChanged();
1360 /// Set TextFit to TextLabel. <br />
1362 /// <param name="textFit">The TextFit</param>
1364 /// SetTextFit specifies the textFit of the text through <see cref="Tizen.NUI.Text.TextFit"/>. <br />
1367 /// The following example demonstrates how to use the SetTextFit method.
1369 /// var textFit = new Tizen.NUI.Text.TextFit();
1370 /// textFit.Enable = true;
1371 /// textFit.MinSize = 10.0f;
1372 /// textFit.MaxSize = 100.0f;
1373 /// textFit.StepSize = 5.0f;
1374 /// textFit.FontSizeType = FontSizeType.PointSize;
1375 /// label.SetTextFit(textFit);
1378 [EditorBrowsable(EditorBrowsableState.Never)]
1379 public void SetTextFit(TextFit textFit)
1381 using (var textFitMap = TextMapHelper.GetTextFitMap(textFit))
1383 SetValue(TextFitProperty, textFitMap);
1388 /// Get TextFit from TextLabel. <br />
1390 /// <returns>The TextFit</returns>
1392 /// TextFit is always returned based on PointSize. <br />
1393 /// If the user sets FontSizeType to PixelSize, then MinSize, MaxSize, and StepSize are converted based on PointSize and returned. <br />
1394 /// <see cref="Tizen.NUI.Text.TextFit"/>
1396 [EditorBrowsable(EditorBrowsableState.Never)]
1397 public TextFit GetTextFit()
1400 using (var textFitMap = (PropertyMap)GetValue(TextFitProperty))
1402 textFit = TextMapHelper.GetTextFitStruct(textFitMap);
1408 /// The MinLineSize property.<br />
1409 /// The height of the line in points. <br />
1410 /// If the font size is larger than the line size, it works with the font size. <br />
1412 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
1413 [EditorBrowsable(EditorBrowsableState.Never)]
1414 public float MinLineSize
1418 return (float)GetValue(MinLineSizeProperty);
1422 SetValue(MinLineSizeProperty, value);
1423 NotifyPropertyChanged();
1428 /// The spaces between characters in Pixels.
1430 /// A positive value will make the characters far apart (expanded) and a negative value will bring them closer (condensed).<br />
1431 /// The default value is 0.f which does nothing.
1434 [EditorBrowsable(EditorBrowsableState.Never)]
1435 public float CharacterSpacing
1439 return (float)GetValue(CharacterSpacingProperty);
1443 SetValue(CharacterSpacingProperty, value);
1444 NotifyPropertyChanged();
1449 /// The FontSizeScale property for scaling the specified font size up or down. <br />
1450 /// The default value is 1.0. <br />
1451 /// The given font size scale value is used for multiplying the specified font size before querying fonts. <br />
1452 /// If FontSizeScale.UseSystemSetting, will use the SystemSettings.FontSize internally. <br />
1454 /// <since_tizen> 9 </since_tizen>
1455 public float FontSizeScale
1459 return (float)GetValue(FontSizeScaleProperty);
1463 SetValue(FontSizeScaleProperty, value);
1464 NotifyPropertyChanged();
1468 private float InternalFontSizeScale
1472 return fontSizeScale;
1476 float newFontSizeScale;
1478 if (fontSizeScale == value) return;
1480 fontSizeScale = value;
1481 if (fontSizeScale == Tizen.NUI.FontSizeScale.UseSystemSetting)
1483 SystemSettingsFontSize systemSettingsFontSize;
1487 systemSettingsFontSize = SystemSettings.FontSize;
1491 Console.WriteLine("{0} Exception caught.", e);
1492 systemSettingsFontSize = SystemSettingsFontSize.Normal;
1494 newFontSizeScale = TextUtils.GetFontSizeScale(systemSettingsFontSize);
1495 AddSystemSettingsFontSizeChanged();
1499 newFontSizeScale = fontSizeScale;
1500 RemoveSystemSettingsFontSizeChanged();
1503 SetInternalFontSizeScale(newFontSizeScale);
1507 private void SetInternalFontSizeScale(float fontSizeScale)
1510 Object.InternalSetPropertyFloat(this.SwigCPtr, TextLabel.Property.FontSizeScale, (float)fontSizeScale);
1515 /// The EnableFontSizeScale property.<br />
1516 /// Whether the font size scale is enabled. (The default value is true)
1518 [EditorBrowsable(EditorBrowsableState.Never)]
1519 public bool EnableFontSizeScale
1523 return (bool)GetValue(EnableFontSizeScaleProperty);
1527 SetValue(EnableFontSizeScaleProperty, value);
1528 NotifyPropertyChanged();
1532 private TextLabelSelectorData EnsureSelectorData() => selectorData ?? (selectorData = new TextLabelSelectorData());
1535 /// Downcasts a handle to textLabel handle
1537 /// <param name="handle"></param>
1538 /// <returns></returns>
1539 /// <exception cref="ArgumentNullException"> Thrown when handle is null. </exception>
1540 /// <since_tizen> 3 </since_tizen>
1541 /// Do not use this, that will be deprecated. Use as keyword instead.
1542 [Obsolete("Do not use this, that will be deprecated. Use as keyword instead. " +
1544 "BaseHandle handle = new TextLabel(\"Hello World!\"); " +
1545 "TextLabel label = handle as TextLabel")]
1546 [EditorBrowsable(EditorBrowsableState.Never)]
1547 public static TextLabel DownCast(BaseHandle handle)
1551 throw new ArgumentNullException(nameof(handle));
1553 TextLabel ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as TextLabel;
1554 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1559 [EditorBrowsable(EditorBrowsableState.Never)]
1560 protected override void Dispose(DisposeTypes type)
1567 internalTextColor?.Dispose();
1569 if (hasSystemLanguageChanged)
1571 systemLocaleLanguageChanged.Remove(SystemSettingsLocaleLanguageChanged);
1574 RemoveSystemSettingsFontTypeChanged();
1575 RemoveSystemSettingsFontSizeChanged();
1577 if (type == DisposeTypes.Explicit)
1580 //Release your own managed resources here.
1581 //You should release all of your own disposable objects here.
1582 selectorData?.Reset(this);
1587 if (textLabelTextFitChangedCallbackDelegate != null)
1589 TextFitChangedSignal().Disconnect(textLabelTextFitChangedCallbackDelegate);
1596 /// This will not be public opened.
1597 [EditorBrowsable(EditorBrowsableState.Never)]
1598 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
1600 Interop.TextLabel.DeleteTextLabel(swigCPtr);
1604 /// Get attribues, it is abstract function and must be override.
1606 [EditorBrowsable(EditorBrowsableState.Never)]
1607 protected override ViewStyle CreateViewStyle()
1609 return new TextLabelStyle();
1612 internal override LayoutItem CreateDefaultLayout()
1614 return new TextLayout();
1618 /// Invoked whenever the binding context of the textlabel changes. Implement this method to add class handling for this event.
1620 protected override void OnBindingContextChanged()
1622 base.OnBindingContextChanged();
1625 private void SystemSettingsLocaleLanguageChanged(object sender, LocaleLanguageChangedEventArgs e)
1627 Text = NUIApplication.MultilingualResourceManager?.GetString(textLabelSid, new CultureInfo(e.Value.Replace("_", "-")));
1630 private void SystemSettingsFontSizeChanged(object sender, FontSizeChangedEventArgs e)
1632 float newFontSizeScale = TextUtils.GetFontSizeScale(e.Value);
1633 SetInternalFontSizeScale(newFontSizeScale);
1636 private void AddSystemSettingsFontSizeChanged()
1638 if (hasSystemFontSizeChanged != true)
1642 SystemFontSizeChangedManager.Add(SystemSettingsFontSizeChanged);
1643 hasSystemFontSizeChanged = true;
1647 Console.WriteLine("{0} Exception caught.", e);
1648 hasSystemFontSizeChanged = false;
1653 private void RemoveSystemSettingsFontSizeChanged()
1655 if (hasSystemFontSizeChanged == true)
1659 SystemFontSizeChangedManager.Remove(SystemSettingsFontSizeChanged);
1660 hasSystemFontSizeChanged = false;
1664 Console.WriteLine("{0} Exception caught.", e);
1665 hasSystemFontSizeChanged = true;
1670 private void SystemSettingsFontTypeChanged(object sender, FontTypeChangedEventArgs e)
1672 SetInternalFontFamily(e.Value);
1675 private void AddSystemSettingsFontTypeChanged()
1677 if (HasStyle() && !hasSystemFontTypeChanged)
1681 systemFontTypeChanged.Add(SystemSettingsFontTypeChanged);
1682 hasSystemFontTypeChanged = true;
1686 Console.WriteLine("{0} Exception caught.", e);
1687 hasSystemFontTypeChanged = false;
1692 private void RemoveSystemSettingsFontTypeChanged()
1694 if (hasSystemFontTypeChanged)
1698 systemFontTypeChanged.Remove(SystemSettingsFontTypeChanged);
1699 hasSystemFontTypeChanged = false;
1703 Console.WriteLine("{0} Exception caught.", e);
1704 hasSystemFontTypeChanged = true;
1709 private void RequestLayout()
1711 Layout?.RequestLayout();
1714 internal new class Property
1716 internal static readonly int TEXT = Interop.TextLabel.TextGet();
1717 internal static readonly int FontFamily = Interop.TextLabel.FontFamilyGet();
1718 internal static readonly int FontStyle = Interop.TextLabel.FontStyleGet();
1719 internal static readonly int PointSize = Interop.TextLabel.PointSizeGet();
1720 internal static readonly int MultiLine = Interop.TextLabel.MultiLineGet();
1721 internal static readonly int HorizontalAlignment = Interop.TextLabel.HorizontalAlignmentGet();
1722 internal static readonly int VerticalAlignment = Interop.TextLabel.VerticalAlignmentGet();
1723 internal static readonly int TextColor = Interop.TextLabel.TextColorGet();
1724 internal static readonly int EnableMarkup = Interop.TextLabel.EnableMarkupGet();
1725 internal static readonly int EnableAutoScroll = Interop.TextLabel.EnableAutoScrollGet();
1726 internal static readonly int AutoScrollSpeed = Interop.TextLabel.AutoScrollSpeedGet();
1727 internal static readonly int AutoScrollLoopCount = Interop.TextLabel.AutoScrollLoopCountGet();
1728 internal static readonly int AutoScrollGap = Interop.TextLabel.AutoScrollGapGet();
1729 internal static readonly int LineSpacing = Interop.TextLabel.LineSpacingGet();
1730 internal static readonly int RelativeLineHeight = Interop.TextLabel.RelativeLineHeightGet();
1731 internal static readonly int UNDERLINE = Interop.TextLabel.UnderlineGet();
1732 internal static readonly int SHADOW = Interop.TextLabel.ShadowGet();
1733 internal static readonly int EMBOSS = Interop.TextLabel.EmbossGet();
1734 internal static readonly int OUTLINE = Interop.TextLabel.OutlineGet();
1735 internal static readonly int PixelSize = Interop.TextLabel.PixelSizeGet();
1736 internal static readonly int ELLIPSIS = Interop.TextLabel.EllipsisGet();
1737 internal static readonly int AutoScrollStopMode = Interop.TextLabel.AutoScrollStopModeGet();
1738 internal static readonly int AutoScrollLoopDelay = Interop.TextLabel.AutoScrollLoopDelayGet();
1739 internal static readonly int LineCount = Interop.TextLabel.LineCountGet();
1740 internal static readonly int LineWrapMode = Interop.TextLabel.LineWrapModeGet();
1741 internal static readonly int TextDirection = Interop.TextLabel.TextDirectionGet();
1742 internal static readonly int VerticalLineAlignment = Interop.TextLabel.VerticalLineAlignmentGet();
1743 internal static readonly int MatchSystemLanguageDirection = Interop.TextLabel.MatchSystemLanguageDirectionGet();
1744 internal static readonly int TextFit = Interop.TextLabel.TextFitGet();
1745 internal static readonly int MinLineSize = Interop.TextLabel.MinLineSizeGet();
1746 internal static readonly int FontSizeScale = Interop.TextLabel.FontSizeScaleGet();
1747 internal static readonly int EnableFontSizeScale = Interop.TextLabel.EnableFontSizeScaleGet();
1748 internal static readonly int EllipsisPosition = Interop.TextLabel.EllipsisPositionGet();
1749 internal static readonly int Strikethrough = Interop.TextLabel.StrikethroughGet();
1750 internal static readonly int CharacterSpacing = Interop.TextLabel.CharacterSpacingGet();
1753 private void OnShadowColorChanged(float x, float y, float z, float w)
1755 ShadowColor = new Vector4(x, y, z, w);
1757 private void OnShadowOffsetChanged(float x, float y)
1759 ShadowOffset = new Vector2(x, y);
1761 private void OnTextColorChanged(float r, float g, float b, float a)
1763 TextColor = new Color(r, g, b, a);
1765 private void OnUnderlineColorChanged(float x, float y, float z, float w)
1767 UnderlineColor = new Vector4(x, y, z, w);