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 new 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;
201 private void SystemSettings_LocaleLanguageChanged(object sender, LocaleLanguageChangedEventArgs e)
203 Text = NUIApplication.MultilingualResourceManager?.GetString(textLabelSid, new CultureInfo(e.Value.Replace("_", "-")));
207 /// The Text property.<br />
208 /// The text to display in the UTF-8 format.<br />
210 /// <since_tizen> 3 </since_tizen>
216 GetProperty(TextLabel.Property.TEXT).Get(out temp);
221 SetProperty(TextLabel.Property.TEXT, new Tizen.NUI.PropertyValue(value));
226 /// The FontFamily property.<br />
227 /// The requested font family to use.<br />
229 /// <since_tizen> 3 </since_tizen>
230 public string FontFamily
235 GetProperty(TextLabel.Property.FONT_FAMILY).Get(out temp);
240 SetProperty(TextLabel.Property.FONT_FAMILY, new Tizen.NUI.PropertyValue(value));
245 /// The FontStyle property.<br />
246 /// The requested font style to use.<br />
248 /// <since_tizen> 3 </since_tizen>
249 public PropertyMap FontStyle
253 PropertyMap temp = new PropertyMap();
254 GetProperty(TextLabel.Property.FONT_STYLE).Get(temp);
259 SetProperty(TextLabel.Property.FONT_STYLE, new Tizen.NUI.PropertyValue(value));
264 /// The PointSize property.<br />
265 /// The size of font in points.<br />
267 /// <since_tizen> 3 </since_tizen>
268 public float PointSize
273 GetProperty(TextLabel.Property.POINT_SIZE).Get(out temp);
278 SetProperty(TextLabel.Property.POINT_SIZE, new Tizen.NUI.PropertyValue(value));
283 /// The MultiLine property.<br />
284 /// The single-line or multi-line layout option.<br />
286 /// <since_tizen> 3 </since_tizen>
287 public bool MultiLine
292 GetProperty(TextLabel.Property.MULTI_LINE).Get(out temp);
297 SetProperty(TextLabel.Property.MULTI_LINE, new Tizen.NUI.PropertyValue(value));
302 /// The HorizontalAlignment property.<br />
303 /// The line horizontal alignment.<br />
305 /// <since_tizen> 3 </since_tizen>
306 public HorizontalAlignment HorizontalAlignment
311 if (GetProperty(TextLabel.Property.HORIZONTAL_ALIGNMENT).Get(out temp) == false)
313 NUILog.Error("HorizontalAlignment get error!");
318 return HorizontalAlignment.Begin;
320 return HorizontalAlignment.Center;
322 return HorizontalAlignment.End;
324 return HorizontalAlignment.Begin;
329 string valueToString = "";
332 case HorizontalAlignment.Begin:
334 valueToString = "BEGIN";
337 case HorizontalAlignment.Center:
339 valueToString = "CENTER";
342 case HorizontalAlignment.End:
344 valueToString = "END";
349 valueToString = "BEGIN";
353 SetProperty(TextLabel.Property.HORIZONTAL_ALIGNMENT, new Tizen.NUI.PropertyValue(valueToString));
358 /// The VerticalAlignment property.<br />
359 /// The line vertical alignment.<br />
361 /// <since_tizen> 3 </since_tizen>
362 public VerticalAlignment VerticalAlignment
367 if (GetProperty(TextLabel.Property.VERTICAL_ALIGNMENT).Get(out temp) == false)
369 NUILog.Error("VerticalAlignment get error!");
375 return VerticalAlignment.Top;
377 return VerticalAlignment.Center;
379 return VerticalAlignment.Bottom;
381 return VerticalAlignment.Bottom;
386 string valueToString = "";
389 case VerticalAlignment.Top:
391 valueToString = "TOP";
394 case VerticalAlignment.Center:
396 valueToString = "CENTER";
399 case VerticalAlignment.Bottom:
401 valueToString = "BOTTOM";
406 valueToString = "BOTTOM";
410 SetProperty(TextLabel.Property.VERTICAL_ALIGNMENT, new Tizen.NUI.PropertyValue(valueToString));
415 /// The TextColor property.<br />
416 /// The color of the text.<br />
417 /// Animation framework can be used to change the color of the text when not using mark up.<br />
418 /// Cannot animate the color when text is auto scrolling.<br />
420 /// <since_tizen> 3 </since_tizen>
421 public Color TextColor
425 Color temp = new Color(0.0f, 0.0f, 0.0f, 0.0f);
426 GetProperty(TextLabel.Property.TEXT_COLOR).Get(temp);
431 SetProperty(TextLabel.Property.TEXT_COLOR, new Tizen.NUI.PropertyValue(value));
436 /// The ShadowOffset property.<br />
437 /// The drop shadow offset 0 indicates no shadow.<br />
439 /// <since_tizen> 3 </since_tizen>
440 public Vector2 ShadowOffset
444 Vector2 temp = new Vector2(0.0f, 0.0f);
445 GetProperty(TextLabel.Property.SHADOW_OFFSET).Get(temp);
450 SetProperty(TextLabel.Property.SHADOW_OFFSET, new Tizen.NUI.PropertyValue(value));
455 /// The ShadowColor property.<br />
456 /// The color of a drop shadow.<br />
458 /// <since_tizen> 3 </since_tizen>
459 public Vector4 ShadowColor
463 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
464 GetProperty(TextLabel.Property.SHADOW_COLOR).Get(temp);
469 SetProperty(TextLabel.Property.SHADOW_COLOR, new Tizen.NUI.PropertyValue(value));
474 /// The UnderlineEnabled property.<br />
475 /// The underline enabled flag.<br />
477 /// <since_tizen> 3 </since_tizen>
478 public bool UnderlineEnabled
483 GetProperty(TextLabel.Property.UNDERLINE_ENABLED).Get(out temp);
488 SetProperty(TextLabel.Property.UNDERLINE_ENABLED, new Tizen.NUI.PropertyValue(value));
493 /// The UnderlineColor property.<br />
494 /// Overrides the underline height from font metrics.<br />
496 /// <since_tizen> 3 </since_tizen>
497 public Vector4 UnderlineColor
501 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
502 GetProperty(TextLabel.Property.UNDERLINE_COLOR).Get(temp);
507 SetProperty(TextLabel.Property.UNDERLINE_COLOR, new Tizen.NUI.PropertyValue(value));
512 /// The UnderlineHeight property.<br />
513 /// Overrides the underline height from font metrics.<br />
515 /// <since_tizen> 3 </since_tizen>
516 public float UnderlineHeight
521 GetProperty(TextLabel.Property.UNDERLINE_HEIGHT).Get(out temp);
526 SetProperty(TextLabel.Property.UNDERLINE_HEIGHT, new Tizen.NUI.PropertyValue(value));
531 /// The EnableMarkup property.<br />
532 /// Whether the mark-up processing is enabled.<br />
534 /// <since_tizen> 3 </since_tizen>
535 public bool EnableMarkup
540 GetProperty(TextLabel.Property.ENABLE_MARKUP).Get(out temp);
545 SetProperty(TextLabel.Property.ENABLE_MARKUP, new Tizen.NUI.PropertyValue(value));
550 /// The EnableAutoScroll property.<br />
551 /// Starts or stops auto scrolling.<br />
553 /// <since_tizen> 3 </since_tizen>
554 public bool EnableAutoScroll
559 GetProperty(TextLabel.Property.ENABLE_AUTO_SCROLL).Get(out temp);
564 SetProperty(TextLabel.Property.ENABLE_AUTO_SCROLL, new Tizen.NUI.PropertyValue(value));
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
578 GetProperty(TextLabel.Property.AUTO_SCROLL_SPEED).Get(out temp);
583 SetProperty(TextLabel.Property.AUTO_SCROLL_SPEED, new Tizen.NUI.PropertyValue(value));
588 /// The AutoScrollLoopCount property.<br />
589 /// Number of complete loops when scrolling enabled.<br />
591 /// <since_tizen> 3 </since_tizen>
592 public int AutoScrollLoopCount
597 GetProperty(TextLabel.Property.AUTO_SCROLL_LOOP_COUNT).Get(out temp);
602 SetProperty(TextLabel.Property.AUTO_SCROLL_LOOP_COUNT, new Tizen.NUI.PropertyValue(value));
607 /// The AutoScrollGap property.<br />
608 /// Gap before scrolling wraps.<br />
610 /// <since_tizen> 3 </since_tizen>
611 public float AutoScrollGap
616 GetProperty(TextLabel.Property.AUTO_SCROLL_GAP).Get(out temp);
621 SetProperty(TextLabel.Property.AUTO_SCROLL_GAP, new Tizen.NUI.PropertyValue(value));
626 /// The LineSpacing property.<br />
627 /// The default extra space between lines in points.<br />
629 /// <since_tizen> 3 </since_tizen>
630 public float LineSpacing
635 GetProperty(TextLabel.Property.LINE_SPACING).Get(out temp);
640 SetProperty(TextLabel.Property.LINE_SPACING, new Tizen.NUI.PropertyValue(value));
645 /// The Underline property.<br />
646 /// The default underline parameters.<br />
648 /// <since_tizen> 3 </since_tizen>
649 public PropertyMap Underline
653 PropertyMap temp = new PropertyMap();
654 GetProperty(TextLabel.Property.UNDERLINE).Get(temp);
659 SetProperty(TextLabel.Property.UNDERLINE, new Tizen.NUI.PropertyValue(value));
664 /// The Shadow property.<br />
665 /// The default shadow parameters.<br />
667 /// <since_tizen> 3 </since_tizen>
668 public PropertyMap Shadow
672 PropertyMap temp = new PropertyMap();
673 GetProperty(TextLabel.Property.SHADOW).Get(temp);
678 SetProperty(TextLabel.Property.SHADOW, new Tizen.NUI.PropertyValue(value));
683 /// The Emboss property.<br />
684 /// The default emboss parameters.<br />
686 /// <since_tizen> 3 </since_tizen>
692 GetProperty(TextLabel.Property.EMBOSS).Get( out temp);
697 SetProperty(TextLabel.Property.EMBOSS, new Tizen.NUI.PropertyValue(value));
702 /// The Outline property.<br />
703 /// The default outline parameters.<br />
705 /// <since_tizen> 3 </since_tizen>
706 public PropertyMap Outline
710 PropertyMap temp = new PropertyMap();
711 GetProperty(TextLabel.Property.OUTLINE).Get(temp);
716 SetProperty(TextLabel.Property.OUTLINE, new Tizen.NUI.PropertyValue(value));
721 /// The PixelSize property.<br />
722 /// The size of font in pixels.<br />
724 /// <since_tizen> 3 </since_tizen>
725 public float PixelSize
730 GetProperty(TextLabel.Property.PIXEL_SIZE).Get(out temp);
735 SetProperty(TextLabel.Property.PIXEL_SIZE, new Tizen.NUI.PropertyValue(value));
740 /// The Ellipsis property.<br />
741 /// Enable or disable the ellipsis.<br />
743 /// <since_tizen> 3 </since_tizen>
749 GetProperty(TextLabel.Property.ELLIPSIS).Get(out temp);
754 SetProperty(TextLabel.Property.ELLIPSIS, new Tizen.NUI.PropertyValue(value));
759 /// The AutoScrollLoopDelay property.<br />
760 /// Do something.<br />
762 /// <since_tizen> 3 </since_tizen>
763 public float AutoScrollLoopDelay
768 GetProperty(TextLabel.Property.AUTO_SCROLL_LOOP_DELAY).Get(out temp);
773 SetProperty(TextLabel.Property.AUTO_SCROLL_LOOP_DELAY, new Tizen.NUI.PropertyValue(value));
778 /// The AutoScrollStopMode property.<br />
779 /// Do something.<br />
781 /// <since_tizen> 3 </since_tizen>
782 public AutoScrollStopMode AutoScrollStopMode
787 if(GetProperty(TextLabel.Property.AUTO_SCROLL_STOP_MODE).Get(out temp) == false)
789 NUILog.Error("AutoScrollStopMode get error!");
794 return AutoScrollStopMode.FinishLoop;
796 return AutoScrollStopMode.Immediate;
798 return AutoScrollStopMode.FinishLoop;
803 SetProperty(TextLabel.Property.AUTO_SCROLL_STOP_MODE, new Tizen.NUI.PropertyValue((int)value));
808 /// The line count of the text.
810 /// <since_tizen> 3 </since_tizen>
816 GetProperty(TextLabel.Property.LINE_COUNT).Get(out temp);
822 /// The LineWrapMode property.<br />
823 /// line wrap mode when the text lines over layout width.<br />
825 /// <since_tizen> 4 </since_tizen>
826 public LineWrapMode LineWrapMode
831 if(GetProperty(TextLabel.Property.LINE_WRAP_MODE).Get(out temp) == false)
833 NUILog.Error("LineWrapMode get error!");
835 return (LineWrapMode)temp;
839 SetProperty(TextLabel.Property.LINE_WRAP_MODE, new Tizen.NUI.PropertyValue((int)value));
844 /// The text direction.
846 /// <since_tizen> 5 </since_tizen>
847 /// This will be released at Tizen.NET API Level 5, so currently this would be used as inhouse API.
848 [EditorBrowsable(EditorBrowsableState.Never)]
849 public TextDirection TextDirection
854 GetProperty(TextLabel.Property.TEXT_DIRECTION).Get(out temp);
855 return (TextDirection)temp;
860 /// The text vertical line alignment.
862 /// <since_tizen> 5 </since_tizen>
863 /// This will be released at Tizen.NET API Level 5, so currently this would be used as inhouse API.
864 [EditorBrowsable(EditorBrowsableState.Never)]
865 public VerticalLineAlignment VerticalLineAlignment
870 GetProperty(TextLabel.Property.VERTICAL_LINE_ALIGNMENT).Get(out temp);
871 return (VerticalLineAlignment)temp;
875 SetProperty(TextLabel.Property.VERTICAL_LINE_ALIGNMENT, new Tizen.NUI.PropertyValue((int)value));