2 * Copyright(c) 2017 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;
21 using System.Globalization;
22 using System.ComponentModel;
23 namespace Tizen.NUI.BaseComponents
27 /// A control which renders a short text string.<br />
28 /// Text labels are lightweight, non-editable, and do not respond to the user input.<br />
30 /// <since_tizen> 3 </since_tizen>
31 public class TextLabel : View
33 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
34 private string textLabelSid = null;
35 private bool systemlangTextFlag = false;
36 internal TextLabel(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.TextLabel_SWIGUpcast(cPtr), cMemoryOwn)
38 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
41 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(TextLabel obj)
43 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
47 /// Downcasts a handle to textLabel handle
49 /// <param name="handle"></param>
50 /// <returns></returns>
51 /// <since_tizen> 3 </since_tizen>
52 /// Please do not use! this will be deprecated!
53 /// Instead please use as keyword.
54 [Obsolete("Please do not use! This will be deprecated! Please use as keyword instead! " +
56 "BaseHandle handle = new TextLabel(\"Hello World!\"); " +
57 "TextLabel label = handle as TextLabel")]
58 [EditorBrowsable(EditorBrowsableState.Never)]
59 public static TextLabel DownCast(BaseHandle handle)
61 TextLabel ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as TextLabel;
63 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
70 /// <since_tizen> 3 </since_tizen>
71 protected override void Dispose(DisposeTypes type)
78 if(type == DisposeTypes.Explicit)
81 //Release your own managed resources here.
82 //You should release all of your own disposable objects here.
85 //Release your own unmanaged resources here.
86 //You should not access any managed member here except static instance.
87 //because the execution order of Finalizes is non-deterministic.
89 if (swigCPtr.Handle != global::System.IntPtr.Zero)
94 NDalicPINVOKE.delete_TextLabel(swigCPtr);
96 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
102 internal new class Property
104 internal static readonly int RENDERING_BACKEND = NDalicPINVOKE.TextLabel_Property_RENDERING_BACKEND_get();
105 internal static readonly int TEXT = NDalicPINVOKE.TextLabel_Property_TEXT_get();
106 internal static readonly int FONT_FAMILY = NDalicPINVOKE.TextLabel_Property_FONT_FAMILY_get();
107 internal static readonly int FONT_STYLE = NDalicPINVOKE.TextLabel_Property_FONT_STYLE_get();
108 internal static readonly int POINT_SIZE = NDalicPINVOKE.TextLabel_Property_POINT_SIZE_get();
109 internal static readonly int MULTI_LINE = NDalicPINVOKE.TextLabel_Property_MULTI_LINE_get();
110 internal static readonly int HORIZONTAL_ALIGNMENT = NDalicPINVOKE.TextLabel_Property_HORIZONTAL_ALIGNMENT_get();
111 internal static readonly int VERTICAL_ALIGNMENT = NDalicPINVOKE.TextLabel_Property_VERTICAL_ALIGNMENT_get();
112 internal static readonly int TEXT_COLOR = NDalicPINVOKE.TextLabel_Property_TEXT_COLOR_get();
113 internal static readonly int SHADOW_OFFSET = NDalicPINVOKE.TextLabel_Property_SHADOW_OFFSET_get();
114 internal static readonly int SHADOW_COLOR = NDalicPINVOKE.TextLabel_Property_SHADOW_COLOR_get();
115 internal static readonly int UNDERLINE_ENABLED = NDalicPINVOKE.TextLabel_Property_UNDERLINE_ENABLED_get();
116 internal static readonly int UNDERLINE_COLOR = NDalicPINVOKE.TextLabel_Property_UNDERLINE_COLOR_get();
117 internal static readonly int UNDERLINE_HEIGHT = NDalicPINVOKE.TextLabel_Property_UNDERLINE_HEIGHT_get();
118 internal static readonly int ENABLE_MARKUP = NDalicPINVOKE.TextLabel_Property_ENABLE_MARKUP_get();
119 internal static readonly int ENABLE_AUTO_SCROLL = NDalicPINVOKE.TextLabel_Property_ENABLE_AUTO_SCROLL_get();
120 internal static readonly int AUTO_SCROLL_SPEED = NDalicPINVOKE.TextLabel_Property_AUTO_SCROLL_SPEED_get();
121 internal static readonly int AUTO_SCROLL_LOOP_COUNT = NDalicPINVOKE.TextLabel_Property_AUTO_SCROLL_LOOP_COUNT_get();
122 internal static readonly int AUTO_SCROLL_GAP = NDalicPINVOKE.TextLabel_Property_AUTO_SCROLL_GAP_get();
123 internal static readonly int LINE_SPACING = NDalicPINVOKE.TextLabel_Property_LINE_SPACING_get();
124 internal static readonly int UNDERLINE = NDalicPINVOKE.TextLabel_Property_UNDERLINE_get();
125 internal static readonly int SHADOW = NDalicPINVOKE.TextLabel_Property_SHADOW_get();
126 internal static readonly int EMBOSS = NDalicPINVOKE.TextLabel_Property_EMBOSS_get();
127 internal static readonly int OUTLINE = NDalicPINVOKE.TextLabel_Property_OUTLINE_get();
128 internal static readonly int PIXEL_SIZE = NDalicManualPINVOKE.TextLabel_Property_PIXEL_SIZE_get();
129 internal static readonly int ELLIPSIS = NDalicManualPINVOKE.TextLabel_Property_ELLIPSIS_get();
130 internal static readonly int AUTO_SCROLL_STOP_MODE = NDalicManualPINVOKE.TextLabel_Property_AUTO_SCROLL_STOP_MODE_get();
131 internal static readonly int AUTO_SCROLL_LOOP_DELAY = NDalicManualPINVOKE.TextLabel_Property_AUTO_SCROLL_LOOP_DELAY_get();
132 internal static readonly int LINE_COUNT = NDalicManualPINVOKE.TextLabel_Property_LINE_COUNT_get();
133 internal static readonly int LINE_WRAP_MODE = NDalicManualPINVOKE.TextLabel_Property_LINE_WRAP_MODE_get();
134 internal static readonly int TEXT_DIRECTION = NDalicManualPINVOKE.TextLabel_Property_TEXT_DIRECTION_get();
135 internal static readonly int VERTICAL_LINE_ALIGNMENT = NDalicManualPINVOKE.TextLabel_Property_VERTICAL_LINE_ALIGNMENT_get();
139 /// Creates the TextLabel control.
141 /// <since_tizen> 3 </since_tizen>
142 public TextLabel() : this(NDalicPINVOKE.TextLabel_New__SWIG_0(), true)
144 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
149 /// Creates the TextLabel control.
151 /// <param name="text">The text to display</param>
152 /// <since_tizen> 3 </since_tizen>
153 public TextLabel(string text) : this(NDalicPINVOKE.TextLabel_New__SWIG_1(text), true)
155 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
158 internal TextLabel(TextLabel handle) : this(NDalicPINVOKE.new_TextLabel__SWIG_1(TextLabel.getCPtr(handle)), true)
160 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
164 /// The TranslatableText property.<br />
165 /// The text can set the SID value.<br />
167 /// <exception cref='ArgumentNullException'>
168 /// ResourceManager about multilingual is null.
170 /// <since_tizen> 4 </since_tizen>
171 public string TranslatableText
179 if (NUIApplication.MultilingualResourceManager == null)
181 throw new ArgumentNullException("ResourceManager about multilingual is null");
183 string translatableText = null;
184 textLabelSid = value;
185 translatableText = NUIApplication.MultilingualResourceManager?.GetString(textLabelSid, new CultureInfo(SystemSettings.LocaleLanguage.Replace("_", "-")));
186 if (translatableText != null)
188 Text = translatableText;
189 if (systemlangTextFlag == false)
191 SystemSettings.LocaleLanguageChanged += new WeakEventHandler<LocaleLanguageChangedEventArgs>(SystemSettings_LocaleLanguageChanged).Handler;
192 systemlangTextFlag = true;
199 NotifyPropertyChanged();
202 private void SystemSettings_LocaleLanguageChanged(object sender, LocaleLanguageChangedEventArgs e)
204 Text = NUIApplication.MultilingualResourceManager?.GetString(textLabelSid, new CultureInfo(e.Value.Replace("_", "-")));
208 /// The Text property.<br />
209 /// The text to display in the UTF-8 format.<br />
211 /// <since_tizen> 3 </since_tizen>
217 GetProperty(TextLabel.Property.TEXT).Get(out temp);
222 SetProperty(TextLabel.Property.TEXT, new Tizen.NUI.PropertyValue(value));
223 NotifyPropertyChanged();
228 /// The FontFamily property.<br />
229 /// The requested font family to use.<br />
231 /// <since_tizen> 3 </since_tizen>
232 public string FontFamily
237 GetProperty(TextLabel.Property.FONT_FAMILY).Get(out temp);
242 SetProperty(TextLabel.Property.FONT_FAMILY, new Tizen.NUI.PropertyValue(value));
243 NotifyPropertyChanged();
248 /// The FontStyle property.<br />
249 /// The requested font style to use.<br />
251 /// <since_tizen> 3 </since_tizen>
252 public PropertyMap FontStyle
256 PropertyMap temp = new PropertyMap();
257 GetProperty(TextLabel.Property.FONT_STYLE).Get(temp);
262 SetProperty(TextLabel.Property.FONT_STYLE, new Tizen.NUI.PropertyValue(value));
263 NotifyPropertyChanged();
268 /// The PointSize property.<br />
269 /// The size of font in points.<br />
271 /// <since_tizen> 3 </since_tizen>
272 public float PointSize
277 GetProperty(TextLabel.Property.POINT_SIZE).Get(out temp);
282 SetProperty(TextLabel.Property.POINT_SIZE, new Tizen.NUI.PropertyValue(value));
283 NotifyPropertyChanged();
288 /// The MultiLine property.<br />
289 /// The single-line or multi-line layout option.<br />
291 /// <since_tizen> 3 </since_tizen>
292 public bool MultiLine
297 GetProperty(TextLabel.Property.MULTI_LINE).Get(out temp);
302 SetProperty(TextLabel.Property.MULTI_LINE, new Tizen.NUI.PropertyValue(value));
303 NotifyPropertyChanged();
308 /// The HorizontalAlignment property.<br />
309 /// The line horizontal alignment.<br />
311 /// <since_tizen> 3 </since_tizen>
312 public HorizontalAlignment HorizontalAlignment
317 if (GetProperty(TextLabel.Property.HORIZONTAL_ALIGNMENT).Get(out temp) == false)
319 NUILog.Error("HorizontalAlignment get error!");
324 return HorizontalAlignment.Begin;
326 return HorizontalAlignment.Center;
328 return HorizontalAlignment.End;
330 return HorizontalAlignment.Begin;
335 string valueToString = "";
338 case HorizontalAlignment.Begin:
340 valueToString = "BEGIN";
343 case HorizontalAlignment.Center:
345 valueToString = "CENTER";
348 case HorizontalAlignment.End:
350 valueToString = "END";
355 valueToString = "BEGIN";
359 SetProperty(TextLabel.Property.HORIZONTAL_ALIGNMENT, new Tizen.NUI.PropertyValue(valueToString));
360 NotifyPropertyChanged();
365 /// The VerticalAlignment property.<br />
366 /// The line vertical alignment.<br />
368 /// <since_tizen> 3 </since_tizen>
369 public VerticalAlignment VerticalAlignment
374 if (GetProperty(TextLabel.Property.VERTICAL_ALIGNMENT).Get(out temp) == false)
376 NUILog.Error("VerticalAlignment get error!");
382 return VerticalAlignment.Top;
384 return VerticalAlignment.Center;
386 return VerticalAlignment.Bottom;
388 return VerticalAlignment.Bottom;
393 string valueToString = "";
396 case VerticalAlignment.Top:
398 valueToString = "TOP";
401 case VerticalAlignment.Center:
403 valueToString = "CENTER";
406 case VerticalAlignment.Bottom:
408 valueToString = "BOTTOM";
413 valueToString = "BOTTOM";
417 SetProperty(TextLabel.Property.VERTICAL_ALIGNMENT, new Tizen.NUI.PropertyValue(valueToString));
418 NotifyPropertyChanged();
423 /// The TextColor property.<br />
424 /// The color of the text.<br />
425 /// Animation framework can be used to change the color of the text when not using mark up.<br />
426 /// Cannot animate the color when text is auto scrolling.<br />
428 /// <since_tizen> 3 </since_tizen>
429 public Color TextColor
433 Color temp = new Color(0.0f, 0.0f, 0.0f, 0.0f);
434 GetProperty(TextLabel.Property.TEXT_COLOR).Get(temp);
439 SetProperty(TextLabel.Property.TEXT_COLOR, new Tizen.NUI.PropertyValue(value));
440 NotifyPropertyChanged();
445 /// The ShadowOffset property.<br />
446 /// The drop shadow offset 0 indicates no shadow.<br />
448 /// <since_tizen> 3 </since_tizen>
449 public Vector2 ShadowOffset
453 Vector2 temp = new Vector2(0.0f, 0.0f);
454 GetProperty(TextLabel.Property.SHADOW_OFFSET).Get(temp);
459 SetProperty(TextLabel.Property.SHADOW_OFFSET, new Tizen.NUI.PropertyValue(value));
460 NotifyPropertyChanged();
465 /// The ShadowColor property.<br />
466 /// The color of a drop shadow.<br />
468 /// <since_tizen> 3 </since_tizen>
469 public Vector4 ShadowColor
473 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
474 GetProperty(TextLabel.Property.SHADOW_COLOR).Get(temp);
479 SetProperty(TextLabel.Property.SHADOW_COLOR, new Tizen.NUI.PropertyValue(value));
480 NotifyPropertyChanged();
485 /// The UnderlineEnabled property.<br />
486 /// The underline enabled flag.<br />
488 /// <since_tizen> 3 </since_tizen>
489 public bool UnderlineEnabled
494 GetProperty(TextLabel.Property.UNDERLINE_ENABLED).Get(out temp);
499 SetProperty(TextLabel.Property.UNDERLINE_ENABLED, new Tizen.NUI.PropertyValue(value));
500 NotifyPropertyChanged();
505 /// The UnderlineColor property.<br />
506 /// Overrides the underline height from font metrics.<br />
508 /// <since_tizen> 3 </since_tizen>
509 public Vector4 UnderlineColor
513 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
514 GetProperty(TextLabel.Property.UNDERLINE_COLOR).Get(temp);
519 SetProperty(TextLabel.Property.UNDERLINE_COLOR, new Tizen.NUI.PropertyValue(value));
520 NotifyPropertyChanged();
525 /// The UnderlineHeight property.<br />
526 /// Overrides the underline height from font metrics.<br />
528 /// <since_tizen> 3 </since_tizen>
529 public float UnderlineHeight
534 GetProperty(TextLabel.Property.UNDERLINE_HEIGHT).Get(out temp);
539 SetProperty(TextLabel.Property.UNDERLINE_HEIGHT, new Tizen.NUI.PropertyValue(value));
540 NotifyPropertyChanged();
545 /// The EnableMarkup property.<br />
546 /// Whether the mark-up processing is enabled.<br />
548 /// <since_tizen> 3 </since_tizen>
549 public bool EnableMarkup
554 GetProperty(TextLabel.Property.ENABLE_MARKUP).Get(out temp);
559 SetProperty(TextLabel.Property.ENABLE_MARKUP, new Tizen.NUI.PropertyValue(value));
560 NotifyPropertyChanged();
565 /// The EnableAutoScroll property.<br />
566 /// Starts or stops auto scrolling.<br />
568 /// <since_tizen> 3 </since_tizen>
569 public bool EnableAutoScroll
574 GetProperty(TextLabel.Property.ENABLE_AUTO_SCROLL).Get(out temp);
579 SetProperty(TextLabel.Property.ENABLE_AUTO_SCROLL, new Tizen.NUI.PropertyValue(value));
580 NotifyPropertyChanged();
585 /// The AutoScrollSpeed property.<br />
586 /// Sets the speed of scrolling in pixels per second.<br />
588 /// <since_tizen> 3 </since_tizen>
589 public int AutoScrollSpeed
594 GetProperty(TextLabel.Property.AUTO_SCROLL_SPEED).Get(out temp);
599 SetProperty(TextLabel.Property.AUTO_SCROLL_SPEED, new Tizen.NUI.PropertyValue(value));
600 NotifyPropertyChanged();
605 /// The AutoScrollLoopCount property.<br />
606 /// Number of complete loops when scrolling enabled.<br />
608 /// <since_tizen> 3 </since_tizen>
609 public int AutoScrollLoopCount
614 GetProperty(TextLabel.Property.AUTO_SCROLL_LOOP_COUNT).Get(out temp);
619 SetProperty(TextLabel.Property.AUTO_SCROLL_LOOP_COUNT, new Tizen.NUI.PropertyValue(value));
620 NotifyPropertyChanged();
625 /// The AutoScrollGap property.<br />
626 /// Gap before scrolling wraps.<br />
628 /// <since_tizen> 3 </since_tizen>
629 public float AutoScrollGap
634 GetProperty(TextLabel.Property.AUTO_SCROLL_GAP).Get(out temp);
639 SetProperty(TextLabel.Property.AUTO_SCROLL_GAP, new Tizen.NUI.PropertyValue(value));
640 NotifyPropertyChanged();
645 /// The LineSpacing property.<br />
646 /// The default extra space between lines in points.<br />
648 /// <since_tizen> 3 </since_tizen>
649 public float LineSpacing
654 GetProperty(TextLabel.Property.LINE_SPACING).Get(out temp);
659 SetProperty(TextLabel.Property.LINE_SPACING, new Tizen.NUI.PropertyValue(value));
660 NotifyPropertyChanged();
665 /// The Underline property.<br />
666 /// The default underline parameters.<br />
668 /// <since_tizen> 3 </since_tizen>
669 public PropertyMap Underline
673 PropertyMap temp = new PropertyMap();
674 GetProperty(TextLabel.Property.UNDERLINE).Get(temp);
679 SetProperty(TextLabel.Property.UNDERLINE, new Tizen.NUI.PropertyValue(value));
680 NotifyPropertyChanged();
685 /// The Shadow property.<br />
686 /// The default shadow parameters.<br />
688 /// <since_tizen> 3 </since_tizen>
689 public PropertyMap Shadow
693 PropertyMap temp = new PropertyMap();
694 GetProperty(TextLabel.Property.SHADOW).Get(temp);
699 SetProperty(TextLabel.Property.SHADOW, new Tizen.NUI.PropertyValue(value));
700 NotifyPropertyChanged();
705 /// The Emboss property.<br />
706 /// The default emboss parameters.<br />
708 /// <since_tizen> 3 </since_tizen>
714 GetProperty(TextLabel.Property.EMBOSS).Get( out temp);
719 SetProperty(TextLabel.Property.EMBOSS, new Tizen.NUI.PropertyValue(value));
720 NotifyPropertyChanged();
725 /// The Outline property.<br />
726 /// The default outline parameters.<br />
728 /// <since_tizen> 3 </since_tizen>
729 public PropertyMap Outline
733 PropertyMap temp = new PropertyMap();
734 GetProperty(TextLabel.Property.OUTLINE).Get(temp);
739 SetProperty(TextLabel.Property.OUTLINE, new Tizen.NUI.PropertyValue(value));
740 NotifyPropertyChanged();
745 /// The PixelSize property.<br />
746 /// The size of font in pixels.<br />
748 /// <since_tizen> 3 </since_tizen>
749 public float PixelSize
754 GetProperty(TextLabel.Property.PIXEL_SIZE).Get(out temp);
759 SetProperty(TextLabel.Property.PIXEL_SIZE, new Tizen.NUI.PropertyValue(value));
760 NotifyPropertyChanged();
765 /// The Ellipsis property.<br />
766 /// Enable or disable the ellipsis.<br />
768 /// <since_tizen> 3 </since_tizen>
774 GetProperty(TextLabel.Property.ELLIPSIS).Get(out temp);
779 SetProperty(TextLabel.Property.ELLIPSIS, new Tizen.NUI.PropertyValue(value));
780 NotifyPropertyChanged();
785 /// The AutoScrollLoopDelay property.<br />
786 /// Do something.<br />
788 /// <since_tizen> 3 </since_tizen>
789 public float AutoScrollLoopDelay
794 GetProperty(TextLabel.Property.AUTO_SCROLL_LOOP_DELAY).Get(out temp);
799 SetProperty(TextLabel.Property.AUTO_SCROLL_LOOP_DELAY, new Tizen.NUI.PropertyValue(value));
800 NotifyPropertyChanged();
805 /// The AutoScrollStopMode property.<br />
806 /// Do something.<br />
808 /// <since_tizen> 3 </since_tizen>
809 public AutoScrollStopMode AutoScrollStopMode
814 if(GetProperty(TextLabel.Property.AUTO_SCROLL_STOP_MODE).Get(out temp) == false)
816 NUILog.Error("AutoScrollStopMode get error!");
821 return AutoScrollStopMode.FinishLoop;
823 return AutoScrollStopMode.Immediate;
825 return AutoScrollStopMode.FinishLoop;
830 SetProperty(TextLabel.Property.AUTO_SCROLL_STOP_MODE, new Tizen.NUI.PropertyValue((int)value));
831 NotifyPropertyChanged();
836 /// The line count of the text.
838 /// <since_tizen> 3 </since_tizen>
844 GetProperty(TextLabel.Property.LINE_COUNT).Get(out temp);
850 /// The LineWrapMode property.<br />
851 /// line wrap mode when the text lines over layout width.<br />
853 /// <since_tizen> 4 </since_tizen>
854 public LineWrapMode LineWrapMode
859 if(GetProperty(TextLabel.Property.LINE_WRAP_MODE).Get(out temp) == false)
861 NUILog.Error("LineWrapMode get error!");
863 return (LineWrapMode)temp;
867 SetProperty(TextLabel.Property.LINE_WRAP_MODE, new Tizen.NUI.PropertyValue((int)value));
868 NotifyPropertyChanged();
873 /// The text direction.
875 /// <since_tizen> 5 </since_tizen>
876 public TextDirection TextDirection
881 GetProperty(TextLabel.Property.TEXT_DIRECTION).Get(out temp);
882 return (TextDirection)temp;
887 /// The text vertical line alignment.
889 /// <since_tizen> 5 </since_tizen>
890 public VerticalLineAlignment VerticalLineAlignment
895 GetProperty(TextLabel.Property.VERTICAL_LINE_ALIGNMENT).Get(out temp);
896 return (VerticalLineAlignment)temp;
900 SetProperty(TextLabel.Property.VERTICAL_LINE_ALIGNMENT, new Tizen.NUI.PropertyValue((int)value));
901 NotifyPropertyChanged();