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();
110 internal static readonly int TEXT_COLOR_ANIMATABLE = NDalicPINVOKE.TextLabel_Property_TEXT_COLOR_ANIMATABLE_get();
115 /// Creates the TextLabel control.
117 /// <since_tizen> 3 </since_tizen>
118 public TextLabel() : this(NDalicPINVOKE.TextLabel_New__SWIG_0(), true)
120 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
125 /// Creates the TextLabel control.
127 /// <param name="text">The text to display</param>
128 /// <since_tizen> 3 </since_tizen>
129 public TextLabel(string text) : this(NDalicPINVOKE.TextLabel_New__SWIG_1(text), true)
131 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
134 internal TextLabel(TextLabel handle) : this(NDalicPINVOKE.new_TextLabel__SWIG_1(TextLabel.getCPtr(handle)), true)
136 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
140 /// [Obsolete("Please do not use! this will be deprecated")]
142 /// <param name="handle"></param>
143 /// <returns></returns>
144 /// <since_tizen> 3 </since_tizen>
145 [Obsolete("Please do not use! this will be deprecated")]
146 public new static TextLabel DownCast(BaseHandle handle)
148 TextLabel ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as TextLabel;
150 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
154 /// The TranslatableText property.<br />
155 /// The text can set the SID value.<br />
157 /// <exception cref='ArgumentNullException'>
158 /// ResourceManager about multilingual is null.
160 /// <since_tizen> 4 </since_tizen>
161 public string TranslatableText
169 if (NUIApplication.MultilingualResourceManager == null)
171 throw new ArgumentNullException("ResourceManager about multilingual is null");
173 string translatableText = null;
174 textLabelSid = value;
175 translatableText = NUIApplication.MultilingualResourceManager?.GetString(textLabelSid, new CultureInfo(SystemSettings.LocaleLanguage.Replace("_", "-")));
176 if (translatableText != null)
178 Text = translatableText;
179 if (systemlangTextFlag == false)
181 SystemSettings.LocaleLanguageChanged += new WeakEventHandler<LocaleLanguageChangedEventArgs>(SystemSettings_LocaleLanguageChanged).Handler;
182 systemlangTextFlag = true;
191 private void SystemSettings_LocaleLanguageChanged(object sender, LocaleLanguageChangedEventArgs e)
193 Text = NUIApplication.MultilingualResourceManager?.GetString(textLabelSid, new CultureInfo(e.Value.Replace("_", "-")));
197 /// The Text property.<br />
198 /// The text to display in the UTF-8 format.<br />
200 /// <since_tizen> 3 </since_tizen>
206 GetProperty(TextLabel.Property.TEXT).Get(out temp);
211 SetProperty(TextLabel.Property.TEXT, new Tizen.NUI.PropertyValue(value));
216 /// The FontFamily property.<br />
217 /// The requested font family to use.<br />
219 /// <since_tizen> 3 </since_tizen>
220 public string FontFamily
225 GetProperty(TextLabel.Property.FONT_FAMILY).Get(out temp);
230 SetProperty(TextLabel.Property.FONT_FAMILY, new Tizen.NUI.PropertyValue(value));
235 /// The FontStyle property.<br />
236 /// The requested font style to use.<br />
238 /// <since_tizen> 3 </since_tizen>
239 public PropertyMap FontStyle
243 PropertyMap temp = new PropertyMap();
244 GetProperty(TextLabel.Property.FONT_STYLE).Get(temp);
249 SetProperty(TextLabel.Property.FONT_STYLE, new Tizen.NUI.PropertyValue(value));
254 /// The PointSize property.<br />
255 /// The size of font in points.<br />
257 /// <since_tizen> 3 </since_tizen>
258 public float PointSize
263 GetProperty(TextLabel.Property.POINT_SIZE).Get(out temp);
268 SetProperty(TextLabel.Property.POINT_SIZE, new Tizen.NUI.PropertyValue(value));
273 /// The MultiLine property.<br />
274 /// The single-line or multi-line layout option.<br />
276 /// <since_tizen> 3 </since_tizen>
277 public bool MultiLine
282 GetProperty(TextLabel.Property.MULTI_LINE).Get(out temp);
287 SetProperty(TextLabel.Property.MULTI_LINE, new Tizen.NUI.PropertyValue(value));
292 /// The HorizontalAlignment property.<br />
293 /// The line horizontal alignment.<br />
295 /// <since_tizen> 3 </since_tizen>
296 public HorizontalAlignment HorizontalAlignment
301 if (GetProperty(TextLabel.Property.HORIZONTAL_ALIGNMENT).Get(out temp) == false)
303 NUILog.Error("HorizontalAlignment get error!");
308 return HorizontalAlignment.Begin;
310 return HorizontalAlignment.Center;
312 return HorizontalAlignment.End;
314 return HorizontalAlignment.Begin;
319 string valueToString = "";
322 case HorizontalAlignment.Begin:
324 valueToString = "BEGIN";
327 case HorizontalAlignment.Center:
329 valueToString = "CENTER";
332 case HorizontalAlignment.End:
334 valueToString = "END";
339 valueToString = "BEGIN";
343 SetProperty(TextLabel.Property.HORIZONTAL_ALIGNMENT, new Tizen.NUI.PropertyValue(valueToString));
348 /// The VerticalAlignment property.<br />
349 /// The line vertical alignment.<br />
351 /// <since_tizen> 3 </since_tizen>
352 public VerticalAlignment VerticalAlignment
357 if (GetProperty(TextLabel.Property.VERTICAL_ALIGNMENT).Get(out temp) == false)
359 NUILog.Error("VerticalAlignment get error!");
365 return VerticalAlignment.Top;
367 return VerticalAlignment.Center;
369 return VerticalAlignment.Bottom;
371 return VerticalAlignment.Bottom;
376 string valueToString = "";
379 case VerticalAlignment.Top:
381 valueToString = "TOP";
384 case VerticalAlignment.Center:
386 valueToString = "CENTER";
389 case VerticalAlignment.Bottom:
391 valueToString = "BOTTOM";
396 valueToString = "BOTTOM";
400 SetProperty(TextLabel.Property.VERTICAL_ALIGNMENT, new Tizen.NUI.PropertyValue(valueToString));
405 /// The TextColor property.<br />
406 /// The color of the text.<br />
408 /// <since_tizen> 3 </since_tizen>
409 public Color TextColor
413 Color temp = new Color(0.0f, 0.0f, 0.0f, 0.0f);
414 GetProperty(TextLabel.Property.TEXT_COLOR).Get(temp);
419 SetProperty(TextLabel.Property.TEXT_COLOR, new Tizen.NUI.PropertyValue(value));
424 /// The ShadowOffset property.<br />
425 /// The drop shadow offset 0 indicates no shadow.<br />
427 /// <since_tizen> 3 </since_tizen>
428 public Vector2 ShadowOffset
432 Vector2 temp = new Vector2(0.0f, 0.0f);
433 GetProperty(TextLabel.Property.SHADOW_OFFSET).Get(temp);
438 SetProperty(TextLabel.Property.SHADOW_OFFSET, new Tizen.NUI.PropertyValue(value));
443 /// The ShadowColor property.<br />
444 /// The color of a drop shadow.<br />
446 /// <since_tizen> 3 </since_tizen>
447 public Vector4 ShadowColor
451 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
452 GetProperty(TextLabel.Property.SHADOW_COLOR).Get(temp);
457 SetProperty(TextLabel.Property.SHADOW_COLOR, new Tizen.NUI.PropertyValue(value));
462 /// The UnderlineEnabled property.<br />
463 /// The underline enabled flag.<br />
465 /// <since_tizen> 3 </since_tizen>
466 public bool UnderlineEnabled
471 GetProperty(TextLabel.Property.UNDERLINE_ENABLED).Get(out temp);
476 SetProperty(TextLabel.Property.UNDERLINE_ENABLED, new Tizen.NUI.PropertyValue(value));
481 /// The UnderlineColor property.<br />
482 /// Overrides the underline height from font metrics.<br />
484 /// <since_tizen> 3 </since_tizen>
485 public Vector4 UnderlineColor
489 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
490 GetProperty(TextLabel.Property.UNDERLINE_COLOR).Get(temp);
495 SetProperty(TextLabel.Property.UNDERLINE_COLOR, new Tizen.NUI.PropertyValue(value));
500 /// The UnderlineHeight property.<br />
501 /// Overrides the underline height from font metrics.<br />
503 /// <since_tizen> 3 </since_tizen>
504 public float UnderlineHeight
509 GetProperty(TextLabel.Property.UNDERLINE_HEIGHT).Get(out temp);
514 SetProperty(TextLabel.Property.UNDERLINE_HEIGHT, new Tizen.NUI.PropertyValue(value));
519 /// The EnableMarkup property.<br />
520 /// Whether the mark-up processing is enabled.<br />
522 /// <since_tizen> 3 </since_tizen>
523 public bool EnableMarkup
528 GetProperty(TextLabel.Property.ENABLE_MARKUP).Get(out temp);
533 SetProperty(TextLabel.Property.ENABLE_MARKUP, new Tizen.NUI.PropertyValue(value));
538 /// The EnableAutoScroll property.<br />
539 /// Starts or stops auto scrolling.<br />
541 /// <since_tizen> 3 </since_tizen>
542 public bool EnableAutoScroll
547 GetProperty(TextLabel.Property.ENABLE_AUTO_SCROLL).Get(out temp);
552 SetProperty(TextLabel.Property.ENABLE_AUTO_SCROLL, new Tizen.NUI.PropertyValue(value));
557 /// The AutoScrollSpeed property.<br />
558 /// Sets the speed of scrolling in pixels per second.<br />
560 /// <since_tizen> 3 </since_tizen>
561 public int AutoScrollSpeed
566 GetProperty(TextLabel.Property.AUTO_SCROLL_SPEED).Get(out temp);
571 SetProperty(TextLabel.Property.AUTO_SCROLL_SPEED, new Tizen.NUI.PropertyValue(value));
576 /// The AutoScrollLoopCount property.<br />
577 /// Number of complete loops when scrolling enabled.<br />
579 /// <since_tizen> 3 </since_tizen>
580 public int AutoScrollLoopCount
585 GetProperty(TextLabel.Property.AUTO_SCROLL_LOOP_COUNT).Get(out temp);
590 SetProperty(TextLabel.Property.AUTO_SCROLL_LOOP_COUNT, new Tizen.NUI.PropertyValue(value));
595 /// The AutoScrollGap property.<br />
596 /// Gap before scrolling wraps.<br />
598 /// <since_tizen> 3 </since_tizen>
599 public float AutoScrollGap
604 GetProperty(TextLabel.Property.AUTO_SCROLL_GAP).Get(out temp);
609 SetProperty(TextLabel.Property.AUTO_SCROLL_GAP, new Tizen.NUI.PropertyValue(value));
614 /// The LineSpacing property.<br />
615 /// The default extra space between lines in points.<br />
617 /// <since_tizen> 3 </since_tizen>
618 public float LineSpacing
623 GetProperty(TextLabel.Property.LINE_SPACING).Get(out temp);
628 SetProperty(TextLabel.Property.LINE_SPACING, new Tizen.NUI.PropertyValue(value));
633 /// The Underline property.<br />
634 /// The default underline parameters.<br />
636 /// <since_tizen> 3 </since_tizen>
637 public PropertyMap Underline
641 PropertyMap temp = new PropertyMap();
642 GetProperty(TextLabel.Property.UNDERLINE).Get(temp);
647 SetProperty(TextLabel.Property.UNDERLINE, new Tizen.NUI.PropertyValue(value));
652 /// The Shadow property.<br />
653 /// The default shadow parameters.<br />
655 /// <since_tizen> 3 </since_tizen>
656 public PropertyMap Shadow
660 PropertyMap temp = new PropertyMap();
661 GetProperty(TextLabel.Property.SHADOW).Get(temp);
666 SetProperty(TextLabel.Property.SHADOW, new Tizen.NUI.PropertyValue(value));
671 /// The Emboss property.<br />
672 /// The default emboss parameters.<br />
674 /// <since_tizen> 3 </since_tizen>
680 GetProperty(TextLabel.Property.EMBOSS).Get( out temp);
685 SetProperty(TextLabel.Property.EMBOSS, new Tizen.NUI.PropertyValue(value));
690 /// The Outline property.<br />
691 /// The default outline parameters.<br />
693 /// <since_tizen> 3 </since_tizen>
694 public string Outline
699 GetProperty(TextLabel.Property.OUTLINE).Get(out temp);
704 SetProperty(TextLabel.Property.OUTLINE, new Tizen.NUI.PropertyValue(value));
709 /// The PixelSize property.<br />
710 /// The size of font in pixels.<br />
712 /// <since_tizen> 3 </since_tizen>
713 public float PixelSize
718 GetProperty(TextLabel.Property.PIXEL_SIZE).Get(out temp);
723 SetProperty(TextLabel.Property.PIXEL_SIZE, new Tizen.NUI.PropertyValue(value));
728 /// The Ellipsis property.<br />
729 /// Enable or disable the ellipsis.<br />
731 /// <since_tizen> 3 </since_tizen>
737 GetProperty(TextLabel.Property.ELLIPSIS).Get(out temp);
742 SetProperty(TextLabel.Property.ELLIPSIS, new Tizen.NUI.PropertyValue(value));
747 /// The AutoScrollLoopDelay property.<br />
748 /// Do something.<br />
750 /// <since_tizen> 3 </since_tizen>
751 public float AutoScrollLoopDelay
756 GetProperty(TextLabel.Property.AUTO_SCROLL_LOOP_DELAY).Get(out temp);
761 SetProperty(TextLabel.Property.AUTO_SCROLL_LOOP_DELAY, new Tizen.NUI.PropertyValue(value));
766 /// The AutoScrollStopMode property.<br />
767 /// Do something.<br />
769 /// <since_tizen> 3 </since_tizen>
770 public AutoScrollStopMode AutoScrollStopMode
775 if(GetProperty(TextLabel.Property.AUTO_SCROLL_STOP_MODE).Get(out temp) == false)
777 NUILog.Error("AutoScrollStopMode get error!");
782 return AutoScrollStopMode.FinishLoop;
784 return AutoScrollStopMode.Immediate;
786 return AutoScrollStopMode.FinishLoop;
791 SetProperty(TextLabel.Property.AUTO_SCROLL_STOP_MODE, new Tizen.NUI.PropertyValue((int)value));
796 /// The TextColorAnimatable property.<br />
797 /// The color of the text that can be animatated.<br />
798 /// Animation framework can be used to change the color of the text when not using mark up.<br />
799 /// Not possible when text is auto scrolling. <br />
801 /// <since_tizen> 4 </since_tizen>
802 public Color TextColorAnimatable
806 Color animatableColor = new Color(0.0f, 0.0f, 0.0f, 0.0f);
807 GetProperty(TextLabel.Property.TEXT_COLOR_ANIMATABLE).Get(animatableColor);
808 return animatableColor;
812 SetProperty(TextLabel.Property.TEXT_COLOR_ANIMATABLE, new Tizen.NUI.PropertyValue(value));
817 /// The line count of the text.
819 /// <since_tizen> 4 </since_tizen>
825 GetProperty(TextLabel.Property.LINE_COUNT).Get(out temp);
831 /// The LineWrapMode property.<br />
832 /// line wrap mode when the text lines over layout width.<br />
834 /// <since_tizen> 4 </since_tizen>
835 public LineWrapMode LineWrapMode
840 if(GetProperty(TextLabel.Property.LINE_WRAP_MODE).Get(out temp) == false)
842 NUILog.Error("LineWrapMode get error!");
846 case "WRAP_MODE_WORD":
847 return LineWrapMode.Word;
848 case "WRAP_MODE_CHARACTER":
849 return LineWrapMode.Character;
851 return LineWrapMode.Word;
859 case LineWrapMode.Word:
861 temp = "WRAP_MODE_WORD";
864 case LineWrapMode.Character:
866 temp = "WRAP_MODE_CHARACTER";
870 SetProperty(TextLabel.Property.LINE_WRAP_MODE, new Tizen.NUI.PropertyValue(temp));