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;
26 namespace Tizen.NUI.BaseComponents
29 /// A control which renders a short text string.<br />
30 /// Text labels are lightweight, non-editable, and do not respond to the user input.<br />
32 /// <since_tizen> 3 </since_tizen>
33 public partial class TextLabel : View
35 private class TextLayout : LayoutItem
37 protected override void OnMeasure(MeasureSpecification widthMeasureSpec, MeasureSpecification heightMeasureSpec)
39 // Padding will be automatically applied by DALi TextLabel.
40 float totalWidth = widthMeasureSpec.Size.AsDecimal();
41 float totalHeight = heightMeasureSpec.Size.AsDecimal();
43 if (widthMeasureSpec.Mode == MeasureSpecification.ModeType.Exactly)
45 if (heightMeasureSpec.Mode != MeasureSpecification.ModeType.Exactly)
47 totalHeight = Owner.GetHeightForWidth(totalWidth);
48 heightMeasureSpec = new MeasureSpecification(new LayoutLength(totalHeight), MeasureSpecification.ModeType.Exactly);
53 var minSize = Owner.MinimumSize;
54 var maxSize = Owner.MaximumSize;
55 var naturalSize = Owner.GetNaturalSize();
57 if (heightMeasureSpec.Mode == MeasureSpecification.ModeType.Exactly)
59 // GetWidthForHeight is not implemented.
60 totalWidth = Math.Min(Math.Max(naturalSize.Width, minSize.Width), (maxSize.Width < 0 ? Int32.MaxValue : maxSize.Width));
61 widthMeasureSpec = new MeasureSpecification(new LayoutLength(totalWidth), MeasureSpecification.ModeType.Exactly);
65 totalWidth = Math.Min(Math.Max(naturalSize.Width, minSize.Width), (maxSize.Width < 0 ? Int32.MaxValue : maxSize.Width));
66 totalHeight = Math.Min(Math.Max(naturalSize.Height, minSize.Height), (maxSize.Height < 0 ? Int32.MaxValue : maxSize.Height));
68 heightMeasureSpec = new MeasureSpecification(new LayoutLength(totalHeight), MeasureSpecification.ModeType.Exactly);
69 widthMeasureSpec = new MeasureSpecification(new LayoutLength(totalWidth), MeasureSpecification.ModeType.Exactly);
73 MeasuredSize.StateType childWidthState = MeasuredSize.StateType.MeasuredSizeOK;
74 MeasuredSize.StateType childHeightState = MeasuredSize.StateType.MeasuredSizeOK;
76 SetMeasuredDimensions(ResolveSizeAndState(new LayoutLength(totalWidth), widthMeasureSpec, childWidthState),
77 ResolveSizeAndState(new LayoutLength(totalHeight), heightMeasureSpec, childHeightState));
81 static TextLabel() { }
83 private string textLabelSid = null;
84 private bool systemlangTextFlag = false;
85 private TextLabelSelectorData selectorData;
86 private float fontSizeScale = 1.0f;
87 private bool hasFontSizeChangedCallback = false;
90 /// Creates the TextLabel control.
92 /// <since_tizen> 3 </since_tizen>
93 public TextLabel() : this(Interop.TextLabel.New(), true)
95 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
98 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
99 [EditorBrowsable(EditorBrowsableState.Never)]
100 public TextLabel(TextLabelStyle viewStyle) : this(Interop.TextLabel.New(), true, viewStyle)
105 /// Creates the TextLabel with setting the status of shown or hidden.
107 /// <param name="shown">false : Not displayed (hidden), true : displayed (shown)</param>
108 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
109 [EditorBrowsable(EditorBrowsableState.Never)]
110 public TextLabel(bool shown) : this(Interop.TextLabel.New(), true)
112 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
117 /// Creates the TextLabel control.
119 /// <param name="text">The text to display</param>
120 /// <since_tizen> 3 </since_tizen>
121 public TextLabel(string text) : this(Interop.TextLabel.New(text), true)
123 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
127 /// Creates the TextLabel with setting the status of shown or hidden.
129 /// <param name="text">The text to display</param>
130 /// <param name="shown">false : Not displayed (hidden), true : displayed (shown)</param>
131 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
132 [EditorBrowsable(EditorBrowsableState.Never)]
133 public TextLabel(string text, bool shown) : this(Interop.TextLabel.New(text), true)
135 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
139 internal TextLabel(TextLabel handle, bool shown = true) : this(Interop.TextLabel.NewTextLabel(TextLabel.getCPtr(handle)), true)
141 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
149 internal TextLabel(global::System.IntPtr cPtr, bool cMemoryOwn, ViewStyle viewStyle, bool shown = true) : base(cPtr, cMemoryOwn, viewStyle)
157 internal TextLabel(global::System.IntPtr cPtr, bool cMemoryOwn, bool shown = true) : base(cPtr, cMemoryOwn, null)
166 /// The TranslatableText property.<br />
167 /// The text can set the SID value.<br />
169 /// <exception cref='ArgumentNullException'>
170 /// ResourceManager about multilingual is null.
172 /// <since_tizen> 4 </since_tizen>
173 public string TranslatableText
177 return (string)GetValue(TranslatableTextProperty);
181 SetValue(TranslatableTextProperty, value);
184 private string translatableText
192 if (NUIApplication.MultilingualResourceManager == null)
194 throw new ArgumentNullException(null, "ResourceManager about multilingual is null");
196 string translatableText = null;
197 textLabelSid = value;
198 translatableText = NUIApplication.MultilingualResourceManager?.GetString(textLabelSid, new CultureInfo(SystemSettings.LocaleLanguage.Replace("_", "-")));
199 if (translatableText != null)
201 Text = translatableText;
202 if (systemlangTextFlag == false)
204 SystemSettings.LocaleLanguageChanged += SystemSettings_LocaleLanguageChanged;
205 systemlangTextFlag = true;
212 NotifyPropertyChanged();
217 /// The Text property.<br />
218 /// The text to display in the UTF-8 format.<br />
220 /// <since_tizen> 3 </since_tizen>
225 return (string)GetValue(TextProperty);
229 SetValue(TextProperty, value);
230 NotifyPropertyChanged();
235 /// The FontFamily property.<br />
236 /// The requested font family to use.<br />
238 /// <since_tizen> 3 </since_tizen>
239 public string FontFamily
243 return (string)GetValue(FontFamilyProperty);
247 SetValue(FontFamilyProperty, value);
248 NotifyPropertyChanged();
253 /// The FontStyle property.<br />
254 /// The requested font style to use.<br />
255 /// The fontStyle map contains the following keys :<br />
256 /// <list type="table">
257 /// <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>
258 /// <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>
259 /// <item><term>slant (string)</term><description>The slant key defines whether to use italics. (values: normal, roman, italic, oblique)</description></item>
262 /// <since_tizen> 3 </since_tizen>
263 [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1721: Property names should not match get methods")]
264 public PropertyMap FontStyle
268 return (PropertyMap)GetValue(FontStyleProperty);
272 SetValue(FontStyleProperty, value);
273 NotifyPropertyChanged();
278 /// Set FontStyle to TextLabel. <br />
280 /// <param name="fontStyle">The FontStyle</param>
282 /// SetFontStyle specifies the requested font style through <see cref="Tizen.NUI.Text.FontStyle"/>. <br />
285 /// The following example demonstrates how to use the SetFontStyle method.
287 /// var fontStyle = new Tizen.NUI.Text.FontStyle();
288 /// fontStyle.Width = FontWidthType.Expanded;
289 /// fontStyle.Weight = FontWeightType.Bold;
290 /// fontStyle.Slant = FontSlantType.Italic;
291 /// label.SetFontStyle(fontStyle);
294 [EditorBrowsable(EditorBrowsableState.Never)]
295 public void SetFontStyle(FontStyle fontStyle)
297 using (var fontStyleMap = TextMapHelper.GetFontStyleMap(fontStyle))
299 SetValue(FontStyleProperty, fontStyleMap);
304 /// Get FontStyle from TextLabel. <br />
306 /// <returns>The FontStyle</returns>
308 /// <see cref="Tizen.NUI.Text.FontStyle"/>
310 [EditorBrowsable(EditorBrowsableState.Never)]
311 public FontStyle GetFontStyle()
314 using (var fontStyleMap = (PropertyMap)GetValue(FontStyleProperty))
316 fontStyle = TextMapHelper.GetFontStyleStruct(fontStyleMap);
322 /// The PointSize property.<br />
323 /// The size of font in points.<br />
325 /// <since_tizen> 3 </since_tizen>
326 public float PointSize
330 return (float)GetValue(PointSizeProperty);
334 SetValue(PointSizeProperty, value);
335 NotifyPropertyChanged();
340 /// The MultiLine property.<br />
341 /// The single-line or multi-line layout option.<br />
343 /// <since_tizen> 3 </since_tizen>
344 public bool MultiLine
348 return (bool)GetValue(MultiLineProperty);
352 SetValue(MultiLineProperty, value);
353 NotifyPropertyChanged();
358 /// The HorizontalAlignment property.<br />
359 /// The line horizontal alignment.<br />
361 /// <since_tizen> 3 </since_tizen>
362 public HorizontalAlignment HorizontalAlignment
366 return (HorizontalAlignment)GetValue(HorizontalAlignmentProperty);
370 SetValue(HorizontalAlignmentProperty, value);
371 NotifyPropertyChanged();
376 /// The VerticalAlignment property.<br />
377 /// The line vertical alignment.<br />
379 /// <since_tizen> 3 </since_tizen>
380 public VerticalAlignment VerticalAlignment
384 return (VerticalAlignment)GetValue(VerticalAlignmentProperty);
388 SetValue(VerticalAlignmentProperty, value);
389 NotifyPropertyChanged();
394 /// The TextColor property.<br />
395 /// The color of the text.<br />
396 /// Animation framework can be used to change the color of the text when not using mark up.<br />
397 /// Cannot animate the color when text is auto scrolling.<br />
400 /// The property cascade chaining set is possible. For example, this (textLabel.TextColor.X = 0.1f;) is possible.
402 /// <since_tizen> 3 </since_tizen>
403 public Color TextColor
407 Color temp = (Color)GetValue(TextColorProperty);
408 return new Color(OnTextColorChanged, temp.R, temp.G, temp.B, temp.A);
412 SetValue(TextColorProperty, value);
413 NotifyPropertyChanged();
418 /// The ShadowOffset property.<br />
419 /// The drop shadow offset 0 indicates no shadow.<br />
421 /// <since_tizen> 3 </since_tizen>
423 /// Deprecated.(API Level 6) Use Shadow instead.
424 /// The property cascade chaining set is possible. For example, this (textLabel.ShadowOffset.X = 0.1f;) is possible.
426 [Obsolete("Please do not use this ShadowOffset(Deprecated). Please use Shadow instead.")]
427 public Vector2 ShadowOffset
431 return GetValue(ShadowOffsetProperty) as Vector2;
435 SetValue(ShadowOffsetProperty, value);
439 private Vector2 InternalShadowOffset
443 float x = 0.0f, y = 0.0f;
444 using (var propertyValue = Shadow.Find(TextLabel.Property.SHADOW, "offset"))
445 using (var shadowOffset = new Vector2())
447 if (null != propertyValue)
449 propertyValue.Get(shadowOffset);
454 return new Vector2(OnShadowOffsetChanged, x, y);
458 using (var map = new PropertyMap())
460 map.Add("offset", value);
462 var shadowMap = Shadow;
463 shadowMap.Merge(map);
465 SetValue(ShadowProperty, shadowMap);
466 NotifyPropertyChanged();
472 /// The ShadowColor property.<br />
473 /// The color of a drop shadow.<br />
475 /// <since_tizen> 3 </since_tizen>
477 /// Deprecated.(API Level 6) Use Shadow instead.
478 /// The property cascade chaining set is possible. For example, this (textLabel.ShadowColor.X = 0.1f;) is possible.
480 [Obsolete("Please do not use this ShadowColor(Deprecated). Please use Shadow instead.")]
481 public Vector4 ShadowColor
485 return GetValue(ShadowColorProperty) as Vector4;
489 SetValue(ShadowColorProperty, value);
493 private Vector4 InternalShadowColor
497 float x = 0.0f, y = 0.0f, z = 0.0f, w = 0.0f;
498 using (var propertyValue = Shadow.Find(TextLabel.Property.SHADOW, "color"))
499 using (var shadowColor = new Vector4())
501 if (null != propertyValue)
503 propertyValue.Get(shadowColor);
510 return new Vector4(OnShadowColorChanged, x, y, z, w);
514 using (var map = new PropertyMap())
516 map.Add("color", value);
517 var shadowMap = Shadow;
518 shadowMap.Merge(map);
519 SetValue(ShadowProperty, shadowMap);
520 NotifyPropertyChanged();
526 /// The UnderlineEnabled property.<br />
527 /// The underline enabled flag.<br />
529 /// <since_tizen> 3 </since_tizen>
531 /// Deprecated.(API Level 6) Use Underline instead.
533 [Obsolete("Please do not use this UnderlineEnabled(Deprecated). Please use Underline instead.")]
534 public bool UnderlineEnabled
538 return (bool)GetValue(UnderlineEnabledProperty);
542 SetValue(UnderlineEnabledProperty, value);
546 private bool InternalUnderlineEnabled
550 bool underlineEnabled = false;
551 using (var propertyValue = Underline.Find(TextLabel.Property.UNDERLINE, "enable"))
553 propertyValue.Get(out underlineEnabled);
555 return underlineEnabled;
559 using (var map = new PropertyMap())
561 map.Add("enable", value);
562 var undelineMap = Underline;
563 undelineMap.Merge(map);
564 SetValue(UnderlineProperty, undelineMap);
565 NotifyPropertyChanged();
571 /// The UnderlineColor property.<br />
572 /// Overrides the underline height from font metrics.<br />
574 /// <since_tizen> 3 </since_tizen>
576 /// Deprecated.(API Level 6) Use Underline instead.
577 /// The property cascade chaining set is possible. For example, this (textLabel.UnderlineColor.X = 0.1f;) is possible.
579 [Obsolete("Please do not use this UnderlineColor(Deprecated). Please use Underline instead.")]
580 public Vector4 UnderlineColor
584 return GetValue(UnderlineColorProperty) as Vector4;
588 SetValue(UnderlineColorProperty, value);
592 private Vector4 InternalUnderlineColor
596 float x = 0.0f, y = 0.0f, z = 0.0f, w = 0.0f;
597 using (var propertyValue = Underline.Find(TextLabel.Property.UNDERLINE, "color"))
598 using (var underlineColor = new Vector4())
600 if (null != propertyValue)
602 propertyValue.Get(underlineColor);
603 x = underlineColor.X;
604 y = underlineColor.Y;
605 z = underlineColor.Z;
606 w = underlineColor.W;
609 return new Vector4(OnUnderlineColorChanged, x, y, z, w);
613 using (var map = new PropertyMap())
615 map.Add("color", value);
616 var undelineMap = Underline;
617 undelineMap.Merge(map);
618 SetValue(UnderlineProperty, undelineMap);
619 NotifyPropertyChanged();
625 /// The UnderlineHeight property.<br />
626 /// Overrides the underline height from font metrics.<br />
628 /// <since_tizen> 3 </since_tizen>
630 /// Deprecated.(API Level 6) Use Underline instead.
632 [Obsolete("Please do not use this UnderlineHeight(Deprecated). Please use Underline instead.")]
633 public float UnderlineHeight
637 return (float)GetValue(UnderlineHeightProperty);
641 SetValue(UnderlineHeightProperty, value);
645 private float InternalUnderlineHeight
649 float underlineHeight = 0.0f;
650 using (var propertyValue = Underline.Find(TextLabel.Property.UNDERLINE, "height"))
652 if (null != propertyValue)
654 propertyValue.Get(out underlineHeight);
657 return underlineHeight;
661 using (var map = new PropertyMap())
663 map.Add("height", value);
664 var undelineMap = Underline;
665 undelineMap.Merge(map);
666 SetValue(UnderlineProperty, undelineMap);
667 NotifyPropertyChanged();
673 /// The EnableMarkup property.<br />
674 /// Whether the mark-up processing is enabled.<br />
676 /// <since_tizen> 3 </since_tizen>
677 public bool EnableMarkup
681 return (bool)GetValue(EnableMarkupProperty);
685 SetValue(EnableMarkupProperty, value);
686 NotifyPropertyChanged();
691 /// The EnableAutoScroll property.<br />
692 /// Starts or stops auto scrolling.<br />
694 /// <since_tizen> 3 </since_tizen>
695 public bool EnableAutoScroll
699 return (bool)GetValue(EnableAutoScrollProperty);
703 SetValue(EnableAutoScrollProperty, value);
704 NotifyPropertyChanged();
709 /// The AutoScrollSpeed property.<br />
710 /// Sets the speed of scrolling in pixels per second.<br />
712 /// <since_tizen> 3 </since_tizen>
713 public int AutoScrollSpeed
717 return (int)GetValue(AutoScrollSpeedProperty);
721 SetValue(AutoScrollSpeedProperty, value);
722 NotifyPropertyChanged();
727 /// The AutoScrollLoopCount property.<br />
728 /// Number of complete loops when scrolling enabled.<br />
730 /// <since_tizen> 3 </since_tizen>
731 public int AutoScrollLoopCount
735 return (int)GetValue(AutoScrollLoopCountProperty);
739 SetValue(AutoScrollLoopCountProperty, value);
740 NotifyPropertyChanged();
745 /// The AutoScrollGap property.<br />
746 /// Gap before scrolling wraps.<br />
748 /// <since_tizen> 3 </since_tizen>
749 public float AutoScrollGap
753 return (float)GetValue(AutoScrollGapProperty);
757 SetValue(AutoScrollGapProperty, value);
758 NotifyPropertyChanged();
763 /// The LineSpacing property.<br />
764 /// The default extra space between lines in points.<br />
766 /// <since_tizen> 3 </since_tizen>
767 public float LineSpacing
771 return (float)GetValue(LineSpacingProperty);
775 SetValue(LineSpacingProperty, value);
776 NotifyPropertyChanged();
781 /// The Underline property.<br />
782 /// The default underline parameters.<br />
783 /// The underline map contains the following keys :<br />
784 /// <list type="table">
785 /// <item><term>enable (bool)</term><description>Whether the underline is enabled (the default value is false)</description></item>
786 /// <item><term>color (Color)</term><description>The color of the underline (If not provided then the color of the text is used)</description></item>
787 /// <item><term>height (float)</term><description>The height in pixels of the underline (the default value is 1.f)</description></item>
790 /// <since_tizen> 3 </since_tizen>
791 [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1721: Property names should not match get methods")]
792 public PropertyMap Underline
796 return (PropertyMap)GetValue(UnderlineProperty);
800 SetValue(UnderlineProperty, value);
801 NotifyPropertyChanged();
806 /// Set Underline to TextLabel. <br />
808 /// <param name="underline">The Underline</param>
810 /// SetUnderline specifies the underline of the text through <see cref="Tizen.NUI.Text.Underline"/>. <br />
813 /// The following example demonstrates how to use the SetUnderline method.
815 /// var underline = new Tizen.NUI.Text.Underline();
816 /// underline.Enable = true;
817 /// underline.Color = new Color("#3498DB");
818 /// underline.Height = 2.0f;
819 /// label.SetUnderline(underline);
822 [EditorBrowsable(EditorBrowsableState.Never)]
823 public void SetUnderline(Underline underline)
825 using (var underlineMap = TextMapHelper.GetUnderlineMap(underline))
827 SetValue(UnderlineProperty, underlineMap);
832 /// Get Underline from TextLabel. <br />
834 /// <returns>The Underline</returns>
836 /// <see cref="Tizen.NUI.Text.Underline"/>
838 [EditorBrowsable(EditorBrowsableState.Never)]
839 public Underline GetUnderline()
842 using (var underlineMap = (PropertyMap)GetValue(UnderlineProperty))
844 underline = TextMapHelper.GetUnderlineStruct(underlineMap);
850 /// The Shadow property.<br />
851 /// The default shadow parameters.<br />
852 /// The shadow map contains the following keys :<br />
853 /// <list type="table">
854 /// <item><term>color (Color)</term><description>The color of the shadow (the default color is Color.Black)</description></item>
855 /// <item><term>offset (Vector2)</term><description>The offset in pixels of the shadow (If not provided then the shadow is not enabled)</description></item>
856 /// <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>
859 /// <since_tizen> 3 </since_tizen>
860 [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1721: Property names should not match get methods")]
861 public PropertyMap Shadow
865 return (PropertyMap)GetValue(ShadowProperty);
869 SetValue(ShadowProperty, value);
870 NotifyPropertyChanged();
875 /// Set Shadow to TextLabel. <br />
877 /// <param name="shadow">The Shadow</param>
879 /// SetShadow specifies the shadow of the text through <see cref="Tizen.NUI.Text.Shadow"/>. <br />
882 /// The following example demonstrates how to use the SetShadow method.
884 /// var shadow = new Tizen.NUI.Text.Shadow();
885 /// shadow.Offset = new Vector2(3, 3);
886 /// shadow.Color = new Color("#F1C40F");
887 /// shadow.BlurRadius = 4.0f;
888 /// label.SetShadow(shadow);
891 [EditorBrowsable(EditorBrowsableState.Never)]
892 public void SetShadow(Tizen.NUI.Text.Shadow shadow)
894 using (var shadowMap = TextMapHelper.GetShadowMap(shadow))
896 SetValue(ShadowProperty, shadowMap);
901 /// Get Shadow from TextLabel. <br />
903 /// <returns>The Shadow</returns>
905 /// <see cref="Tizen.NUI.Text.Shadow"/>
907 [EditorBrowsable(EditorBrowsableState.Never)]
908 public Tizen.NUI.Text.Shadow GetShadow()
910 Tizen.NUI.Text.Shadow shadow;
911 using (var shadowMap = (PropertyMap)GetValue(ShadowProperty))
913 shadow = TextMapHelper.GetShadowStruct(shadowMap);
919 /// Describes a text shadow for a TextLabel.
920 /// It is null by default.
922 [EditorBrowsable(EditorBrowsableState.Never)]
923 public TextShadow TextShadow
927 return (TextShadow)GetValue(TextShadowProperty);
931 SetValue(TextShadowProperty, value);
932 NotifyPropertyChanged();
937 /// The Emboss property.<br />
938 /// The default emboss parameters.<br />
940 /// <since_tizen> 3 </since_tizen>
945 return (string)GetValue(EmbossProperty);
949 SetValue(EmbossProperty, value);
950 NotifyPropertyChanged();
955 /// The Outline property.<br />
956 /// The default outline parameters.<br />
957 /// The outline map contains the following keys :<br />
958 /// <list type="table">
959 /// <item><term>color (Color)</term><description>The color of the outline (the default color is Color.White)</description></item>
960 /// <item><term>width (float)</term><description>The width in pixels of the outline (If not provided then the outline is not enabled)</description></item>
963 /// <since_tizen> 3 </since_tizen>
964 [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1721: Property names should not match get methods")]
965 public PropertyMap Outline
969 return (PropertyMap)GetValue(OutlineProperty);
973 SetValue(OutlineProperty, value);
974 NotifyPropertyChanged();
979 /// Set Outline to TextLabel. <br />
981 /// <param name="outline">The Outline</param>
983 /// SetOutline specifies the outline of the text through <see cref="Tizen.NUI.Text.Outline"/>. <br />
986 /// The following example demonstrates how to use the SetOutline method.
988 /// var outline = new Tizen.NUI.Text.Outline();
989 /// outline.Width = 2.0f;
990 /// outline.Color = new Color("#45B39D");
991 /// label.SetOutline(outline);
994 [EditorBrowsable(EditorBrowsableState.Never)]
995 public void SetOutline(Outline outline)
997 using (var outlineMap = TextMapHelper.GetOutlineMap(outline))
999 SetValue(OutlineProperty, outlineMap);
1004 /// Get Outline from TextLabel. <br />
1006 /// <returns>The Outline</returns>
1008 /// <see cref="Tizen.NUI.Text.Outline"/>
1010 [EditorBrowsable(EditorBrowsableState.Never)]
1011 public Outline GetOutline()
1014 using (var outlineMap = (PropertyMap)GetValue(OutlineProperty))
1016 outline = TextMapHelper.GetOutlineStruct(outlineMap);
1022 /// The PixelSize property.<br />
1023 /// The size of font in pixels.<br />
1025 /// <since_tizen> 3 </since_tizen>
1026 public float PixelSize
1030 return (float)GetValue(PixelSizeProperty);
1034 SetValue(PixelSizeProperty, value);
1035 NotifyPropertyChanged();
1040 /// The Ellipsis property.<br />
1041 /// Enable or disable the ellipsis.<br />
1043 /// <since_tizen> 3 </since_tizen>
1044 public bool Ellipsis
1048 return (bool)GetValue(EllipsisProperty);
1052 SetValue(EllipsisProperty, value);
1053 NotifyPropertyChanged();
1058 /// The ellipsis position of the text.
1059 /// Specifies which portion of the text should be replaced with an ellipsis when the text size exceeds the layout size.<br />
1061 /// <since_tizen> 9 </since_tizen>
1062 public EllipsisPosition EllipsisPosition
1066 return (EllipsisPosition)GetValue(EllipsisPositionProperty);
1070 SetValue(EllipsisPositionProperty, value);
1071 NotifyPropertyChanged();
1076 /// The AutoScrollLoopDelay property.<br />
1077 /// The amount of time to delay the starting time of auto scrolling and further loops.<br />
1079 /// <since_tizen> 3 </since_tizen>
1080 public float AutoScrollLoopDelay
1084 return (float)GetValue(AutoScrollLoopDelayProperty);
1088 SetValue(AutoScrollLoopDelayProperty, value);
1089 NotifyPropertyChanged();
1094 /// The AutoScrollStopMode property.<br />
1095 /// The auto scrolling stop behaviour.<br />
1096 /// The default value is AutoScrollStopMode.FinishLoop. <br />
1098 /// <since_tizen> 3 </since_tizen>
1099 public AutoScrollStopMode AutoScrollStopMode
1103 return (AutoScrollStopMode)GetValue(AutoScrollStopModeProperty);
1107 SetValue(AutoScrollStopModeProperty, value);
1108 NotifyPropertyChanged();
1113 /// The line count of the text.
1115 /// <since_tizen> 3 </since_tizen>
1116 public int LineCount
1121 using (var propertyValue = GetProperty(TextLabel.Property.LineCount))
1123 propertyValue.Get(out lineCount);
1130 /// The LineWrapMode property.<br />
1131 /// line wrap mode when the text lines over layout width.<br />
1133 /// <since_tizen> 4 </since_tizen>
1134 public LineWrapMode LineWrapMode
1138 return (LineWrapMode)GetValue(LineWrapModeProperty);
1142 SetValue(LineWrapModeProperty, value);
1143 NotifyPropertyChanged();
1148 /// The direction of the text such as left to right or right to left.
1150 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
1151 [EditorBrowsable(EditorBrowsableState.Never)]
1152 public TextDirection TextDirection
1156 int textDirection = 0;
1157 using (var propertyValue = GetProperty(TextLabel.Property.TextDirection))
1159 propertyValue.Get(out textDirection);
1161 return (TextDirection)textDirection;
1166 /// The vertical line alignment of the text.
1168 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
1169 [EditorBrowsable(EditorBrowsableState.Never)]
1170 public VerticalLineAlignment VerticalLineAlignment
1174 return (VerticalLineAlignment)GetValue(VerticalLineAlignmentProperty);
1178 SetValue(VerticalLineAlignmentProperty, value);
1179 NotifyPropertyChanged();
1184 /// The text alignment to match the direction of the system language.
1186 /// <since_tizen> 6 </since_tizen>
1187 public bool MatchSystemLanguageDirection
1191 return (bool)GetValue(MatchSystemLanguageDirectionProperty);
1195 SetValue(MatchSystemLanguageDirectionProperty, value);
1196 NotifyPropertyChanged();
1201 /// The text fit parameters.<br />
1202 /// The textFit map contains the following keys :<br />
1203 /// <list type="table">
1204 /// <item><term>enable (bool)</term><description>True to enable the text fit or false to disable (the default value is false)</description></item>
1205 /// <item><term>minSize (float)</term><description>Minimum Size for text fit (the default value is 10.f)</description></item>
1206 /// <item><term>maxSize (float)</term><description>Maximum Size for text fit (the default value is 100.f)</description></item>
1207 /// <item><term>stepSize (float)</term><description>Step Size for font increase (the default value is 1.f)</description></item>
1208 /// <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>
1211 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
1212 [EditorBrowsable(EditorBrowsableState.Never)]
1213 [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1721: Property names should not match get methods")]
1214 public PropertyMap TextFit
1218 return (PropertyMap)GetValue(TextFitProperty);
1222 SetValue(TextFitProperty, value);
1223 NotifyPropertyChanged();
1228 /// Set TextFit to TextLabel. <br />
1230 /// <param name="textFit">The TextFit</param>
1232 /// SetTextFit specifies the textFit of the text through <see cref="Tizen.NUI.Text.TextFit"/>. <br />
1235 /// The following example demonstrates how to use the SetTextFit method.
1237 /// var textFit = new Tizen.NUI.Text.TextFit();
1238 /// textFit.Enable = true;
1239 /// textFit.MinSize = 10.0f;
1240 /// textFit.MaxSize = 100.0f;
1241 /// textFit.StepSize = 5.0f;
1242 /// textFit.FontSizeType = FontSizeType.PointSize;
1243 /// label.SetTextFit(textFit);
1246 [EditorBrowsable(EditorBrowsableState.Never)]
1247 public void SetTextFit(TextFit textFit)
1249 using (var textFitMap = TextMapHelper.GetTextFitMap(textFit))
1251 SetValue(TextFitProperty, textFitMap);
1256 /// Get TextFit from TextLabel. <br />
1258 /// <returns>The TextFit</returns>
1260 /// TextFit is always returned based on PointSize. <br />
1261 /// If the user sets FontSizeType to PixelSize, then MinSize, MaxSize, and StepSize are converted based on PointSize and returned. <br />
1262 /// <see cref="Tizen.NUI.Text.TextFit"/>
1264 [EditorBrowsable(EditorBrowsableState.Never)]
1265 public TextFit GetTextFit()
1268 using (var textFitMap = (PropertyMap)GetValue(TextFitProperty))
1270 textFit = TextMapHelper.GetTextFitStruct(textFitMap);
1276 /// The MinLineSize property.<br />
1277 /// The height of the line in points. <br />
1278 /// If the font size is larger than the line size, it works with the font size. <br />
1280 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
1281 [EditorBrowsable(EditorBrowsableState.Never)]
1282 public float MinLineSize
1286 return (float)GetValue(MinLineSizeProperty);
1290 SetValue(MinLineSizeProperty, value);
1291 NotifyPropertyChanged();
1296 /// The FontSizeScale property for scaling the specified font size up or down. <br />
1297 /// The default value is 1.0. <br />
1298 /// The given font size scale value is used for multiplying the specified font size before querying fonts. <br />
1299 /// If FontSizeScale.UseSystemSetting, will use the SystemSettings.FontSize internally. <br />
1301 /// <since_tizen> 9 </since_tizen>
1302 public float FontSizeScale
1306 return fontSizeScale;
1310 float newFontSizeScale;
1312 if (fontSizeScale == value) return;
1314 fontSizeScale = value;
1315 if (fontSizeScale == Tizen.NUI.FontSizeScale.UseSystemSetting)
1317 SystemSettingsFontSize systemSettingsFontSize;
1321 systemSettingsFontSize = SystemSettings.FontSize;
1325 Console.WriteLine("{0} Exception caught.", e);
1326 systemSettingsFontSize = SystemSettingsFontSize.Normal;
1328 newFontSizeScale = TextUtils.GetFontSizeScale(systemSettingsFontSize);
1329 addFontSizeChangedCallback();
1333 newFontSizeScale = fontSizeScale;
1334 removeFontSizeChangedCallback();
1337 SetValue(FontSizeScaleProperty, newFontSizeScale);
1338 NotifyPropertyChanged();
1343 /// The EnableFontSizeScale property.<br />
1344 /// Whether the font size scale is enabled. (The default value is true)
1346 [EditorBrowsable(EditorBrowsableState.Never)]
1347 public bool EnableFontSizeScale
1351 return (bool)GetValue(EnableFontSizeScaleProperty);
1355 SetValue(EnableFontSizeScaleProperty, value);
1356 NotifyPropertyChanged();
1360 private TextLabelSelectorData EnsureSelectorData() => selectorData ?? (selectorData = new TextLabelSelectorData());
1363 /// Downcasts a handle to textLabel handle
1365 /// <param name="handle"></param>
1366 /// <returns></returns>
1367 /// <exception cref="ArgumentNullException"> Thrown when handle is null. </exception>
1368 /// <since_tizen> 3 </since_tizen>
1369 /// Please do not use! this will be deprecated!
1370 /// Instead please use as keyword.
1371 [Obsolete("Please do not use! This will be deprecated! Please use as keyword instead! " +
1373 "BaseHandle handle = new TextLabel(\"Hello World!\"); " +
1374 "TextLabel label = handle as TextLabel")]
1375 [EditorBrowsable(EditorBrowsableState.Never)]
1376 public static TextLabel DownCast(BaseHandle handle)
1380 throw new ArgumentNullException(nameof(handle));
1382 TextLabel ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as TextLabel;
1383 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1388 [EditorBrowsable(EditorBrowsableState.Never)]
1389 protected override void Dispose(DisposeTypes type)
1396 if (systemlangTextFlag)
1398 SystemSettings.LocaleLanguageChanged -= SystemSettings_LocaleLanguageChanged;
1401 removeFontSizeChangedCallback();
1403 if (type == DisposeTypes.Explicit)
1406 //Release your own managed resources here.
1407 //You should release all of your own disposable objects here.
1408 selectorData?.Reset(this);
1413 if (textLabelTextFitChangedCallbackDelegate != null)
1415 TextFitChangedSignal().Disconnect(textLabelTextFitChangedCallbackDelegate);
1422 /// This will not be public opened.
1423 [EditorBrowsable(EditorBrowsableState.Never)]
1424 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
1426 Interop.TextLabel.DeleteTextLabel(swigCPtr);
1430 /// Get attribues, it is abstract function and must be override.
1432 [EditorBrowsable(EditorBrowsableState.Never)]
1433 protected override ViewStyle CreateViewStyle()
1435 return new TextLabelStyle();
1438 internal override LayoutItem CreateDefaultLayout()
1440 return new TextLayout();
1444 /// Invoked whenever the binding context of the textlabel changes. Implement this method to add class handling for this event.
1446 protected override void OnBindingContextChanged()
1448 base.OnBindingContextChanged();
1451 private void SystemSettings_LocaleLanguageChanged(object sender, LocaleLanguageChangedEventArgs e)
1453 Text = NUIApplication.MultilingualResourceManager?.GetString(textLabelSid, new CultureInfo(e.Value.Replace("_", "-")));
1456 private void SystemSettingsFontSizeChanged(object sender, FontSizeChangedEventArgs e)
1458 float newFontSizeScale = TextUtils.GetFontSizeScale(e.Value);
1459 SetValue(FontSizeScaleProperty, newFontSizeScale);
1462 private void addFontSizeChangedCallback()
1464 if (hasFontSizeChangedCallback != true)
1468 SystemSettings.FontSizeChanged += SystemSettingsFontSizeChanged;
1469 hasFontSizeChangedCallback = true;
1473 Console.WriteLine("{0} Exception caught.", e);
1474 hasFontSizeChangedCallback = false;
1479 private void removeFontSizeChangedCallback()
1481 if (hasFontSizeChangedCallback == true)
1485 SystemSettings.FontSizeChanged -= SystemSettingsFontSizeChanged;
1486 hasFontSizeChangedCallback = false;
1490 Console.WriteLine("{0} Exception caught.", e);
1491 hasFontSizeChangedCallback = true;
1496 private void RequestLayout()
1498 Layout?.RequestLayout();
1501 internal new class Property
1503 internal static readonly int TEXT = Interop.TextLabel.TextGet();
1504 internal static readonly int FontFamily = Interop.TextLabel.FontFamilyGet();
1505 internal static readonly int FontStyle = Interop.TextLabel.FontStyleGet();
1506 internal static readonly int PointSize = Interop.TextLabel.PointSizeGet();
1507 internal static readonly int MultiLine = Interop.TextLabel.MultiLineGet();
1508 internal static readonly int HorizontalAlignment = Interop.TextLabel.HorizontalAlignmentGet();
1509 internal static readonly int VerticalAlignment = Interop.TextLabel.VerticalAlignmentGet();
1510 internal static readonly int TextColor = Interop.TextLabel.TextColorGet();
1511 internal static readonly int EnableMarkup = Interop.TextLabel.EnableMarkupGet();
1512 internal static readonly int EnableAutoScroll = Interop.TextLabel.EnableAutoScrollGet();
1513 internal static readonly int AutoScrollSpeed = Interop.TextLabel.AutoScrollSpeedGet();
1514 internal static readonly int AutoScrollLoopCount = Interop.TextLabel.AutoScrollLoopCountGet();
1515 internal static readonly int AutoScrollGap = Interop.TextLabel.AutoScrollGapGet();
1516 internal static readonly int LineSpacing = Interop.TextLabel.LineSpacingGet();
1517 internal static readonly int UNDERLINE = Interop.TextLabel.UnderlineGet();
1518 internal static readonly int SHADOW = Interop.TextLabel.ShadowGet();
1519 internal static readonly int EMBOSS = Interop.TextLabel.EmbossGet();
1520 internal static readonly int OUTLINE = Interop.TextLabel.OutlineGet();
1521 internal static readonly int PixelSize = Interop.TextLabel.PixelSizeGet();
1522 internal static readonly int ELLIPSIS = Interop.TextLabel.EllipsisGet();
1523 internal static readonly int AutoScrollStopMode = Interop.TextLabel.AutoScrollStopModeGet();
1524 internal static readonly int AutoScrollLoopDelay = Interop.TextLabel.AutoScrollLoopDelayGet();
1525 internal static readonly int LineCount = Interop.TextLabel.LineCountGet();
1526 internal static readonly int LineWrapMode = Interop.TextLabel.LineWrapModeGet();
1527 internal static readonly int TextDirection = Interop.TextLabel.TextDirectionGet();
1528 internal static readonly int VerticalLineAlignment = Interop.TextLabel.VerticalLineAlignmentGet();
1529 internal static readonly int MatchSystemLanguageDirection = Interop.TextLabel.MatchSystemLanguageDirectionGet();
1530 internal static readonly int TextFit = Interop.TextLabel.TextFitGet();
1531 internal static readonly int MinLineSize = Interop.TextLabel.MinLineSizeGet();
1532 internal static readonly int FontSizeScale = Interop.TextLabel.FontSizeScaleGet();
1533 internal static readonly int EnableFontSizeScale = Interop.TextLabel.EnableFontSizeScaleGet();
1534 internal static readonly int EllipsisPosition = Interop.TextLabel.EllipsisPositionGet();
1537 private void OnShadowColorChanged(float x, float y, float z, float w)
1539 ShadowColor = new Vector4(x, y, z, w);
1541 private void OnShadowOffsetChanged(float x, float y)
1543 ShadowOffset = new Vector2(x, y);
1545 private void OnTextColorChanged(float r, float g, float b, float a)
1547 TextColor = new Color(r, g, b, a);
1549 private void OnUnderlineColorChanged(float x, float y, float z, float w)
1551 UnderlineColor = new Vector4(x, y, z, w);