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 namespace Tizen.NUI.BaseComponents
28 /// A control which renders a short text string.<br />
29 /// Text labels are lightweight, non-editable, and do not respond to the user input.<br />
31 /// <since_tizen> 3 </since_tizen>
32 public partial class TextLabel : View
34 private class TextLayout : LayoutItem
36 protected override void OnMeasure(MeasureSpecification widthMeasureSpec, MeasureSpecification heightMeasureSpec)
38 // Padding will be automatically applied by DALi TextLabel.
39 float totalWidth = widthMeasureSpec.Size.AsDecimal();
40 float totalHeight = heightMeasureSpec.Size.AsDecimal();
42 if (widthMeasureSpec.Mode == MeasureSpecification.ModeType.Exactly)
44 if (heightMeasureSpec.Mode != MeasureSpecification.ModeType.Exactly)
46 totalHeight = Owner.GetHeightForWidth(totalWidth);
47 heightMeasureSpec = new MeasureSpecification(new LayoutLength(totalHeight), MeasureSpecification.ModeType.Exactly);
52 var minSize = Owner.MinimumSize;
53 var maxSize = Owner.MaximumSize;
54 var naturalSize = Owner.GetNaturalSize();
56 if (heightMeasureSpec.Mode == MeasureSpecification.ModeType.Exactly)
58 // GetWidthForHeight is not implemented.
59 totalWidth = Math.Min(Math.Max(naturalSize.Width, minSize.Width), (maxSize.Width < 0 ? Int32.MaxValue : maxSize.Width));
60 widthMeasureSpec = new MeasureSpecification(new LayoutLength(totalWidth), MeasureSpecification.ModeType.Exactly);
64 totalWidth = Math.Min(Math.Max(naturalSize.Width, minSize.Width), (maxSize.Width < 0 ? Int32.MaxValue : maxSize.Width));
65 totalHeight = Math.Min(Math.Max(naturalSize.Height, minSize.Height), (maxSize.Height < 0 ? Int32.MaxValue : maxSize.Height));
67 heightMeasureSpec = new MeasureSpecification(new LayoutLength(totalHeight), MeasureSpecification.ModeType.Exactly);
68 widthMeasureSpec = new MeasureSpecification(new LayoutLength(totalWidth), MeasureSpecification.ModeType.Exactly);
72 MeasuredSize.StateType childWidthState = MeasuredSize.StateType.MeasuredSizeOK;
73 MeasuredSize.StateType childHeightState = MeasuredSize.StateType.MeasuredSizeOK;
75 SetMeasuredDimensions(ResolveSizeAndState(new LayoutLength(totalWidth), widthMeasureSpec, childWidthState),
76 ResolveSizeAndState(new LayoutLength(totalHeight), heightMeasureSpec, childHeightState));
80 static TextLabel() { }
82 private string textLabelSid = null;
83 private bool systemlangTextFlag = false;
84 private TextLabelSelectorData selectorData;
85 private float fontSizeScale = 1.0f;
86 private bool hasFontSizeChangedCallback = false;
89 /// Creates the TextLabel control.
91 /// <since_tizen> 3 </since_tizen>
92 public TextLabel() : this(Interop.TextLabel.New(), true)
94 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
97 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
98 [EditorBrowsable(EditorBrowsableState.Never)]
99 public TextLabel(TextLabelStyle viewStyle) : this(Interop.TextLabel.New(), true, viewStyle)
104 /// Creates the TextLabel with setting the status of shown or hidden.
106 /// <param name="shown">false : Not displayed (hidden), true : displayed (shown)</param>
107 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
108 [EditorBrowsable(EditorBrowsableState.Never)]
109 public TextLabel(bool shown) : this(Interop.TextLabel.New(), true)
111 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
116 /// Creates the TextLabel control.
118 /// <param name="text">The text to display</param>
119 /// <since_tizen> 3 </since_tizen>
120 public TextLabel(string text) : this(Interop.TextLabel.New(text), true)
122 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
126 /// Creates the TextLabel with setting the status of shown or hidden.
128 /// <param name="text">The text to display</param>
129 /// <param name="shown">false : Not displayed (hidden), true : displayed (shown)</param>
130 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
131 [EditorBrowsable(EditorBrowsableState.Never)]
132 public TextLabel(string text, bool shown) : this(Interop.TextLabel.New(text), true)
134 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
138 internal TextLabel(TextLabel handle, bool shown = true) : this(Interop.TextLabel.NewTextLabel(TextLabel.getCPtr(handle)), true)
140 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
148 internal TextLabel(global::System.IntPtr cPtr, bool cMemoryOwn, ViewStyle viewStyle, bool shown = true) : base(cPtr, cMemoryOwn, viewStyle)
156 internal TextLabel(global::System.IntPtr cPtr, bool cMemoryOwn, bool shown = true) : base(cPtr, cMemoryOwn, null)
165 /// Create internal layout of TextLabel
167 internal LayoutItem CreateTextLayout()
169 return new TextLayout();
173 /// The TranslatableText property.<br />
174 /// The text can set the SID value.<br />
176 /// <exception cref='ArgumentNullException'>
177 /// ResourceManager about multilingual is null.
179 /// <since_tizen> 4 </since_tizen>
180 public string TranslatableText
184 return (string)GetValue(TranslatableTextProperty);
188 SetValue(TranslatableTextProperty, value);
189 selectorData?.TranslatableText?.Reset(this);
192 private string translatableText
200 if (NUIApplication.MultilingualResourceManager == null)
202 throw new ArgumentNullException(null, "ResourceManager about multilingual is null");
204 string translatableText = null;
205 textLabelSid = value;
206 translatableText = NUIApplication.MultilingualResourceManager?.GetString(textLabelSid, new CultureInfo(SystemSettings.LocaleLanguage.Replace("_", "-")));
207 if (translatableText != null)
209 Text = translatableText;
210 if (systemlangTextFlag == false)
212 SystemSettings.LocaleLanguageChanged += SystemSettings_LocaleLanguageChanged;
213 systemlangTextFlag = true;
220 NotifyPropertyChanged();
225 /// The Text property.<br />
226 /// The text to display in the UTF-8 format.<br />
228 /// <since_tizen> 3 </since_tizen>
233 return (string)GetValue(TextProperty);
237 SetValue(TextProperty, value);
238 selectorData?.Text?.Reset(this);
239 NotifyPropertyChangedAndRequestLayout();
244 /// The FontFamily property.<br />
245 /// The requested font family to use.<br />
247 /// <since_tizen> 3 </since_tizen>
248 public string FontFamily
252 return (string)GetValue(FontFamilyProperty);
256 SetValue(FontFamilyProperty, value);
257 selectorData?.FontFamily?.Reset(this);
258 NotifyPropertyChangedAndRequestLayout();
263 /// The FontStyle property.<br />
264 /// The requested font style to use.<br />
266 /// <since_tizen> 3 </since_tizen>
267 public PropertyMap FontStyle
271 return (PropertyMap)GetValue(FontStyleProperty);
275 SetValue(FontStyleProperty, value);
276 NotifyPropertyChangedAndRequestLayout();
281 /// The PointSize property.<br />
282 /// The size of font in points.<br />
284 /// <since_tizen> 3 </since_tizen>
285 public float PointSize
289 return (float)GetValue(PointSizeProperty);
293 SetValue(PointSizeProperty, value);
294 selectorData?.PointSize?.Reset(this);
295 NotifyPropertyChangedAndRequestLayout();
300 /// The MultiLine property.<br />
301 /// The single-line or multi-line layout option.<br />
303 /// <since_tizen> 3 </since_tizen>
304 public bool MultiLine
308 return (bool)GetValue(MultiLineProperty);
312 SetValue(MultiLineProperty, value);
313 NotifyPropertyChangedAndRequestLayout();
318 /// The HorizontalAlignment property.<br />
319 /// The line horizontal alignment.<br />
321 /// <since_tizen> 3 </since_tizen>
322 public HorizontalAlignment HorizontalAlignment
326 return (HorizontalAlignment)GetValue(HorizontalAlignmentProperty);
330 SetValue(HorizontalAlignmentProperty, value);
331 NotifyPropertyChanged();
336 /// The VerticalAlignment property.<br />
337 /// The line vertical alignment.<br />
339 /// <since_tizen> 3 </since_tizen>
340 public VerticalAlignment VerticalAlignment
344 return (VerticalAlignment)GetValue(VerticalAlignmentProperty);
348 SetValue(VerticalAlignmentProperty, value);
349 NotifyPropertyChanged();
354 /// The TextColor property.<br />
355 /// The color of the text.<br />
356 /// Animation framework can be used to change the color of the text when not using mark up.<br />
357 /// Cannot animate the color when text is auto scrolling.<br />
360 /// The property cascade chaining set is possible. For example, this (textLabel.TextColor.X = 0.1f;) is possible.
362 /// <since_tizen> 3 </since_tizen>
363 public Color TextColor
367 Color temp = (Color)GetValue(TextColorProperty);
368 return new Color(OnTextColorChanged, temp.R, temp.G, temp.B, temp.A);
372 SetValue(TextColorProperty, value);
373 selectorData?.TextColor?.Reset(this);
374 NotifyPropertyChanged();
379 /// The ShadowOffset property.<br />
380 /// The drop shadow offset 0 indicates no shadow.<br />
382 /// <since_tizen> 3 </since_tizen>
384 /// Deprecated.(API Level 6) Use Shadow instead.
385 /// The property cascade chaining set is possible. For example, this (textLabel.ShadowOffset.X = 0.1f;) is possible.
387 [Obsolete("Please do not use this ShadowOffset(Deprecated). Please use Shadow instead.")]
388 public Vector2 ShadowOffset
392 Vector2 shadowOffset = new Vector2();
393 Shadow.Find(TextLabel.Property.SHADOW, "offset")?.Get(shadowOffset);
394 return new Vector2(OnShadowOffsetChanged, shadowOffset.X, shadowOffset.Y);
398 PropertyMap temp = new PropertyMap();
399 temp.Insert("offset", new PropertyValue(value));
401 PropertyMap shadowMap = Shadow;
402 shadowMap.Merge(temp);
404 SetValue(ShadowProperty, shadowMap);
405 NotifyPropertyChanged();
410 /// The ShadowColor property.<br />
411 /// The color of a drop shadow.<br />
413 /// <since_tizen> 3 </since_tizen>
415 /// Deprecated.(API Level 6) Use Shadow instead.
416 /// The property cascade chaining set is possible. For example, this (textLabel.ShadowColor.X = 0.1f;) is possible.
418 [Obsolete("Please do not use this ShadowColor(Deprecated). Please use Shadow instead.")]
419 public Vector4 ShadowColor
423 Vector4 shadowColor = new Vector4();
424 Shadow.Find(TextLabel.Property.SHADOW, "color")?.Get(shadowColor);
425 return new Vector4(OnShadowColorChanged, shadowColor.X, shadowColor.Y, shadowColor.Z, shadowColor.W);
429 PropertyMap temp = new PropertyMap();
430 temp.Insert("color", new PropertyValue(value));
432 PropertyMap shadowMap = Shadow;
433 shadowMap.Merge(temp);
435 SetValue(ShadowProperty, shadowMap);
436 NotifyPropertyChanged();
441 /// The UnderlineEnabled property.<br />
442 /// The underline enabled flag.<br />
444 /// <since_tizen> 3 </since_tizen>
446 /// Deprecated.(API Level 6) Use Underline instead.
448 [Obsolete("Please do not use this UnderlineEnabled(Deprecated). Please use Underline instead.")]
449 public bool UnderlineEnabled
453 bool underlineEnabled = false;
454 Underline.Find(TextLabel.Property.UNDERLINE, "enable")?.Get(out underlineEnabled);
455 return underlineEnabled;
459 PropertyMap temp = new PropertyMap();
460 temp.Add("enable", new PropertyValue(value));
462 PropertyMap undelineMap = Underline;
463 undelineMap.Merge(temp);
465 SetValue(UnderlineProperty, undelineMap);
466 NotifyPropertyChanged();
472 /// The UnderlineColor property.<br />
473 /// Overrides the underline height from font metrics.<br />
475 /// <since_tizen> 3 </since_tizen>
477 /// Deprecated.(API Level 6) Use Underline instead.
478 /// The property cascade chaining set is possible. For example, this (textLabel.UnderlineColor.X = 0.1f;) is possible.
480 [Obsolete("Please do not use this UnderlineColor(Deprecated). Please use Underline instead.")]
481 public Vector4 UnderlineColor
485 Vector4 underlineColor = new Vector4();
486 Underline.Find(TextLabel.Property.UNDERLINE, "color")?.Get(underlineColor);
487 return new Vector4(OnUnderlineColorChanged, underlineColor.X, underlineColor.Y, underlineColor.Z, underlineColor.W);
491 PropertyMap temp = new PropertyMap();
492 temp.Insert("color", new PropertyValue(value));
494 PropertyMap undelineMap = Underline;
495 undelineMap.Merge(temp);
497 SetValue(UnderlineProperty, undelineMap);
498 NotifyPropertyChanged();
503 /// The UnderlineHeight property.<br />
504 /// Overrides the underline height from font metrics.<br />
506 /// <since_tizen> 3 </since_tizen>
508 /// Deprecated.(API Level 6) Use Underline instead.
510 [Obsolete("Please do not use this UnderlineHeight(Deprecated). Please use Underline instead.")]
511 public float UnderlineHeight
515 float underlineHeight = 0.0f;
516 Underline.Find(TextLabel.Property.UNDERLINE, "height")?.Get(out underlineHeight);
517 return underlineHeight;
521 PropertyMap temp = new PropertyMap();
522 temp.Insert("height", new PropertyValue(value));
524 PropertyMap undelineMap = Underline;
525 undelineMap.Merge(temp);
527 SetValue(UnderlineProperty, undelineMap);
528 NotifyPropertyChanged();
533 /// The EnableMarkup property.<br />
534 /// Whether the mark-up processing is enabled.<br />
536 /// <since_tizen> 3 </since_tizen>
537 public bool EnableMarkup
541 return (bool)GetValue(EnableMarkupProperty);
545 SetValue(EnableMarkupProperty, value);
546 NotifyPropertyChanged();
551 /// The EnableAutoScroll property.<br />
552 /// Starts or stops auto scrolling.<br />
554 /// <since_tizen> 3 </since_tizen>
555 public bool EnableAutoScroll
559 return (bool)GetValue(EnableAutoScrollProperty);
563 SetValue(EnableAutoScrollProperty, value);
564 NotifyPropertyChanged();
569 /// The AutoScrollSpeed property.<br />
570 /// Sets the speed of scrolling in pixels per second.<br />
572 /// <since_tizen> 3 </since_tizen>
573 public int AutoScrollSpeed
577 return (int)GetValue(AutoScrollSpeedProperty);
581 SetValue(AutoScrollSpeedProperty, value);
582 NotifyPropertyChanged();
587 /// The AutoScrollLoopCount property.<br />
588 /// Number of complete loops when scrolling enabled.<br />
590 /// <since_tizen> 3 </since_tizen>
591 public int AutoScrollLoopCount
595 return (int)GetValue(AutoScrollLoopCountProperty);
599 SetValue(AutoScrollLoopCountProperty, value);
600 NotifyPropertyChanged();
605 /// The AutoScrollGap property.<br />
606 /// Gap before scrolling wraps.<br />
608 /// <since_tizen> 3 </since_tizen>
609 public float AutoScrollGap
613 return (float)GetValue(AutoScrollGapProperty);
617 SetValue(AutoScrollGapProperty, value);
618 NotifyPropertyChanged();
623 /// The LineSpacing property.<br />
624 /// The default extra space between lines in points.<br />
626 /// <since_tizen> 3 </since_tizen>
627 public float LineSpacing
631 return (float)GetValue(LineSpacingProperty);
635 SetValue(LineSpacingProperty, value);
636 NotifyPropertyChangedAndRequestLayout();
641 /// The Underline property.<br />
642 /// The default underline parameters.<br />
644 /// <since_tizen> 3 </since_tizen>
645 public PropertyMap Underline
649 return (PropertyMap)GetValue(UnderlineProperty);
653 SetValue(UnderlineProperty, value);
654 NotifyPropertyChanged();
659 /// The Shadow property.<br />
660 /// The default shadow parameters.<br />
662 /// <since_tizen> 3 </since_tizen>
663 public PropertyMap Shadow
667 return (PropertyMap)GetValue(ShadowProperty);
671 SetValue(ShadowProperty, value);
672 NotifyPropertyChanged();
677 /// Describes a text shadow for a TextLabel.
678 /// It is null by default.
680 [EditorBrowsable(EditorBrowsableState.Never)]
681 public TextShadow TextShadow
685 return (TextShadow)GetValue(TextShadowProperty);
689 SetValue(TextShadowProperty, value);
690 selectorData?.TextShadow?.Reset(this);
691 NotifyPropertyChanged();
696 /// The Emboss property.<br />
697 /// The default emboss parameters.<br />
699 /// <since_tizen> 3 </since_tizen>
704 return (string)GetValue(EmbossProperty);
708 SetValue(EmbossProperty, value);
709 NotifyPropertyChanged();
714 /// The Outline property.<br />
715 /// The default outline parameters.<br />
717 /// <since_tizen> 3 </since_tizen>
718 public PropertyMap Outline
722 return (PropertyMap)GetValue(OutlineProperty);
726 SetValue(OutlineProperty, value);
727 NotifyPropertyChanged();
732 /// The PixelSize property.<br />
733 /// The size of font in pixels.<br />
735 /// <since_tizen> 3 </since_tizen>
736 public float PixelSize
740 return (float)GetValue(PixelSizeProperty);
744 SetValue(PixelSizeProperty, value);
745 selectorData?.PixelSize?.Reset(this);
746 NotifyPropertyChangedAndRequestLayout();
751 /// The Ellipsis property.<br />
752 /// Enable or disable the ellipsis.<br />
754 /// <since_tizen> 3 </since_tizen>
759 return (bool)GetValue(EllipsisProperty);
763 SetValue(EllipsisProperty, value);
764 NotifyPropertyChanged();
769 /// The AutoScrollLoopDelay property.<br />
770 /// Do something.<br />
772 /// <since_tizen> 3 </since_tizen>
773 public float AutoScrollLoopDelay
777 return (float)GetValue(AutoScrollLoopDelayProperty);
781 SetValue(AutoScrollLoopDelayProperty, value);
782 NotifyPropertyChanged();
787 /// The AutoScrollStopMode property.<br />
788 /// Do something.<br />
790 /// <since_tizen> 3 </since_tizen>
791 public AutoScrollStopMode AutoScrollStopMode
795 return (AutoScrollStopMode)GetValue(AutoScrollStopModeProperty);
799 SetValue(AutoScrollStopModeProperty, value);
800 NotifyPropertyChanged();
805 /// The line count of the text.
807 /// <since_tizen> 3 </since_tizen>
813 GetProperty(TextLabel.Property.LineCount).Get(out temp);
819 /// The LineWrapMode property.<br />
820 /// line wrap mode when the text lines over layout width.<br />
822 /// <since_tizen> 4 </since_tizen>
823 public LineWrapMode LineWrapMode
827 return (LineWrapMode)GetValue(LineWrapModeProperty);
831 SetValue(LineWrapModeProperty, value);
832 NotifyPropertyChanged();
837 /// The direction of the text such as left to right or right to left.
839 /// <since_tizen> 5 </since_tizen>
840 /// This will be released at Tizen.NET API Level 5, so currently this would be used as inhouse API.
841 [EditorBrowsable(EditorBrowsableState.Never)]
842 public TextDirection TextDirection
847 GetProperty(TextLabel.Property.TextDirection).Get(out temp);
848 return (TextDirection)temp;
853 /// The vertical line alignment of the text.
855 /// <since_tizen> 5 </since_tizen>
856 /// This will be released at Tizen.NET API Level 5, so currently this would be used as inhouse API.
857 [EditorBrowsable(EditorBrowsableState.Never)]
858 public VerticalLineAlignment VerticalLineAlignment
862 return (VerticalLineAlignment)GetValue(VerticalLineAlignmentProperty);
866 SetValue(VerticalLineAlignmentProperty, value);
867 NotifyPropertyChanged();
872 /// The text alignment to match the direction of the system language.
874 /// <since_tizen> 6 </since_tizen>
875 public bool MatchSystemLanguageDirection
879 return (bool)GetValue(MatchSystemLanguageDirectionProperty);
883 SetValue(MatchSystemLanguageDirectionProperty, value);
884 NotifyPropertyChanged();
889 /// The text fit parameters.<br />
890 /// The textFit map contains the following keys :<br />
891 /// - enable (bool type) : True to enable the text fit or false to disable(the default value is false)<br />
892 /// - minSize (float type) : Minimum Size for text fit(the default value is 10.f)<br />
893 /// - maxSize (float type) : Maximum Size for text fit(the default value is 100.f)<br />
894 /// - stepSize (float type) : Step Size for font increase(the default value is 1.f)<br />
895 /// - fontSize (string type) : The size type of font, You can choose between "pointSize" or "pixelSize". (the default value is "pointSize")<br />
897 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
898 [EditorBrowsable(EditorBrowsableState.Never)]
899 public PropertyMap TextFit
903 return (PropertyMap)GetValue(TextFitProperty);
907 SetValue(TextFitProperty, value);
908 NotifyPropertyChanged();
913 /// The MinLineSize property.<br />
915 /// <since_tizen> 8 </since_tizen>
916 [EditorBrowsable(EditorBrowsableState.Never)]
917 public float MinLineSize
921 return (float)GetValue(MinLineSizeProperty);
925 SetValue(MinLineSizeProperty, value);
926 NotifyPropertyChangedAndRequestLayout();
931 /// The FontSizeScale property. <br />
932 /// The default value is 1.0. <br />
933 /// If FontSizeScale.UseSystemSetting, will use the SystemSettings.FontSize internally. <br />
935 /// <since_tizen> 9 </since_tizen>
936 public float FontSizeScale
940 return fontSizeScale;
944 float newFontSizeScale;
946 if (fontSizeScale == value) return;
948 fontSizeScale = value;
949 if (fontSizeScale == Tizen.NUI.FontSizeScale.UseSystemSetting)
951 SystemSettingsFontSize systemSettingsFontSize;
955 systemSettingsFontSize = SystemSettings.FontSize;
959 Console.WriteLine("{0} Exception caught.", e);
960 systemSettingsFontSize = SystemSettingsFontSize.Normal;
962 newFontSizeScale = TextUtils.GetFontSizeScale(systemSettingsFontSize);
963 addFontSizeChangedCallback();
967 newFontSizeScale = fontSizeScale;
968 removeFontSizeChangedCallback();
971 SetValue(FontSizeScaleProperty, newFontSizeScale);
972 NotifyPropertyChangedAndRequestLayout();
976 private TextLabelSelectorData EnsureSelectorData() => selectorData ?? (selectorData = new TextLabelSelectorData());
979 /// Downcasts a handle to textLabel handle
981 /// <param name="handle"></param>
982 /// <returns></returns>
983 /// <exception cref="ArgumentNullException"> Thrown when handle is null. </exception>
984 /// <since_tizen> 3 </since_tizen>
985 /// Please do not use! this will be deprecated!
986 /// Instead please use as keyword.
987 [Obsolete("Please do not use! This will be deprecated! Please use as keyword instead! " +
989 "BaseHandle handle = new TextLabel(\"Hello World!\"); " +
990 "TextLabel label = handle as TextLabel")]
991 [EditorBrowsable(EditorBrowsableState.Never)]
992 public static TextLabel DownCast(BaseHandle handle)
996 throw new ArgumentNullException(nameof(handle));
998 TextLabel ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as TextLabel;
999 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1004 [EditorBrowsable(EditorBrowsableState.Never)]
1005 protected override void Dispose(DisposeTypes type)
1012 if (systemlangTextFlag)
1014 SystemSettings.LocaleLanguageChanged -= SystemSettings_LocaleLanguageChanged;
1017 removeFontSizeChangedCallback();
1019 if (type == DisposeTypes.Explicit)
1022 //Release your own managed resources here.
1023 //You should release all of your own disposable objects here.
1024 selectorData?.Reset(this);
1030 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(TextLabel obj)
1032 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.SwigCPtr;
1035 /// This will not be public opened.
1036 [EditorBrowsable(EditorBrowsableState.Never)]
1037 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
1039 Interop.TextLabel.DeleteTextLabel(swigCPtr);
1043 /// Get attribues, it is abstract function and must be override.
1045 [EditorBrowsable(EditorBrowsableState.Never)]
1046 protected override ViewStyle CreateViewStyle()
1048 return new TextLabelStyle();
1052 /// Invoked whenever the binding context of the textlabel changes. Implement this method to add class handling for this event.
1054 protected override void OnBindingContextChanged()
1056 base.OnBindingContextChanged();
1059 private void SystemSettings_LocaleLanguageChanged(object sender, LocaleLanguageChangedEventArgs e)
1061 Text = NUIApplication.MultilingualResourceManager?.GetString(textLabelSid, new CultureInfo(e.Value.Replace("_", "-")));
1064 private void SystemSettingsFontSizeChanged(object sender, FontSizeChangedEventArgs e)
1066 float newFontSizeScale = TextUtils.GetFontSizeScale(e.Value);
1067 SetValue(FontSizeScaleProperty, newFontSizeScale);
1068 NotifyPropertyChangedAndRequestLayout();
1071 private void addFontSizeChangedCallback()
1073 if (hasFontSizeChangedCallback != true)
1077 SystemSettings.FontSizeChanged += SystemSettingsFontSizeChanged;
1078 hasFontSizeChangedCallback = true;
1082 Console.WriteLine("{0} Exception caught.", e);
1083 hasFontSizeChangedCallback = false;
1088 private void removeFontSizeChangedCallback()
1090 if (hasFontSizeChangedCallback == true)
1094 SystemSettings.FontSizeChanged -= SystemSettingsFontSizeChanged;
1095 hasFontSizeChangedCallback = false;
1099 Console.WriteLine("{0} Exception caught.", e);
1100 hasFontSizeChangedCallback = true;
1105 private void NotifyPropertyChangedAndRequestLayout()
1107 NotifyPropertyChanged();
1108 Layout?.RequestLayout();
1111 internal new class Property
1113 internal static readonly int TEXT = Interop.TextLabel.TextGet();
1114 internal static readonly int FontFamily = Interop.TextLabel.FontFamilyGet();
1115 internal static readonly int FontStyle = Interop.TextLabel.FontStyleGet();
1116 internal static readonly int PointSize = Interop.TextLabel.PointSizeGet();
1117 internal static readonly int MultiLine = Interop.TextLabel.MultiLineGet();
1118 internal static readonly int HorizontalAlignment = Interop.TextLabel.HorizontalAlignmentGet();
1119 internal static readonly int VerticalAlignment = Interop.TextLabel.VerticalAlignmentGet();
1120 internal static readonly int TextColor = Interop.TextLabel.TextColorGet();
1121 internal static readonly int EnableMarkup = Interop.TextLabel.EnableMarkupGet();
1122 internal static readonly int EnableAutoScroll = Interop.TextLabel.EnableAutoScrollGet();
1123 internal static readonly int AutoScrollSpeed = Interop.TextLabel.AutoScrollSpeedGet();
1124 internal static readonly int AutoScrollLoopCount = Interop.TextLabel.AutoScrollLoopCountGet();
1125 internal static readonly int AutoScrollGap = Interop.TextLabel.AutoScrollGapGet();
1126 internal static readonly int LineSpacing = Interop.TextLabel.LineSpacingGet();
1127 internal static readonly int UNDERLINE = Interop.TextLabel.UnderlineGet();
1128 internal static readonly int SHADOW = Interop.TextLabel.ShadowGet();
1129 internal static readonly int EMBOSS = Interop.TextLabel.EmbossGet();
1130 internal static readonly int OUTLINE = Interop.TextLabel.OutlineGet();
1131 internal static readonly int PixelSize = Interop.TextLabel.PixelSizeGet();
1132 internal static readonly int ELLIPSIS = Interop.TextLabel.EllipsisGet();
1133 internal static readonly int AutoScrollStopMode = Interop.TextLabel.AutoScrollStopModeGet();
1134 internal static readonly int AutoScrollLoopDelay = Interop.TextLabel.AutoScrollLoopDelayGet();
1135 internal static readonly int LineCount = Interop.TextLabel.LineCountGet();
1136 internal static readonly int LineWrapMode = Interop.TextLabel.LineWrapModeGet();
1137 internal static readonly int TextDirection = Interop.TextLabel.TextDirectionGet();
1138 internal static readonly int VerticalLineAlignment = Interop.TextLabel.VerticalLineAlignmentGet();
1139 internal static readonly int MatchSystemLanguageDirection = Interop.TextLabel.MatchSystemLanguageDirectionGet();
1140 internal static readonly int TextFit = Interop.TextLabel.TextFitGet();
1141 internal static readonly int MinLineSize = Interop.TextLabel.MinLineSizeGet();
1142 internal static readonly int FontSizeScale = Interop.TextLabel.FontSizeScaleGet();
1145 private void OnShadowColorChanged(float x, float y, float z, float w)
1147 ShadowColor = new Vector4(x, y, z, w);
1149 private void OnShadowOffsetChanged(float x, float y)
1151 ShadowOffset = new Vector2(x, y);
1153 private void OnTextColorChanged(float r, float g, float b, float a)
1155 TextColor = new Color(r, g, b, a);
1157 private void OnUnderlineColorChanged(float x, float y, float z, float w)
1159 UnderlineColor = new Vector4(x, y, z, w);