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 namespace Tizen.NUI.BaseComponents
26 /// A control which renders a short text string.<br />
27 /// Text labels are lightweight, non-editable, and do not respond to the user input.<br />
29 public class TextLabel : View
31 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
32 private string textLabelSid = null;
33 private bool systemlangTextFlag = false;
34 internal TextLabel(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.TextLabel_SWIGUpcast(cPtr), cMemoryOwn)
36 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
39 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(TextLabel obj)
41 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
47 protected override void Dispose(DisposeTypes type)
54 if(type == DisposeTypes.Explicit)
57 //Release your own managed resources here.
58 //You should release all of your own disposable objects here.
61 //Release your own unmanaged resources here.
62 //You should not access any managed member here except static instance.
63 //because the execution order of Finalizes is non-deterministic.
65 if (swigCPtr.Handle != global::System.IntPtr.Zero)
70 NDalicPINVOKE.delete_TextLabel(swigCPtr);
72 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
78 internal new class Property
80 internal static readonly int RENDERING_BACKEND = NDalicPINVOKE.TextLabel_Property_RENDERING_BACKEND_get();
81 internal static readonly int TEXT = NDalicPINVOKE.TextLabel_Property_TEXT_get();
82 internal static readonly int FONT_FAMILY = NDalicPINVOKE.TextLabel_Property_FONT_FAMILY_get();
83 internal static readonly int FONT_STYLE = NDalicPINVOKE.TextLabel_Property_FONT_STYLE_get();
84 internal static readonly int POINT_SIZE = NDalicPINVOKE.TextLabel_Property_POINT_SIZE_get();
85 internal static readonly int MULTI_LINE = NDalicPINVOKE.TextLabel_Property_MULTI_LINE_get();
86 internal static readonly int HORIZONTAL_ALIGNMENT = NDalicPINVOKE.TextLabel_Property_HORIZONTAL_ALIGNMENT_get();
87 internal static readonly int VERTICAL_ALIGNMENT = NDalicPINVOKE.TextLabel_Property_VERTICAL_ALIGNMENT_get();
88 internal static readonly int TEXT_COLOR = NDalicPINVOKE.TextLabel_Property_TEXT_COLOR_get();
89 internal static readonly int SHADOW_OFFSET = NDalicPINVOKE.TextLabel_Property_SHADOW_OFFSET_get();
90 internal static readonly int SHADOW_COLOR = NDalicPINVOKE.TextLabel_Property_SHADOW_COLOR_get();
91 internal static readonly int UNDERLINE_ENABLED = NDalicPINVOKE.TextLabel_Property_UNDERLINE_ENABLED_get();
92 internal static readonly int UNDERLINE_COLOR = NDalicPINVOKE.TextLabel_Property_UNDERLINE_COLOR_get();
93 internal static readonly int UNDERLINE_HEIGHT = NDalicPINVOKE.TextLabel_Property_UNDERLINE_HEIGHT_get();
94 internal static readonly int ENABLE_MARKUP = NDalicPINVOKE.TextLabel_Property_ENABLE_MARKUP_get();
95 internal static readonly int ENABLE_AUTO_SCROLL = NDalicPINVOKE.TextLabel_Property_ENABLE_AUTO_SCROLL_get();
96 internal static readonly int AUTO_SCROLL_SPEED = NDalicPINVOKE.TextLabel_Property_AUTO_SCROLL_SPEED_get();
97 internal static readonly int AUTO_SCROLL_LOOP_COUNT = NDalicPINVOKE.TextLabel_Property_AUTO_SCROLL_LOOP_COUNT_get();
98 internal static readonly int AUTO_SCROLL_GAP = NDalicPINVOKE.TextLabel_Property_AUTO_SCROLL_GAP_get();
99 internal static readonly int LINE_SPACING = NDalicPINVOKE.TextLabel_Property_LINE_SPACING_get();
100 internal static readonly int UNDERLINE = NDalicPINVOKE.TextLabel_Property_UNDERLINE_get();
101 internal static readonly int SHADOW = NDalicPINVOKE.TextLabel_Property_SHADOW_get();
102 internal static readonly int EMBOSS = NDalicPINVOKE.TextLabel_Property_EMBOSS_get();
103 internal static readonly int OUTLINE = NDalicPINVOKE.TextLabel_Property_OUTLINE_get();
104 internal static readonly int PIXEL_SIZE = NDalicManualPINVOKE.TextLabel_Property_PIXEL_SIZE_get();
105 internal static readonly int ELLIPSIS = NDalicManualPINVOKE.TextLabel_Property_ELLIPSIS_get();
106 internal static readonly int AUTO_SCROLL_STOP_MODE = NDalicManualPINVOKE.TextLabel_Property_AUTO_SCROLL_STOP_MODE_get();
107 internal static readonly int AUTO_SCROLL_LOOP_DELAY = NDalicManualPINVOKE.TextLabel_Property_AUTO_SCROLL_LOOP_DELAY_get();
108 internal static readonly int LINE_COUNT = NDalicManualPINVOKE.TextLabel_Property_LINE_COUNT_get();
109 internal static readonly int LINE_WRAP_MODE = NDalicManualPINVOKE.TextLabel_Property_LINE_WRAP_MODE_get();
114 /// Creates the TextLabel control.
116 /// <since_tizen> 3 </since_tizen>
117 public TextLabel() : this(NDalicPINVOKE.TextLabel_New__SWIG_0(), true)
119 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
124 /// Creates the TextLabel control.
126 /// <param name="text">The text to display</param>
127 /// <since_tizen> 3 </since_tizen>
128 public TextLabel(string text) : this(NDalicPINVOKE.TextLabel_New__SWIG_1(text), true)
130 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
133 internal TextLabel(TextLabel handle) : this(NDalicPINVOKE.new_TextLabel__SWIG_1(TextLabel.getCPtr(handle)), true)
135 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
139 /// [Obsolete("Please do not use! this will be deprecated")]
141 /// <param name="handle"></param>
142 /// <returns></returns>
143 /// <since_tizen> 3 </since_tizen>
144 [Obsolete("Please do not use! this will be deprecated")]
145 public new static TextLabel DownCast(BaseHandle handle)
147 TextLabel ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as TextLabel;
149 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
153 /// The TranslatableText property.<br />
154 /// The text can set the SID value.<br />
156 /// <exception cref='ArgumentNullException'>
157 /// ResourceManager about multilingual is null.
159 /// <since_tizen> 4 </since_tizen>
160 public string TranslatableText
168 if (NUIApplication.MultilingualResourceManager == null)
170 throw new ArgumentNullException("ResourceManager about multilingual is null");
172 string translatableText = null;
173 textLabelSid = value;
174 translatableText = NUIApplication.MultilingualResourceManager?.GetString(textLabelSid, new CultureInfo(SystemSettings.LocaleLanguage.Replace("_", "-")));
175 if (translatableText != null)
177 Text = translatableText;
178 if (systemlangTextFlag == false)
180 SystemSettings.LocaleLanguageChanged += new WeakEventHandler<LocaleLanguageChangedEventArgs>(SystemSettings_LocaleLanguageChanged).Handler;
181 systemlangTextFlag = true;
190 private void SystemSettings_LocaleLanguageChanged(object sender, LocaleLanguageChangedEventArgs e)
192 Text = NUIApplication.MultilingualResourceManager?.GetString(textLabelSid, new CultureInfo(e.Value.Replace("_", "-")));
196 /// The Text property.<br />
197 /// The text to display in the UTF-8 format.<br />
199 /// <since_tizen> 3 </since_tizen>
205 GetProperty(TextLabel.Property.TEXT).Get(out temp);
210 SetProperty(TextLabel.Property.TEXT, new Tizen.NUI.PropertyValue(value));
215 /// The FontFamily property.<br />
216 /// The requested font family to use.<br />
218 /// <since_tizen> 3 </since_tizen>
219 public string FontFamily
224 GetProperty(TextLabel.Property.FONT_FAMILY).Get(out temp);
229 SetProperty(TextLabel.Property.FONT_FAMILY, new Tizen.NUI.PropertyValue(value));
234 /// The FontStyle property.<br />
235 /// The requested font style to use.<br />
237 /// <since_tizen> 3 </since_tizen>
238 public PropertyMap FontStyle
242 PropertyMap temp = new PropertyMap();
243 GetProperty(TextLabel.Property.FONT_STYLE).Get(temp);
248 SetProperty(TextLabel.Property.FONT_STYLE, new Tizen.NUI.PropertyValue(value));
253 /// The PointSize property.<br />
254 /// The size of font in points.<br />
256 /// <since_tizen> 3 </since_tizen>
257 public float PointSize
262 GetProperty(TextLabel.Property.POINT_SIZE).Get(out temp);
267 SetProperty(TextLabel.Property.POINT_SIZE, new Tizen.NUI.PropertyValue(value));
272 /// The MultiLine property.<br />
273 /// The single-line or multi-line layout option.<br />
275 /// <since_tizen> 3 </since_tizen>
276 public bool MultiLine
281 GetProperty(TextLabel.Property.MULTI_LINE).Get(out temp);
286 SetProperty(TextLabel.Property.MULTI_LINE, new Tizen.NUI.PropertyValue(value));
291 /// The HorizontalAlignment property.<br />
292 /// The line horizontal alignment.<br />
294 /// <since_tizen> 3 </since_tizen>
295 public HorizontalAlignment HorizontalAlignment
300 if (GetProperty(TextLabel.Property.HORIZONTAL_ALIGNMENT).Get(out temp) == false)
302 NUILog.Error("HorizontalAlignment get error!");
307 return HorizontalAlignment.Begin;
309 return HorizontalAlignment.Center;
311 return HorizontalAlignment.End;
313 return HorizontalAlignment.Begin;
318 string valueToString = "";
321 case HorizontalAlignment.Begin:
323 valueToString = "BEGIN";
326 case HorizontalAlignment.Center:
328 valueToString = "CENTER";
331 case HorizontalAlignment.End:
333 valueToString = "END";
338 valueToString = "BEGIN";
342 SetProperty(TextLabel.Property.HORIZONTAL_ALIGNMENT, new Tizen.NUI.PropertyValue(valueToString));
347 /// The VerticalAlignment property.<br />
348 /// The line vertical alignment.<br />
350 /// <since_tizen> 3 </since_tizen>
351 public VerticalAlignment VerticalAlignment
356 if (GetProperty(TextLabel.Property.VERTICAL_ALIGNMENT).Get(out temp) == false)
358 NUILog.Error("VerticalAlignment get error!");
364 return VerticalAlignment.Top;
366 return VerticalAlignment.Center;
368 return VerticalAlignment.Bottom;
370 return VerticalAlignment.Bottom;
375 string valueToString = "";
378 case VerticalAlignment.Top:
380 valueToString = "TOP";
383 case VerticalAlignment.Center:
385 valueToString = "CENTER";
388 case VerticalAlignment.Bottom:
390 valueToString = "BOTTOM";
395 valueToString = "BOTTOM";
399 SetProperty(TextLabel.Property.VERTICAL_ALIGNMENT, new Tizen.NUI.PropertyValue(valueToString));
404 /// The TextColor property.<br />
405 /// The color of the text.<br />
406 /// Animation framework can be used to change the color of the text when not using mark up.<br />
407 /// Cannot animate the color when text is auto scrolling.<br />
409 /// <since_tizen> 3 </since_tizen>
410 public Color TextColor
414 Color temp = new Color(0.0f, 0.0f, 0.0f, 0.0f);
415 GetProperty(TextLabel.Property.TEXT_COLOR).Get(temp);
420 SetProperty(TextLabel.Property.TEXT_COLOR, new Tizen.NUI.PropertyValue(value));
425 /// The ShadowOffset property.<br />
426 /// The drop shadow offset 0 indicates no shadow.<br />
428 /// <since_tizen> 3 </since_tizen>
429 public Vector2 ShadowOffset
433 Vector2 temp = new Vector2(0.0f, 0.0f);
434 GetProperty(TextLabel.Property.SHADOW_OFFSET).Get(temp);
439 SetProperty(TextLabel.Property.SHADOW_OFFSET, new Tizen.NUI.PropertyValue(value));
444 /// The ShadowColor property.<br />
445 /// The color of a drop shadow.<br />
447 /// <since_tizen> 3 </since_tizen>
448 public Vector4 ShadowColor
452 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
453 GetProperty(TextLabel.Property.SHADOW_COLOR).Get(temp);
458 SetProperty(TextLabel.Property.SHADOW_COLOR, new Tizen.NUI.PropertyValue(value));
463 /// The UnderlineEnabled property.<br />
464 /// The underline enabled flag.<br />
466 /// <since_tizen> 3 </since_tizen>
467 public bool UnderlineEnabled
472 GetProperty(TextLabel.Property.UNDERLINE_ENABLED).Get(out temp);
477 SetProperty(TextLabel.Property.UNDERLINE_ENABLED, new Tizen.NUI.PropertyValue(value));
482 /// The UnderlineColor property.<br />
483 /// Overrides the underline height from font metrics.<br />
485 /// <since_tizen> 3 </since_tizen>
486 public Vector4 UnderlineColor
490 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
491 GetProperty(TextLabel.Property.UNDERLINE_COLOR).Get(temp);
496 SetProperty(TextLabel.Property.UNDERLINE_COLOR, new Tizen.NUI.PropertyValue(value));
501 /// The UnderlineHeight property.<br />
502 /// Overrides the underline height from font metrics.<br />
504 /// <since_tizen> 3 </since_tizen>
505 public float UnderlineHeight
510 GetProperty(TextLabel.Property.UNDERLINE_HEIGHT).Get(out temp);
515 SetProperty(TextLabel.Property.UNDERLINE_HEIGHT, new Tizen.NUI.PropertyValue(value));
520 /// The EnableMarkup property.<br />
521 /// Whether the mark-up processing is enabled.<br />
523 /// <since_tizen> 3 </since_tizen>
524 public bool EnableMarkup
529 GetProperty(TextLabel.Property.ENABLE_MARKUP).Get(out temp);
534 SetProperty(TextLabel.Property.ENABLE_MARKUP, new Tizen.NUI.PropertyValue(value));
539 /// The EnableAutoScroll property.<br />
540 /// Starts or stops auto scrolling.<br />
542 /// <since_tizen> 3 </since_tizen>
543 public bool EnableAutoScroll
548 GetProperty(TextLabel.Property.ENABLE_AUTO_SCROLL).Get(out temp);
553 SetProperty(TextLabel.Property.ENABLE_AUTO_SCROLL, new Tizen.NUI.PropertyValue(value));
558 /// The AutoScrollSpeed property.<br />
559 /// Sets the speed of scrolling in pixels per second.<br />
561 /// <since_tizen> 3 </since_tizen>
562 public int AutoScrollSpeed
567 GetProperty(TextLabel.Property.AUTO_SCROLL_SPEED).Get(out temp);
572 SetProperty(TextLabel.Property.AUTO_SCROLL_SPEED, new Tizen.NUI.PropertyValue(value));
577 /// The AutoScrollLoopCount property.<br />
578 /// Number of complete loops when scrolling enabled.<br />
580 /// <since_tizen> 3 </since_tizen>
581 public int AutoScrollLoopCount
586 GetProperty(TextLabel.Property.AUTO_SCROLL_LOOP_COUNT).Get(out temp);
591 SetProperty(TextLabel.Property.AUTO_SCROLL_LOOP_COUNT, new Tizen.NUI.PropertyValue(value));
596 /// The AutoScrollGap property.<br />
597 /// Gap before scrolling wraps.<br />
599 /// <since_tizen> 3 </since_tizen>
600 public float AutoScrollGap
605 GetProperty(TextLabel.Property.AUTO_SCROLL_GAP).Get(out temp);
610 SetProperty(TextLabel.Property.AUTO_SCROLL_GAP, new Tizen.NUI.PropertyValue(value));
615 /// The LineSpacing property.<br />
616 /// The default extra space between lines in points.<br />
618 /// <since_tizen> 3 </since_tizen>
619 public float LineSpacing
624 GetProperty(TextLabel.Property.LINE_SPACING).Get(out temp);
629 SetProperty(TextLabel.Property.LINE_SPACING, new Tizen.NUI.PropertyValue(value));
634 /// The Underline property.<br />
635 /// The default underline parameters.<br />
637 /// <since_tizen> 3 </since_tizen>
638 public PropertyMap Underline
642 PropertyMap temp = new PropertyMap();
643 GetProperty(TextLabel.Property.UNDERLINE).Get(temp);
648 SetProperty(TextLabel.Property.UNDERLINE, new Tizen.NUI.PropertyValue(value));
653 /// The Shadow property.<br />
654 /// The default shadow parameters.<br />
656 /// <since_tizen> 3 </since_tizen>
657 public PropertyMap Shadow
661 PropertyMap temp = new PropertyMap();
662 GetProperty(TextLabel.Property.SHADOW).Get(temp);
667 SetProperty(TextLabel.Property.SHADOW, new Tizen.NUI.PropertyValue(value));
672 /// The Emboss property.<br />
673 /// The default emboss parameters.<br />
675 /// <since_tizen> 3 </since_tizen>
681 GetProperty(TextLabel.Property.EMBOSS).Get( out temp);
686 SetProperty(TextLabel.Property.EMBOSS, new Tizen.NUI.PropertyValue(value));
691 /// The Outline property.<br />
692 /// The default outline parameters.<br />
694 /// <since_tizen> 3 </since_tizen>
695 public string Outline
700 GetProperty(TextLabel.Property.OUTLINE).Get(out temp);
705 SetProperty(TextLabel.Property.OUTLINE, new Tizen.NUI.PropertyValue(value));
710 /// The PixelSize property.<br />
711 /// The size of font in pixels.<br />
713 /// <since_tizen> 3 </since_tizen>
714 public float PixelSize
719 GetProperty(TextLabel.Property.PIXEL_SIZE).Get(out temp);
724 SetProperty(TextLabel.Property.PIXEL_SIZE, new Tizen.NUI.PropertyValue(value));
729 /// The Ellipsis property.<br />
730 /// Enable or disable the ellipsis.<br />
732 /// <since_tizen> 3 </since_tizen>
738 GetProperty(TextLabel.Property.ELLIPSIS).Get(out temp);
743 SetProperty(TextLabel.Property.ELLIPSIS, new Tizen.NUI.PropertyValue(value));
748 /// The AutoScrollLoopDelay property.<br />
749 /// Do something.<br />
751 /// <since_tizen> 3 </since_tizen>
752 public float AutoScrollLoopDelay
757 GetProperty(TextLabel.Property.AUTO_SCROLL_LOOP_DELAY).Get(out temp);
762 SetProperty(TextLabel.Property.AUTO_SCROLL_LOOP_DELAY, new Tizen.NUI.PropertyValue(value));
767 /// The AutoScrollStopMode property.<br />
768 /// Do something.<br />
770 /// <since_tizen> 3 </since_tizen>
771 public AutoScrollStopMode AutoScrollStopMode
776 if(GetProperty(TextLabel.Property.AUTO_SCROLL_STOP_MODE).Get(out temp) == false)
778 NUILog.Error("AutoScrollStopMode get error!");
783 return AutoScrollStopMode.FinishLoop;
785 return AutoScrollStopMode.Immediate;
787 return AutoScrollStopMode.FinishLoop;
792 SetProperty(TextLabel.Property.AUTO_SCROLL_STOP_MODE, new Tizen.NUI.PropertyValue((int)value));
797 /// The line count of the text.
799 /// <since_tizen> 4 </since_tizen>
805 GetProperty(TextLabel.Property.LINE_COUNT).Get(out temp);
811 /// The LineWrapMode property.<br />
812 /// line wrap mode when the text lines over layout width.<br />
814 /// <since_tizen> 4 </since_tizen>
815 public LineWrapMode LineWrapMode
820 if(GetProperty(TextLabel.Property.LINE_WRAP_MODE).Get(out temp) == false)
822 NUILog.Error("LineWrapMode get error!");
826 case "WRAP_MODE_WORD":
827 return LineWrapMode.Word;
828 case "WRAP_MODE_CHARACTER":
829 return LineWrapMode.Character;
831 return LineWrapMode.Word;
839 case LineWrapMode.Word:
841 temp = "WRAP_MODE_WORD";
844 case LineWrapMode.Character:
846 temp = "WRAP_MODE_CHARACTER";
850 SetProperty(TextLabel.Property.LINE_WRAP_MODE, new Tizen.NUI.PropertyValue(temp));