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 totalWidth = Math.Min(Math.Max(naturalSize.Width, minSize.Width), (maxSize.Width < 0 ? Int32.MaxValue : maxSize.Width));
62 widthMeasureSpec = new MeasureSpecification(new LayoutLength(totalWidth), MeasureSpecification.ModeType.Exactly);
66 totalWidth = Math.Min(Math.Max(naturalSize.Width, minSize.Width), (maxSize.Width < 0 ? Int32.MaxValue : maxSize.Width));
67 totalHeight = Math.Min(Math.Max(naturalSize.Height, minSize.Height), (maxSize.Height < 0 ? Int32.MaxValue : maxSize.Height));
69 heightMeasureSpec = new MeasureSpecification(new LayoutLength(totalHeight), MeasureSpecification.ModeType.Exactly);
70 widthMeasureSpec = new MeasureSpecification(new LayoutLength(totalWidth), MeasureSpecification.ModeType.Exactly);
74 MeasuredSize.StateType childWidthState = MeasuredSize.StateType.MeasuredSizeOK;
75 MeasuredSize.StateType childHeightState = MeasuredSize.StateType.MeasuredSizeOK;
77 SetMeasuredDimensions(ResolveSizeAndState(new LayoutLength(totalWidth), widthMeasureSpec, childWidthState),
78 ResolveSizeAndState(new LayoutLength(totalHeight), heightMeasureSpec, childHeightState));
82 static TextLabel() { }
84 static private string defaultFontFamily = "TizenSans";
85 private string fontFamily = defaultFontFamily;
86 private bool hasSystemFontTypeChanged = false;
87 private string textLabelSid = null;
88 private bool systemlangTextFlag = false;
89 private TextLabelSelectorData selectorData;
90 private float fontSizeScale = 1.0f;
91 private bool hasFontSizeChangedCallback = false;
92 static private string defaultStyleName = "Tizen.NUI.BaseComponents.TextLabel";
94 private Color internalTextColor;
97 /// Creates the TextLabel control.
99 /// <since_tizen> 3 </since_tizen>
100 public TextLabel() : this(Interop.TextLabel.New(ThemeManager.GetStyle(defaultStyleName) == null ? false : true), true)
102 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
105 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
106 [EditorBrowsable(EditorBrowsableState.Never)]
107 public TextLabel(TextLabelStyle viewStyle) : this(Interop.TextLabel.New(ThemeManager.GetStyle(defaultStyleName) == null ? false : true), true, viewStyle)
112 /// Creates the TextLabel with setting the status of shown or hidden.
114 /// <param name="shown">false : Not displayed (hidden), true : displayed (shown)</param>
115 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
116 [EditorBrowsable(EditorBrowsableState.Never)]
117 public TextLabel(bool shown) : this(Interop.TextLabel.New(ThemeManager.GetStyle(defaultStyleName) == null ? false : true), true)
119 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
124 /// Creates the TextLabel control.
126 /// <param name="text">The text to display</param>
127 /// <since_tizen> 3 </since_tizen>
128 public TextLabel(string text) : this(Interop.TextLabel.New(text, ThemeManager.GetStyle(defaultStyleName) == null ? false : true), true)
130 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
134 /// Creates the TextLabel with setting the status of shown or hidden.
136 /// <param name="text">The text to display</param>
137 /// <param name="shown">false : Not displayed (hidden), true : displayed (shown)</param>
138 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
139 [EditorBrowsable(EditorBrowsableState.Never)]
140 public TextLabel(string text, bool shown) : this(Interop.TextLabel.New(text, ThemeManager.GetStyle(defaultStyleName) == null ? false : true), true)
142 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
146 internal TextLabel(TextLabel handle, bool shown = true) : this(Interop.TextLabel.NewTextLabel(TextLabel.getCPtr(handle)), true)
148 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
156 internal TextLabel(global::System.IntPtr cPtr, bool cMemoryOwn, ViewStyle viewStyle, bool shown = true) : base(cPtr, cMemoryOwn, viewStyle)
164 internal TextLabel(global::System.IntPtr cPtr, bool cMemoryOwn, bool shown = true) : base(cPtr, cMemoryOwn, null)
172 private bool HasStyle()
174 return ThemeManager.GetStyle(this.GetType()) == null ? false : true;
178 /// The TranslatableText property.<br />
179 /// The text can set the SID value.<br />
181 /// <exception cref='ArgumentNullException'>
182 /// ResourceManager about multilingual is null.
184 /// <since_tizen> 4 </since_tizen>
185 public string TranslatableText
189 return (string)GetValue(TranslatableTextProperty);
193 SetValue(TranslatableTextProperty, value);
196 private string translatableText
204 if (NUIApplication.MultilingualResourceManager == null)
206 throw new ArgumentNullException(null, "ResourceManager about multilingual is null");
208 string translatableText = null;
209 textLabelSid = value;
210 translatableText = NUIApplication.MultilingualResourceManager?.GetString(textLabelSid, new CultureInfo(SystemSettings.LocaleLanguage.Replace("_", "-")));
211 if (translatableText != null)
213 Text = translatableText;
214 if (systemlangTextFlag == false)
216 SystemSettings.LocaleLanguageChanged += SystemSettings_LocaleLanguageChanged;
217 systemlangTextFlag = true;
224 NotifyPropertyChanged();
229 /// The Text property.<br />
230 /// The text to display in the UTF-8 format.<br />
232 /// <since_tizen> 3 </since_tizen>
237 return (string)GetValue(TextProperty);
241 SetValue(TextProperty, value);
242 NotifyPropertyChanged();
247 /// The FontFamily property.<br />
248 /// The requested font family to use.<br />
250 /// <since_tizen> 3 </since_tizen>
251 public string FontFamily
255 return (string)GetValue(FontFamilyProperty);
259 SetValue(FontFamilyProperty, value);
260 NotifyPropertyChanged();
264 private string InternalFontFamily
271 return Object.InternalGetPropertyString(this.SwigCPtr, TextLabel.Property.FontFamily);
275 string newFontFamily;
277 if (string.Equals(fontFamily, value)) return;
280 if (fontFamily == Tizen.NUI.FontFamily.UseSystemSetting)
284 newFontFamily = SystemSettings.FontType;
288 Console.WriteLine("{0} Exception caught.", e);
289 newFontFamily = defaultFontFamily;
291 AddSystemSettingsFontTypeChanged();
295 newFontFamily = fontFamily;
296 RemoveSystemSettingsFontTypeChanged();
299 SetInternalFontFamily(newFontFamily);
303 private void SetInternalFontFamily(string fontFamily)
305 Object.InternalSetPropertyString(this.SwigCPtr, TextLabel.Property.FontFamily, (string)fontFamily);
310 /// The FontStyle property.<br />
311 /// The requested font style to use.<br />
312 /// The fontStyle map contains the following keys :<br />
313 /// <list type="table">
314 /// <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>
315 /// <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>
316 /// <item><term>slant (string)</term><description>The slant key defines whether to use italics. (values: normal, roman, italic, oblique)</description></item>
319 /// <since_tizen> 3 </since_tizen>
320 [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1721: Property names should not match get methods")]
321 public PropertyMap FontStyle
325 return (PropertyMap)GetValue(FontStyleProperty);
329 SetValue(FontStyleProperty, value);
330 NotifyPropertyChanged();
335 /// Set FontStyle to TextLabel. <br />
337 /// <param name="fontStyle">The FontStyle</param>
339 /// SetFontStyle specifies the requested font style through <see cref="Tizen.NUI.Text.FontStyle"/>. <br />
342 /// The following example demonstrates how to use the SetFontStyle method.
344 /// var fontStyle = new Tizen.NUI.Text.FontStyle();
345 /// fontStyle.Width = FontWidthType.Expanded;
346 /// fontStyle.Weight = FontWeightType.Bold;
347 /// fontStyle.Slant = FontSlantType.Italic;
348 /// label.SetFontStyle(fontStyle);
351 [EditorBrowsable(EditorBrowsableState.Never)]
352 public void SetFontStyle(FontStyle fontStyle)
354 using (var fontStyleMap = TextMapHelper.GetFontStyleMap(fontStyle))
356 SetValue(FontStyleProperty, fontStyleMap);
361 /// Get FontStyle from TextLabel. <br />
363 /// <returns>The FontStyle</returns>
365 /// <see cref="Tizen.NUI.Text.FontStyle"/>
367 [EditorBrowsable(EditorBrowsableState.Never)]
368 public FontStyle GetFontStyle()
371 using (var fontStyleMap = (PropertyMap)GetValue(FontStyleProperty))
373 fontStyle = TextMapHelper.GetFontStyleStruct(fontStyleMap);
379 /// The PointSize property.<br />
380 /// The size of font in points.<br />
382 /// <since_tizen> 3 </since_tizen>
383 [Binding.TypeConverter(typeof(PointSizeTypeConverter))]
384 public float PointSize
388 return (float)GetValue(PointSizeProperty);
392 SetValue(PointSizeProperty, value);
393 NotifyPropertyChanged();
398 /// The MultiLine property.<br />
399 /// The single-line or multi-line layout option.<br />
401 /// <since_tizen> 3 </since_tizen>
402 public bool MultiLine
406 return (bool)GetValue(MultiLineProperty);
410 SetValue(MultiLineProperty, value);
411 NotifyPropertyChanged();
416 /// The HorizontalAlignment property.<br />
417 /// The line horizontal alignment.<br />
419 /// <since_tizen> 3 </since_tizen>
420 public HorizontalAlignment HorizontalAlignment
424 return (HorizontalAlignment)GetValue(HorizontalAlignmentProperty);
428 SetValue(HorizontalAlignmentProperty, value);
429 NotifyPropertyChanged();
434 /// The VerticalAlignment property.<br />
435 /// The line vertical alignment.<br />
437 /// <since_tizen> 3 </since_tizen>
438 public VerticalAlignment VerticalAlignment
442 return (VerticalAlignment)GetValue(VerticalAlignmentProperty);
446 SetValue(VerticalAlignmentProperty, value);
447 NotifyPropertyChanged();
452 /// The TextColor property.<br />
453 /// The color of the text.<br />
454 /// Animation framework can be used to change the color of the text when not using mark up.<br />
455 /// Cannot animate the color when text is auto scrolling.<br />
458 /// The property cascade chaining set is possible. For example, this (textLabel.TextColor.X = 0.1f;) is possible.
460 /// <since_tizen> 3 </since_tizen>
461 public Color TextColor
465 Color temp = (Color)GetValue(TextColorProperty);
466 return new Color(OnTextColorChanged, temp.R, temp.G, temp.B, temp.A);
470 SetValue(TextColorProperty, value);
471 NotifyPropertyChanged();
476 /// The ShadowOffset property.<br />
477 /// The drop shadow offset 0 indicates no shadow.<br />
479 /// <since_tizen> 3 </since_tizen>
481 /// Deprecated.(API Level 6) Use Shadow instead.
482 /// The property cascade chaining set is possible. For example, this (textLabel.ShadowOffset.X = 0.1f;) is possible.
484 [Obsolete("Do not use this ShadowOffset(Deprecated). Use Shadow instead.")]
485 public Vector2 ShadowOffset
489 return GetValue(ShadowOffsetProperty) as Vector2;
493 SetValue(ShadowOffsetProperty, value);
497 private Vector2 InternalShadowOffset
501 float x = 0.0f, y = 0.0f;
502 using (var propertyValue = Shadow.Find(TextLabel.Property.SHADOW, "offset"))
503 using (var shadowOffset = new Vector2())
505 if (null != propertyValue)
507 propertyValue.Get(shadowOffset);
512 return new Vector2(OnShadowOffsetChanged, x, y);
516 using (var map = new PropertyMap())
518 map.Add("offset", value);
520 var shadowMap = Shadow;
521 shadowMap.Merge(map);
523 SetValue(ShadowProperty, shadowMap);
524 NotifyPropertyChanged();
530 /// The ShadowColor property.<br />
531 /// The color of a drop shadow.<br />
533 /// <since_tizen> 3 </since_tizen>
535 /// Deprecated.(API Level 6) Use Shadow instead.
536 /// The property cascade chaining set is possible. For example, this (textLabel.ShadowColor.X = 0.1f;) is possible.
538 [Obsolete("Do not use this ShadowColor(Deprecated). Use Shadow instead.")]
539 public Vector4 ShadowColor
543 return GetValue(ShadowColorProperty) as Vector4;
547 SetValue(ShadowColorProperty, value);
551 private Vector4 InternalShadowColor
555 float x = 0.0f, y = 0.0f, z = 0.0f, w = 0.0f;
556 using (var propertyValue = Shadow.Find(TextLabel.Property.SHADOW, "color"))
557 using (var shadowColor = new Vector4())
559 if (null != propertyValue)
561 propertyValue.Get(shadowColor);
568 return new Vector4(OnShadowColorChanged, x, y, z, w);
572 using (var map = new PropertyMap())
574 map.Add("color", value);
575 var shadowMap = Shadow;
576 shadowMap.Merge(map);
577 SetValue(ShadowProperty, shadowMap);
578 NotifyPropertyChanged();
584 /// The UnderlineEnabled property.<br />
585 /// The underline enabled flag.<br />
587 /// <since_tizen> 3 </since_tizen>
589 /// Deprecated.(API Level 6) Use Underline instead.
591 [Obsolete("Do not use this UnderlineEnabled(Deprecated). Use Underline instead.")]
592 public bool UnderlineEnabled
596 return (bool)GetValue(UnderlineEnabledProperty);
600 SetValue(UnderlineEnabledProperty, value);
604 private bool InternalUnderlineEnabled
608 bool underlineEnabled = false;
609 using (var propertyValue = Underline.Find(TextLabel.Property.UNDERLINE, "enable"))
611 if (propertyValue != null)
613 propertyValue.Get(out underlineEnabled);
616 return underlineEnabled;
620 using (var map = new PropertyMap())
622 map.Add("enable", value);
623 var undelineMap = Underline;
624 undelineMap.Merge(map);
625 SetValue(UnderlineProperty, undelineMap);
626 NotifyPropertyChanged();
632 /// The UnderlineColor property.<br />
633 /// Overrides the underline height from font metrics.<br />
635 /// <since_tizen> 3 </since_tizen>
637 /// Deprecated.(API Level 6) Use Underline instead.
638 /// The property cascade chaining set is possible. For example, this (textLabel.UnderlineColor.X = 0.1f;) is possible.
640 [Obsolete("Do not use this UnderlineColor(Deprecated). Use Underline instead.")]
641 public Vector4 UnderlineColor
645 return GetValue(UnderlineColorProperty) as Vector4;
649 SetValue(UnderlineColorProperty, value);
653 private Vector4 InternalUnderlineColor
657 float x = 0.0f, y = 0.0f, z = 0.0f, w = 0.0f;
658 using (var propertyValue = Underline.Find(TextLabel.Property.UNDERLINE, "color"))
659 using (var underlineColor = new Vector4())
661 if (null != propertyValue)
663 propertyValue.Get(underlineColor);
664 x = underlineColor.X;
665 y = underlineColor.Y;
666 z = underlineColor.Z;
667 w = underlineColor.W;
670 return new Vector4(OnUnderlineColorChanged, x, y, z, w);
674 using (var map = new PropertyMap())
676 map.Add("color", value);
677 var undelineMap = Underline;
678 undelineMap.Merge(map);
679 SetValue(UnderlineProperty, undelineMap);
680 NotifyPropertyChanged();
686 /// The UnderlineHeight property.<br />
687 /// Overrides the underline height from font metrics.<br />
689 /// <since_tizen> 3 </since_tizen>
691 /// Deprecated.(API Level 6) Use Underline instead.
693 [Obsolete("Do not use this UnderlineHeight(Deprecated). Use Underline instead.")]
694 public float UnderlineHeight
698 return (float)GetValue(UnderlineHeightProperty);
702 SetValue(UnderlineHeightProperty, value);
706 private float InternalUnderlineHeight
710 float underlineHeight = 0.0f;
711 using (var propertyValue = Underline.Find(TextLabel.Property.UNDERLINE, "height"))
713 if (null != propertyValue)
715 propertyValue.Get(out underlineHeight);
718 return underlineHeight;
722 using (var map = new PropertyMap())
724 map.Add("height", value);
725 var undelineMap = Underline;
726 undelineMap.Merge(map);
727 SetValue(UnderlineProperty, undelineMap);
728 NotifyPropertyChanged();
734 /// The EnableMarkup property.<br />
735 /// Whether the mark-up processing is enabled.<br />
737 /// <since_tizen> 3 </since_tizen>
738 public bool EnableMarkup
742 return (bool)GetValue(EnableMarkupProperty);
746 SetValue(EnableMarkupProperty, value);
747 NotifyPropertyChanged();
752 /// The EnableAutoScroll property.<br />
753 /// Starts or stops auto scrolling.<br />
755 /// <since_tizen> 3 </since_tizen>
756 public bool EnableAutoScroll
760 return (bool)GetValue(EnableAutoScrollProperty);
764 SetValue(EnableAutoScrollProperty, value);
765 NotifyPropertyChanged();
770 /// The AutoScrollSpeed property.<br />
771 /// Sets the speed of scrolling in pixels per second.<br />
773 /// <since_tizen> 3 </since_tizen>
774 public int AutoScrollSpeed
778 return (int)GetValue(AutoScrollSpeedProperty);
782 SetValue(AutoScrollSpeedProperty, value);
783 NotifyPropertyChanged();
788 /// The AutoScrollLoopCount property.<br />
789 /// Number of complete loops when scrolling enabled.<br />
791 /// <since_tizen> 3 </since_tizen>
792 public int AutoScrollLoopCount
796 return (int)GetValue(AutoScrollLoopCountProperty);
800 SetValue(AutoScrollLoopCountProperty, value);
801 NotifyPropertyChanged();
806 /// The AutoScrollGap property.<br />
807 /// Gap before scrolling wraps.<br />
809 /// <since_tizen> 3 </since_tizen>
810 public float AutoScrollGap
814 return (float)GetValue(AutoScrollGapProperty);
818 SetValue(AutoScrollGapProperty, value);
819 NotifyPropertyChanged();
824 /// The LineSpacing property.<br />
825 /// The default extra space between lines in points.<br />
827 /// <since_tizen> 3 </since_tizen>
828 public float LineSpacing
832 return (float)GetValue(LineSpacingProperty);
836 SetValue(LineSpacingProperty, value);
837 NotifyPropertyChanged();
842 /// The relative height of the line (a factor that will be multiplied by text height). <br />
843 /// If the value is less than 1, the lines could to be overlapped.
845 [EditorBrowsable(EditorBrowsableState.Never)]
846 public float RelativeLineHeight
850 return (float)GetValue(RelativeLineHeightProperty);
854 SetValue(RelativeLineHeightProperty, value);
855 NotifyPropertyChanged();
860 /// The Underline property.<br />
861 /// The default underline parameters.<br />
862 /// The underline map contains the following keys :<br />
863 /// <list type="table">
864 /// <item><term>enable (bool)</term><description>Whether the underline is enabled (the default value is false)</description></item>
865 /// <item><term>color (Color)</term><description>The color of the underline (If not provided then the color of the text is used)</description></item>
866 /// <item><term>height (float)</term><description>The height in pixels of the underline (the default value is 1.f)</description></item>
869 /// <since_tizen> 3 </since_tizen>
870 [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1721: Property names should not match get methods")]
871 public PropertyMap Underline
875 return (PropertyMap)GetValue(UnderlineProperty);
879 SetValue(UnderlineProperty, value);
880 NotifyPropertyChanged();
885 /// Set Underline to TextLabel. <br />
887 /// <param name="underline">The Underline</param>
889 /// SetUnderline specifies the underline of the text through <see cref="Tizen.NUI.Text.Underline"/>. <br />
892 /// The following example demonstrates how to use the SetUnderline method.
894 /// var underline = new Tizen.NUI.Text.Underline();
895 /// underline.Enable = true;
896 /// underline.Color = new Color("#3498DB");
897 /// underline.Height = 2.0f;
898 /// label.SetUnderline(underline);
901 [EditorBrowsable(EditorBrowsableState.Never)]
902 public void SetUnderline(Underline underline)
904 using (var underlineMap = TextMapHelper.GetUnderlineMap(underline))
906 SetValue(UnderlineProperty, underlineMap);
911 /// Get Underline from TextLabel. <br />
913 /// <returns>The Underline</returns>
915 /// <see cref="Tizen.NUI.Text.Underline"/>
917 [EditorBrowsable(EditorBrowsableState.Never)]
918 public Underline GetUnderline()
921 using (var underlineMap = (PropertyMap)GetValue(UnderlineProperty))
923 underline = TextMapHelper.GetUnderlineStruct(underlineMap);
929 /// The Shadow property.<br />
930 /// The default shadow parameters.<br />
931 /// The shadow map contains the following keys :<br />
932 /// <list type="table">
933 /// <item><term>color (Color)</term><description>The color of the shadow (the default color is Color.Black)</description></item>
934 /// <item><term>offset (Vector2)</term><description>The offset in pixels of the shadow (If not provided then the shadow is not enabled)</description></item>
935 /// <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>
938 /// <since_tizen> 3 </since_tizen>
939 [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1721: Property names should not match get methods")]
940 public PropertyMap Shadow
944 return (PropertyMap)GetValue(ShadowProperty);
948 SetValue(ShadowProperty, value);
949 NotifyPropertyChanged();
954 /// Set Shadow to TextLabel. <br />
956 /// <param name="shadow">The Shadow</param>
958 /// SetShadow specifies the shadow of the text through <see cref="Tizen.NUI.Text.Shadow"/>. <br />
961 /// The following example demonstrates how to use the SetShadow method.
963 /// var shadow = new Tizen.NUI.Text.Shadow();
964 /// shadow.Offset = new Vector2(3, 3);
965 /// shadow.Color = new Color("#F1C40F");
966 /// shadow.BlurRadius = 4.0f;
967 /// label.SetShadow(shadow);
970 [EditorBrowsable(EditorBrowsableState.Never)]
971 public void SetShadow(Tizen.NUI.Text.Shadow shadow)
973 using (var shadowMap = TextMapHelper.GetShadowMap(shadow))
975 SetValue(ShadowProperty, shadowMap);
980 /// Get Shadow from TextLabel. <br />
982 /// <returns>The Shadow</returns>
984 /// <see cref="Tizen.NUI.Text.Shadow"/>
986 [EditorBrowsable(EditorBrowsableState.Never)]
987 public Tizen.NUI.Text.Shadow GetShadow()
989 Tizen.NUI.Text.Shadow shadow;
990 using (var shadowMap = (PropertyMap)GetValue(ShadowProperty))
992 shadow = TextMapHelper.GetShadowStruct(shadowMap);
998 /// Describes a text shadow for a TextLabel.
999 /// It is null by default.
1001 [EditorBrowsable(EditorBrowsableState.Never)]
1002 public TextShadow TextShadow
1006 return (TextShadow)GetValue(TextShadowProperty);
1010 SetValue(TextShadowProperty, value);
1011 NotifyPropertyChanged();
1016 /// The Emboss property.<br />
1017 /// The default emboss parameters.<br />
1019 /// <since_tizen> 3 </since_tizen>
1020 public string Emboss
1024 return (string)GetValue(EmbossProperty);
1028 SetValue(EmbossProperty, value);
1029 NotifyPropertyChanged();
1034 /// The Outline property.<br />
1035 /// The default outline parameters.<br />
1036 /// The outline map contains the following keys :<br />
1037 /// <list type="table">
1038 /// <item><term>color (Color)</term><description>The color of the outline (the default color is Color.White)</description></item>
1039 /// <item><term>width (float)</term><description>The width in pixels of the outline (If not provided then the outline is not enabled)</description></item>
1042 /// <since_tizen> 3 </since_tizen>
1043 [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1721: Property names should not match get methods")]
1044 public PropertyMap Outline
1048 return (PropertyMap)GetValue(OutlineProperty);
1052 SetValue(OutlineProperty, value);
1053 NotifyPropertyChanged();
1058 /// Set Outline to TextLabel. <br />
1060 /// <param name="outline">The Outline</param>
1062 /// SetOutline specifies the outline of the text through <see cref="Tizen.NUI.Text.Outline"/>. <br />
1065 /// The following example demonstrates how to use the SetOutline method.
1067 /// var outline = new Tizen.NUI.Text.Outline();
1068 /// outline.Width = 2.0f;
1069 /// outline.Color = new Color("#45B39D");
1070 /// label.SetOutline(outline);
1073 [EditorBrowsable(EditorBrowsableState.Never)]
1074 public void SetOutline(Outline outline)
1076 using (var outlineMap = TextMapHelper.GetOutlineMap(outline))
1078 SetValue(OutlineProperty, outlineMap);
1083 /// Get Outline from TextLabel. <br />
1085 /// <returns>The Outline</returns>
1087 /// <see cref="Tizen.NUI.Text.Outline"/>
1089 [EditorBrowsable(EditorBrowsableState.Never)]
1090 public Outline GetOutline()
1093 using (var outlineMap = (PropertyMap)GetValue(OutlineProperty))
1095 outline = TextMapHelper.GetOutlineStruct(outlineMap);
1101 /// Set Strikethrough to TextLabel. <br />
1103 /// <param name="strikethrough">The Strikethrough</param>
1105 /// SetStrikethrough specifies the strikethrough of the text through <see cref="Tizen.NUI.Text.Strikethrough"/>. <br />
1108 /// The following example demonstrates how to use the SetStrikethrough method.
1110 /// var strikethrough = new Tizen.NUI.Text.Strikethrough();
1111 /// strikethrough.Enable = true;
1112 /// strikethrough.Color = new Color("#3498DB");
1113 /// strikethrough.Height = 2.0f;
1114 /// label.SetStrikethrough(strikethrough);
1117 [EditorBrowsable(EditorBrowsableState.Never)]
1118 public void SetStrikethrough(Strikethrough strikethrough)
1120 using (var map = TextMapHelper.GetStrikethroughMap(strikethrough))
1121 using (var propertyValue = new PropertyValue(map))
1123 SetProperty(TextLabel.Property.Strikethrough, propertyValue);
1128 /// Get Strikethrough from TextLabel. <br />
1130 /// <returns>The Strikethrough</returns>
1132 /// <see cref="Tizen.NUI.Text.Strikethrough"/>
1134 [EditorBrowsable(EditorBrowsableState.Never)]
1135 public Strikethrough GetStrikethrough()
1137 Strikethrough strikethrough;
1138 using (var propertyValue = GetProperty(TextLabel.Property.Strikethrough))
1139 using (var map = new PropertyMap())
1141 propertyValue.Get(map);
1142 strikethrough = TextMapHelper.GetStrikethroughStruct(map);
1144 return strikethrough;
1148 /// The PixelSize property.<br />
1149 /// The size of font in pixels.<br />
1151 /// <since_tizen> 3 </since_tizen>
1152 [Binding.TypeConverter(typeof(FloatGraphicsTypeConverter))]
1153 public float PixelSize
1157 return (float)GetValue(PixelSizeProperty);
1161 SetValue(PixelSizeProperty, value);
1162 NotifyPropertyChanged();
1167 /// The Ellipsis property.<br />
1168 /// Enable or disable the ellipsis.<br />
1170 /// <since_tizen> 3 </since_tizen>
1171 public bool Ellipsis
1175 return (bool)GetValue(EllipsisProperty);
1179 SetValue(EllipsisProperty, value);
1180 NotifyPropertyChanged();
1185 /// The ellipsis position of the text.
1186 /// Specifies which portion of the text should be replaced with an ellipsis when the text size exceeds the layout size.<br />
1188 /// <since_tizen> 9 </since_tizen>
1189 public EllipsisPosition EllipsisPosition
1193 return (EllipsisPosition)GetValue(EllipsisPositionProperty);
1197 SetValue(EllipsisPositionProperty, value);
1198 NotifyPropertyChanged();
1203 /// The AutoScrollLoopDelay property.<br />
1204 /// The amount of time to delay the starting time of auto scrolling and further loops.<br />
1206 /// <since_tizen> 3 </since_tizen>
1207 public float AutoScrollLoopDelay
1211 return (float)GetValue(AutoScrollLoopDelayProperty);
1215 SetValue(AutoScrollLoopDelayProperty, value);
1216 NotifyPropertyChanged();
1221 /// The AutoScrollStopMode property.<br />
1222 /// The auto scrolling stop behaviour.<br />
1223 /// The default value is AutoScrollStopMode.FinishLoop. <br />
1225 /// <since_tizen> 3 </since_tizen>
1226 public AutoScrollStopMode AutoScrollStopMode
1230 return (AutoScrollStopMode)GetValue(AutoScrollStopModeProperty);
1234 SetValue(AutoScrollStopModeProperty, value);
1235 NotifyPropertyChanged();
1240 /// The line count of the text.
1242 /// <since_tizen> 3 </since_tizen>
1243 public int LineCount
1248 using (var propertyValue = GetProperty(TextLabel.Property.LineCount))
1250 propertyValue.Get(out lineCount);
1257 /// The LineWrapMode property.<br />
1258 /// line wrap mode when the text lines over layout width.<br />
1260 /// <since_tizen> 4 </since_tizen>
1261 public LineWrapMode LineWrapMode
1265 return (LineWrapMode)GetValue(LineWrapModeProperty);
1269 SetValue(LineWrapModeProperty, value);
1270 NotifyPropertyChanged();
1275 /// The direction of the text such as left to right or right to left.
1277 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
1278 [EditorBrowsable(EditorBrowsableState.Never)]
1279 public TextDirection TextDirection
1283 int textDirection = 0;
1284 using (var propertyValue = GetProperty(TextLabel.Property.TextDirection))
1286 propertyValue.Get(out textDirection);
1288 return (TextDirection)textDirection;
1293 /// The vertical line alignment of the text.
1295 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
1296 [EditorBrowsable(EditorBrowsableState.Never)]
1297 public VerticalLineAlignment VerticalLineAlignment
1301 return (VerticalLineAlignment)GetValue(VerticalLineAlignmentProperty);
1305 SetValue(VerticalLineAlignmentProperty, value);
1306 NotifyPropertyChanged();
1311 /// The text alignment to match the direction of the system language.
1313 /// <since_tizen> 6 </since_tizen>
1314 public bool MatchSystemLanguageDirection
1318 return (bool)GetValue(MatchSystemLanguageDirectionProperty);
1322 SetValue(MatchSystemLanguageDirectionProperty, value);
1323 NotifyPropertyChanged();
1328 /// The text fit parameters.<br />
1329 /// The textFit map contains the following keys :<br />
1330 /// <list type="table">
1331 /// <item><term>enable (bool)</term><description>True to enable the text fit or false to disable (the default value is false)</description></item>
1332 /// <item><term>minSize (float)</term><description>Minimum Size for text fit (the default value is 10.f)</description></item>
1333 /// <item><term>maxSize (float)</term><description>Maximum Size for text fit (the default value is 100.f)</description></item>
1334 /// <item><term>stepSize (float)</term><description>Step Size for font increase (the default value is 1.f)</description></item>
1335 /// <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>
1338 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
1339 [EditorBrowsable(EditorBrowsableState.Never)]
1340 [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1721: Property names should not match get methods")]
1341 public PropertyMap TextFit
1345 return (PropertyMap)GetValue(TextFitProperty);
1349 SetValue(TextFitProperty, value);
1350 NotifyPropertyChanged();
1355 /// Set TextFit to TextLabel. <br />
1357 /// <param name="textFit">The TextFit</param>
1359 /// SetTextFit specifies the textFit of the text through <see cref="Tizen.NUI.Text.TextFit"/>. <br />
1362 /// The following example demonstrates how to use the SetTextFit method.
1364 /// var textFit = new Tizen.NUI.Text.TextFit();
1365 /// textFit.Enable = true;
1366 /// textFit.MinSize = 10.0f;
1367 /// textFit.MaxSize = 100.0f;
1368 /// textFit.StepSize = 5.0f;
1369 /// textFit.FontSizeType = FontSizeType.PointSize;
1370 /// label.SetTextFit(textFit);
1373 [EditorBrowsable(EditorBrowsableState.Never)]
1374 public void SetTextFit(TextFit textFit)
1376 using (var textFitMap = TextMapHelper.GetTextFitMap(textFit))
1378 SetValue(TextFitProperty, textFitMap);
1383 /// Get TextFit from TextLabel. <br />
1385 /// <returns>The TextFit</returns>
1387 /// TextFit is always returned based on PointSize. <br />
1388 /// If the user sets FontSizeType to PixelSize, then MinSize, MaxSize, and StepSize are converted based on PointSize and returned. <br />
1389 /// <see cref="Tizen.NUI.Text.TextFit"/>
1391 [EditorBrowsable(EditorBrowsableState.Never)]
1392 public TextFit GetTextFit()
1395 using (var textFitMap = (PropertyMap)GetValue(TextFitProperty))
1397 textFit = TextMapHelper.GetTextFitStruct(textFitMap);
1403 /// The MinLineSize property.<br />
1404 /// The height of the line in points. <br />
1405 /// If the font size is larger than the line size, it works with the font size. <br />
1407 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
1408 [EditorBrowsable(EditorBrowsableState.Never)]
1409 public float MinLineSize
1413 return (float)GetValue(MinLineSizeProperty);
1417 SetValue(MinLineSizeProperty, value);
1418 NotifyPropertyChanged();
1423 /// The spaces between characters in Pixels.
1425 /// A positive value will make the characters far apart (expanded) and a negative value will bring them closer (condensed).<br />
1426 /// The default value is 0.f which does nothing.
1429 [EditorBrowsable(EditorBrowsableState.Never)]
1430 public float CharacterSpacing
1434 return (float)GetValue(CharacterSpacingProperty);
1438 SetValue(CharacterSpacingProperty, value);
1439 NotifyPropertyChanged();
1444 /// The FontSizeScale property for scaling the specified font size up or down. <br />
1445 /// The default value is 1.0. <br />
1446 /// The given font size scale value is used for multiplying the specified font size before querying fonts. <br />
1447 /// If FontSizeScale.UseSystemSetting, will use the SystemSettings.FontSize internally. <br />
1449 /// <since_tizen> 9 </since_tizen>
1450 public float FontSizeScale
1454 return (float)GetValue(FontSizeScaleProperty);
1458 SetValue(FontSizeScaleProperty, value);
1459 NotifyPropertyChanged();
1463 private float InternalFontSizeScale
1467 return fontSizeScale;
1471 float newFontSizeScale;
1473 if (fontSizeScale == value) return;
1475 fontSizeScale = value;
1476 if (fontSizeScale == Tizen.NUI.FontSizeScale.UseSystemSetting)
1478 SystemSettingsFontSize systemSettingsFontSize;
1482 systemSettingsFontSize = SystemSettings.FontSize;
1486 Console.WriteLine("{0} Exception caught.", e);
1487 systemSettingsFontSize = SystemSettingsFontSize.Normal;
1489 newFontSizeScale = TextUtils.GetFontSizeScale(systemSettingsFontSize);
1490 addFontSizeChangedCallback();
1494 newFontSizeScale = fontSizeScale;
1495 removeFontSizeChangedCallback();
1498 SetInternalFontSizeScale(newFontSizeScale);
1502 private void SetInternalFontSizeScale(float fontSizeScale)
1505 Object.InternalSetPropertyFloat(this.SwigCPtr, TextLabel.Property.FontSizeScale, (float)fontSizeScale);
1510 /// The EnableFontSizeScale property.<br />
1511 /// Whether the font size scale is enabled. (The default value is true)
1513 [EditorBrowsable(EditorBrowsableState.Never)]
1514 public bool EnableFontSizeScale
1518 return (bool)GetValue(EnableFontSizeScaleProperty);
1522 SetValue(EnableFontSizeScaleProperty, value);
1523 NotifyPropertyChanged();
1527 private TextLabelSelectorData EnsureSelectorData() => selectorData ?? (selectorData = new TextLabelSelectorData());
1530 /// Downcasts a handle to textLabel handle
1532 /// <param name="handle"></param>
1533 /// <returns></returns>
1534 /// <exception cref="ArgumentNullException"> Thrown when handle is null. </exception>
1535 /// <since_tizen> 3 </since_tizen>
1536 /// Do not use this, that will be deprecated. Use as keyword instead.
1537 [Obsolete("Do not use this, that will be deprecated. Use as keyword instead. " +
1539 "BaseHandle handle = new TextLabel(\"Hello World!\"); " +
1540 "TextLabel label = handle as TextLabel")]
1541 [EditorBrowsable(EditorBrowsableState.Never)]
1542 public static TextLabel DownCast(BaseHandle handle)
1546 throw new ArgumentNullException(nameof(handle));
1548 TextLabel ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as TextLabel;
1549 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1554 [EditorBrowsable(EditorBrowsableState.Never)]
1555 protected override void Dispose(DisposeTypes type)
1562 internalTextColor?.Dispose();
1564 if (systemlangTextFlag)
1566 SystemSettings.LocaleLanguageChanged -= SystemSettings_LocaleLanguageChanged;
1569 RemoveSystemSettingsFontTypeChanged();
1571 removeFontSizeChangedCallback();
1573 if (type == DisposeTypes.Explicit)
1576 //Release your own managed resources here.
1577 //You should release all of your own disposable objects here.
1578 selectorData?.Reset(this);
1583 if (textLabelTextFitChangedCallbackDelegate != null)
1585 TextFitChangedSignal().Disconnect(textLabelTextFitChangedCallbackDelegate);
1592 /// This will not be public opened.
1593 [EditorBrowsable(EditorBrowsableState.Never)]
1594 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
1596 Interop.TextLabel.DeleteTextLabel(swigCPtr);
1600 /// Get attribues, it is abstract function and must be override.
1602 [EditorBrowsable(EditorBrowsableState.Never)]
1603 protected override ViewStyle CreateViewStyle()
1605 return new TextLabelStyle();
1608 internal override LayoutItem CreateDefaultLayout()
1610 return new TextLayout();
1614 /// Invoked whenever the binding context of the textlabel changes. Implement this method to add class handling for this event.
1616 protected override void OnBindingContextChanged()
1618 base.OnBindingContextChanged();
1621 private void SystemSettings_LocaleLanguageChanged(object sender, LocaleLanguageChangedEventArgs e)
1623 Text = NUIApplication.MultilingualResourceManager?.GetString(textLabelSid, new CultureInfo(e.Value.Replace("_", "-")));
1626 private void SystemSettingsFontSizeChanged(object sender, FontSizeChangedEventArgs e)
1628 float newFontSizeScale = TextUtils.GetFontSizeScale(e.Value);
1629 SetInternalFontSizeScale(newFontSizeScale);
1632 private void addFontSizeChangedCallback()
1634 if (hasFontSizeChangedCallback != true)
1638 SystemSettings.FontSizeChanged += SystemSettingsFontSizeChanged;
1639 hasFontSizeChangedCallback = true;
1643 Console.WriteLine("{0} Exception caught.", e);
1644 hasFontSizeChangedCallback = false;
1649 private void removeFontSizeChangedCallback()
1651 if (hasFontSizeChangedCallback == true)
1655 SystemSettings.FontSizeChanged -= SystemSettingsFontSizeChanged;
1656 hasFontSizeChangedCallback = false;
1660 Console.WriteLine("{0} Exception caught.", e);
1661 hasFontSizeChangedCallback = true;
1666 private void SystemSettingsFontTypeChanged(object sender, FontTypeChangedEventArgs e)
1668 SetInternalFontFamily(e.Value);
1671 private void AddSystemSettingsFontTypeChanged()
1673 if (HasStyle() && !hasSystemFontTypeChanged)
1677 SystemSettings.FontTypeChanged += SystemSettingsFontTypeChanged;
1678 hasSystemFontTypeChanged = true;
1682 Console.WriteLine("{0} Exception caught.", e);
1683 hasSystemFontTypeChanged = false;
1688 private void RemoveSystemSettingsFontTypeChanged()
1690 if (hasSystemFontTypeChanged)
1694 SystemSettings.FontTypeChanged -= SystemSettingsFontTypeChanged;
1695 hasSystemFontTypeChanged = false;
1699 Console.WriteLine("{0} Exception caught.", e);
1700 hasSystemFontTypeChanged = true;
1705 private void RequestLayout()
1707 Layout?.RequestLayout();
1710 internal new class Property
1712 internal static readonly int TEXT = Interop.TextLabel.TextGet();
1713 internal static readonly int FontFamily = Interop.TextLabel.FontFamilyGet();
1714 internal static readonly int FontStyle = Interop.TextLabel.FontStyleGet();
1715 internal static readonly int PointSize = Interop.TextLabel.PointSizeGet();
1716 internal static readonly int MultiLine = Interop.TextLabel.MultiLineGet();
1717 internal static readonly int HorizontalAlignment = Interop.TextLabel.HorizontalAlignmentGet();
1718 internal static readonly int VerticalAlignment = Interop.TextLabel.VerticalAlignmentGet();
1719 internal static readonly int TextColor = Interop.TextLabel.TextColorGet();
1720 internal static readonly int EnableMarkup = Interop.TextLabel.EnableMarkupGet();
1721 internal static readonly int EnableAutoScroll = Interop.TextLabel.EnableAutoScrollGet();
1722 internal static readonly int AutoScrollSpeed = Interop.TextLabel.AutoScrollSpeedGet();
1723 internal static readonly int AutoScrollLoopCount = Interop.TextLabel.AutoScrollLoopCountGet();
1724 internal static readonly int AutoScrollGap = Interop.TextLabel.AutoScrollGapGet();
1725 internal static readonly int LineSpacing = Interop.TextLabel.LineSpacingGet();
1726 internal static readonly int RelativeLineHeight = Interop.TextLabel.RelativeLineHeightGet();
1727 internal static readonly int UNDERLINE = Interop.TextLabel.UnderlineGet();
1728 internal static readonly int SHADOW = Interop.TextLabel.ShadowGet();
1729 internal static readonly int EMBOSS = Interop.TextLabel.EmbossGet();
1730 internal static readonly int OUTLINE = Interop.TextLabel.OutlineGet();
1731 internal static readonly int PixelSize = Interop.TextLabel.PixelSizeGet();
1732 internal static readonly int ELLIPSIS = Interop.TextLabel.EllipsisGet();
1733 internal static readonly int AutoScrollStopMode = Interop.TextLabel.AutoScrollStopModeGet();
1734 internal static readonly int AutoScrollLoopDelay = Interop.TextLabel.AutoScrollLoopDelayGet();
1735 internal static readonly int LineCount = Interop.TextLabel.LineCountGet();
1736 internal static readonly int LineWrapMode = Interop.TextLabel.LineWrapModeGet();
1737 internal static readonly int TextDirection = Interop.TextLabel.TextDirectionGet();
1738 internal static readonly int VerticalLineAlignment = Interop.TextLabel.VerticalLineAlignmentGet();
1739 internal static readonly int MatchSystemLanguageDirection = Interop.TextLabel.MatchSystemLanguageDirectionGet();
1740 internal static readonly int TextFit = Interop.TextLabel.TextFitGet();
1741 internal static readonly int MinLineSize = Interop.TextLabel.MinLineSizeGet();
1742 internal static readonly int FontSizeScale = Interop.TextLabel.FontSizeScaleGet();
1743 internal static readonly int EnableFontSizeScale = Interop.TextLabel.EnableFontSizeScaleGet();
1744 internal static readonly int EllipsisPosition = Interop.TextLabel.EllipsisPositionGet();
1745 internal static readonly int Strikethrough = Interop.TextLabel.StrikethroughGet();
1746 internal static readonly int CharacterSpacing = Interop.TextLabel.CharacterSpacingGet();
1749 private void OnShadowColorChanged(float x, float y, float z, float w)
1751 ShadowColor = new Vector4(x, y, z, w);
1753 private void OnShadowOffsetChanged(float x, float y)
1755 ShadowOffset = new Vector2(x, y);
1757 private void OnTextColorChanged(float r, float g, float b, float a)
1759 TextColor = new Color(r, g, b, a);
1761 private void OnUnderlineColorChanged(float x, float y, float z, float w)
1763 UnderlineColor = new Vector4(x, y, z, w);