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;
49 /// <since_tizen> 3 </since_tizen>
50 protected override void Dispose(DisposeTypes type)
57 if(type == DisposeTypes.Explicit)
60 //Release your own managed resources here.
61 //You should release all of your own disposable objects here.
64 //Release your own unmanaged resources here.
65 //You should not access any managed member here except static instance.
66 //because the execution order of Finalizes is non-deterministic.
68 if (swigCPtr.Handle != global::System.IntPtr.Zero)
73 NDalicPINVOKE.delete_TextLabel(swigCPtr);
75 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
81 internal new class Property
83 internal static readonly int RENDERING_BACKEND = NDalicPINVOKE.TextLabel_Property_RENDERING_BACKEND_get();
84 internal static readonly int TEXT = NDalicPINVOKE.TextLabel_Property_TEXT_get();
85 internal static readonly int FONT_FAMILY = NDalicPINVOKE.TextLabel_Property_FONT_FAMILY_get();
86 internal static readonly int FONT_STYLE = NDalicPINVOKE.TextLabel_Property_FONT_STYLE_get();
87 internal static readonly int POINT_SIZE = NDalicPINVOKE.TextLabel_Property_POINT_SIZE_get();
88 internal static readonly int MULTI_LINE = NDalicPINVOKE.TextLabel_Property_MULTI_LINE_get();
89 internal static readonly int HORIZONTAL_ALIGNMENT = NDalicPINVOKE.TextLabel_Property_HORIZONTAL_ALIGNMENT_get();
90 internal static readonly int VERTICAL_ALIGNMENT = NDalicPINVOKE.TextLabel_Property_VERTICAL_ALIGNMENT_get();
91 internal static readonly int TEXT_COLOR = NDalicPINVOKE.TextLabel_Property_TEXT_COLOR_get();
92 internal static readonly int SHADOW_OFFSET = NDalicPINVOKE.TextLabel_Property_SHADOW_OFFSET_get();
93 internal static readonly int SHADOW_COLOR = NDalicPINVOKE.TextLabel_Property_SHADOW_COLOR_get();
94 internal static readonly int UNDERLINE_ENABLED = NDalicPINVOKE.TextLabel_Property_UNDERLINE_ENABLED_get();
95 internal static readonly int UNDERLINE_COLOR = NDalicPINVOKE.TextLabel_Property_UNDERLINE_COLOR_get();
96 internal static readonly int UNDERLINE_HEIGHT = NDalicPINVOKE.TextLabel_Property_UNDERLINE_HEIGHT_get();
97 internal static readonly int ENABLE_MARKUP = NDalicPINVOKE.TextLabel_Property_ENABLE_MARKUP_get();
98 internal static readonly int ENABLE_AUTO_SCROLL = NDalicPINVOKE.TextLabel_Property_ENABLE_AUTO_SCROLL_get();
99 internal static readonly int AUTO_SCROLL_SPEED = NDalicPINVOKE.TextLabel_Property_AUTO_SCROLL_SPEED_get();
100 internal static readonly int AUTO_SCROLL_LOOP_COUNT = NDalicPINVOKE.TextLabel_Property_AUTO_SCROLL_LOOP_COUNT_get();
101 internal static readonly int AUTO_SCROLL_GAP = NDalicPINVOKE.TextLabel_Property_AUTO_SCROLL_GAP_get();
102 internal static readonly int LINE_SPACING = NDalicPINVOKE.TextLabel_Property_LINE_SPACING_get();
103 internal static readonly int UNDERLINE = NDalicPINVOKE.TextLabel_Property_UNDERLINE_get();
104 internal static readonly int SHADOW = NDalicPINVOKE.TextLabel_Property_SHADOW_get();
105 internal static readonly int EMBOSS = NDalicPINVOKE.TextLabel_Property_EMBOSS_get();
106 internal static readonly int OUTLINE = NDalicPINVOKE.TextLabel_Property_OUTLINE_get();
107 internal static readonly int PIXEL_SIZE = NDalicManualPINVOKE.TextLabel_Property_PIXEL_SIZE_get();
108 internal static readonly int ELLIPSIS = NDalicManualPINVOKE.TextLabel_Property_ELLIPSIS_get();
109 internal static readonly int AUTO_SCROLL_STOP_MODE = NDalicManualPINVOKE.TextLabel_Property_AUTO_SCROLL_STOP_MODE_get();
110 internal static readonly int AUTO_SCROLL_LOOP_DELAY = NDalicManualPINVOKE.TextLabel_Property_AUTO_SCROLL_LOOP_DELAY_get();
111 internal static readonly int LINE_COUNT = NDalicManualPINVOKE.TextLabel_Property_LINE_COUNT_get();
112 internal static readonly int LINE_WRAP_MODE = NDalicManualPINVOKE.TextLabel_Property_LINE_WRAP_MODE_get();
113 internal static readonly int TEXT_DIRECTION = NDalicManualPINVOKE.TextLabel_Property_TEXT_DIRECTION_get();
117 /// Creates the TextLabel control.
119 /// <since_tizen> 3 </since_tizen>
120 public TextLabel() : this(NDalicPINVOKE.TextLabel_New__SWIG_0(), true)
122 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
127 /// Creates the TextLabel control.
129 /// <param name="text">The text to display</param>
130 /// <since_tizen> 3 </since_tizen>
131 public TextLabel(string text) : this(NDalicPINVOKE.TextLabel_New__SWIG_1(text), true)
133 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
136 internal TextLabel(TextLabel handle) : this(NDalicPINVOKE.new_TextLabel__SWIG_1(TextLabel.getCPtr(handle)), true)
138 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
142 /// The TranslatableText property.<br />
143 /// The text can set the SID value.<br />
145 /// <exception cref='ArgumentNullException'>
146 /// ResourceManager about multilingual is null.
148 /// <since_tizen> 4 </since_tizen>
149 public string TranslatableText
157 if (NUIApplication.MultilingualResourceManager == null)
159 throw new ArgumentNullException("ResourceManager about multilingual is null");
161 string translatableText = null;
162 textLabelSid = value;
163 translatableText = NUIApplication.MultilingualResourceManager?.GetString(textLabelSid, new CultureInfo(SystemSettings.LocaleLanguage.Replace("_", "-")));
164 if (translatableText != null)
166 Text = translatableText;
167 if (systemlangTextFlag == false)
169 SystemSettings.LocaleLanguageChanged += new WeakEventHandler<LocaleLanguageChangedEventArgs>(SystemSettings_LocaleLanguageChanged).Handler;
170 systemlangTextFlag = true;
179 private void SystemSettings_LocaleLanguageChanged(object sender, LocaleLanguageChangedEventArgs e)
181 Text = NUIApplication.MultilingualResourceManager?.GetString(textLabelSid, new CultureInfo(e.Value.Replace("_", "-")));
185 /// The Text property.<br />
186 /// The text to display in the UTF-8 format.<br />
188 /// <since_tizen> 3 </since_tizen>
194 GetProperty(TextLabel.Property.TEXT).Get(out temp);
199 SetProperty(TextLabel.Property.TEXT, new Tizen.NUI.PropertyValue(value));
204 /// The FontFamily property.<br />
205 /// The requested font family to use.<br />
207 /// <since_tizen> 3 </since_tizen>
208 public string FontFamily
213 GetProperty(TextLabel.Property.FONT_FAMILY).Get(out temp);
218 SetProperty(TextLabel.Property.FONT_FAMILY, new Tizen.NUI.PropertyValue(value));
223 /// The FontStyle property.<br />
224 /// The requested font style to use.<br />
226 /// <since_tizen> 3 </since_tizen>
227 public PropertyMap FontStyle
231 PropertyMap temp = new PropertyMap();
232 GetProperty(TextLabel.Property.FONT_STYLE).Get(temp);
237 SetProperty(TextLabel.Property.FONT_STYLE, new Tizen.NUI.PropertyValue(value));
242 /// The PointSize property.<br />
243 /// The size of font in points.<br />
245 /// <since_tizen> 3 </since_tizen>
246 public float PointSize
251 GetProperty(TextLabel.Property.POINT_SIZE).Get(out temp);
256 SetProperty(TextLabel.Property.POINT_SIZE, new Tizen.NUI.PropertyValue(value));
261 /// The MultiLine property.<br />
262 /// The single-line or multi-line layout option.<br />
264 /// <since_tizen> 3 </since_tizen>
265 public bool MultiLine
270 GetProperty(TextLabel.Property.MULTI_LINE).Get(out temp);
275 SetProperty(TextLabel.Property.MULTI_LINE, new Tizen.NUI.PropertyValue(value));
280 /// The HorizontalAlignment property.<br />
281 /// The line horizontal alignment.<br />
283 /// <since_tizen> 3 </since_tizen>
284 public HorizontalAlignment HorizontalAlignment
289 if (GetProperty(TextLabel.Property.HORIZONTAL_ALIGNMENT).Get(out temp) == false)
291 NUILog.Error("HorizontalAlignment get error!");
296 return HorizontalAlignment.Begin;
298 return HorizontalAlignment.Center;
300 return HorizontalAlignment.End;
302 return HorizontalAlignment.Begin;
307 string valueToString = "";
310 case HorizontalAlignment.Begin:
312 valueToString = "BEGIN";
315 case HorizontalAlignment.Center:
317 valueToString = "CENTER";
320 case HorizontalAlignment.End:
322 valueToString = "END";
327 valueToString = "BEGIN";
331 SetProperty(TextLabel.Property.HORIZONTAL_ALIGNMENT, new Tizen.NUI.PropertyValue(valueToString));
336 /// The VerticalAlignment property.<br />
337 /// The line vertical alignment.<br />
339 /// <since_tizen> 3 </since_tizen>
340 public VerticalAlignment VerticalAlignment
345 if (GetProperty(TextLabel.Property.VERTICAL_ALIGNMENT).Get(out temp) == false)
347 NUILog.Error("VerticalAlignment get error!");
353 return VerticalAlignment.Top;
355 return VerticalAlignment.Center;
357 return VerticalAlignment.Bottom;
359 return VerticalAlignment.Bottom;
364 string valueToString = "";
367 case VerticalAlignment.Top:
369 valueToString = "TOP";
372 case VerticalAlignment.Center:
374 valueToString = "CENTER";
377 case VerticalAlignment.Bottom:
379 valueToString = "BOTTOM";
384 valueToString = "BOTTOM";
388 SetProperty(TextLabel.Property.VERTICAL_ALIGNMENT, new Tizen.NUI.PropertyValue(valueToString));
393 /// The TextColor property.<br />
394 /// The color of the text.<br />
395 /// Animation framework can be used to change the color of the text when not using mark up.<br />
396 /// Cannot animate the color when text is auto scrolling.<br />
398 /// <since_tizen> 3 </since_tizen>
399 public Color TextColor
403 Color temp = new Color(0.0f, 0.0f, 0.0f, 0.0f);
404 GetProperty(TextLabel.Property.TEXT_COLOR).Get(temp);
409 SetProperty(TextLabel.Property.TEXT_COLOR, new Tizen.NUI.PropertyValue(value));
414 /// The ShadowOffset property.<br />
415 /// The drop shadow offset 0 indicates no shadow.<br />
417 /// <since_tizen> 3 </since_tizen>
418 public Vector2 ShadowOffset
422 Vector2 temp = new Vector2(0.0f, 0.0f);
423 GetProperty(TextLabel.Property.SHADOW_OFFSET).Get(temp);
428 SetProperty(TextLabel.Property.SHADOW_OFFSET, new Tizen.NUI.PropertyValue(value));
433 /// The ShadowColor property.<br />
434 /// The color of a drop shadow.<br />
436 /// <since_tizen> 3 </since_tizen>
437 public Vector4 ShadowColor
441 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
442 GetProperty(TextLabel.Property.SHADOW_COLOR).Get(temp);
447 SetProperty(TextLabel.Property.SHADOW_COLOR, new Tizen.NUI.PropertyValue(value));
452 /// The UnderlineEnabled property.<br />
453 /// The underline enabled flag.<br />
455 /// <since_tizen> 3 </since_tizen>
456 public bool UnderlineEnabled
461 GetProperty(TextLabel.Property.UNDERLINE_ENABLED).Get(out temp);
466 SetProperty(TextLabel.Property.UNDERLINE_ENABLED, new Tizen.NUI.PropertyValue(value));
471 /// The UnderlineColor property.<br />
472 /// Overrides the underline height from font metrics.<br />
474 /// <since_tizen> 3 </since_tizen>
475 public Vector4 UnderlineColor
479 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
480 GetProperty(TextLabel.Property.UNDERLINE_COLOR).Get(temp);
485 SetProperty(TextLabel.Property.UNDERLINE_COLOR, new Tizen.NUI.PropertyValue(value));
490 /// The UnderlineHeight property.<br />
491 /// Overrides the underline height from font metrics.<br />
493 /// <since_tizen> 3 </since_tizen>
494 public float UnderlineHeight
499 GetProperty(TextLabel.Property.UNDERLINE_HEIGHT).Get(out temp);
504 SetProperty(TextLabel.Property.UNDERLINE_HEIGHT, new Tizen.NUI.PropertyValue(value));
509 /// The EnableMarkup property.<br />
510 /// Whether the mark-up processing is enabled.<br />
512 /// <since_tizen> 3 </since_tizen>
513 public bool EnableMarkup
518 GetProperty(TextLabel.Property.ENABLE_MARKUP).Get(out temp);
523 SetProperty(TextLabel.Property.ENABLE_MARKUP, new Tizen.NUI.PropertyValue(value));
528 /// The EnableAutoScroll property.<br />
529 /// Starts or stops auto scrolling.<br />
531 /// <since_tizen> 3 </since_tizen>
532 public bool EnableAutoScroll
537 GetProperty(TextLabel.Property.ENABLE_AUTO_SCROLL).Get(out temp);
542 SetProperty(TextLabel.Property.ENABLE_AUTO_SCROLL, new Tizen.NUI.PropertyValue(value));
547 /// The AutoScrollSpeed property.<br />
548 /// Sets the speed of scrolling in pixels per second.<br />
550 /// <since_tizen> 3 </since_tizen>
551 public int AutoScrollSpeed
556 GetProperty(TextLabel.Property.AUTO_SCROLL_SPEED).Get(out temp);
561 SetProperty(TextLabel.Property.AUTO_SCROLL_SPEED, new Tizen.NUI.PropertyValue(value));
566 /// The AutoScrollLoopCount property.<br />
567 /// Number of complete loops when scrolling enabled.<br />
569 /// <since_tizen> 3 </since_tizen>
570 public int AutoScrollLoopCount
575 GetProperty(TextLabel.Property.AUTO_SCROLL_LOOP_COUNT).Get(out temp);
580 SetProperty(TextLabel.Property.AUTO_SCROLL_LOOP_COUNT, new Tizen.NUI.PropertyValue(value));
585 /// The AutoScrollGap property.<br />
586 /// Gap before scrolling wraps.<br />
588 /// <since_tizen> 3 </since_tizen>
589 public float AutoScrollGap
594 GetProperty(TextLabel.Property.AUTO_SCROLL_GAP).Get(out temp);
599 SetProperty(TextLabel.Property.AUTO_SCROLL_GAP, new Tizen.NUI.PropertyValue(value));
604 /// The LineSpacing property.<br />
605 /// The default extra space between lines in points.<br />
607 /// <since_tizen> 3 </since_tizen>
608 public float LineSpacing
613 GetProperty(TextLabel.Property.LINE_SPACING).Get(out temp);
618 SetProperty(TextLabel.Property.LINE_SPACING, new Tizen.NUI.PropertyValue(value));
623 /// The Underline property.<br />
624 /// The default underline parameters.<br />
626 /// <since_tizen> 3 </since_tizen>
627 public PropertyMap Underline
631 PropertyMap temp = new PropertyMap();
632 GetProperty(TextLabel.Property.UNDERLINE).Get(temp);
637 SetProperty(TextLabel.Property.UNDERLINE, new Tizen.NUI.PropertyValue(value));
642 /// The Shadow property.<br />
643 /// The default shadow parameters.<br />
645 /// <since_tizen> 3 </since_tizen>
646 public PropertyMap Shadow
650 PropertyMap temp = new PropertyMap();
651 GetProperty(TextLabel.Property.SHADOW).Get(temp);
656 SetProperty(TextLabel.Property.SHADOW, new Tizen.NUI.PropertyValue(value));
661 /// The Emboss property.<br />
662 /// The default emboss parameters.<br />
664 /// <since_tizen> 3 </since_tizen>
670 GetProperty(TextLabel.Property.EMBOSS).Get( out temp);
675 SetProperty(TextLabel.Property.EMBOSS, new Tizen.NUI.PropertyValue(value));
680 /// The Outline property.<br />
681 /// The default outline parameters.<br />
683 /// <since_tizen> 3 </since_tizen>
684 public PropertyMap Outline
688 PropertyMap temp = new PropertyMap();
689 GetProperty(TextLabel.Property.OUTLINE).Get(temp);
694 SetProperty(TextLabel.Property.OUTLINE, new Tizen.NUI.PropertyValue(value));
699 /// The PixelSize property.<br />
700 /// The size of font in pixels.<br />
702 /// <since_tizen> 3 </since_tizen>
703 public float PixelSize
708 GetProperty(TextLabel.Property.PIXEL_SIZE).Get(out temp);
713 SetProperty(TextLabel.Property.PIXEL_SIZE, new Tizen.NUI.PropertyValue(value));
718 /// The Ellipsis property.<br />
719 /// Enable or disable the ellipsis.<br />
721 /// <since_tizen> 3 </since_tizen>
727 GetProperty(TextLabel.Property.ELLIPSIS).Get(out temp);
732 SetProperty(TextLabel.Property.ELLIPSIS, new Tizen.NUI.PropertyValue(value));
737 /// The AutoScrollLoopDelay property.<br />
738 /// Do something.<br />
740 /// <since_tizen> 3 </since_tizen>
741 public float AutoScrollLoopDelay
746 GetProperty(TextLabel.Property.AUTO_SCROLL_LOOP_DELAY).Get(out temp);
751 SetProperty(TextLabel.Property.AUTO_SCROLL_LOOP_DELAY, new Tizen.NUI.PropertyValue(value));
756 /// The AutoScrollStopMode property.<br />
757 /// Do something.<br />
759 /// <since_tizen> 3 </since_tizen>
760 public AutoScrollStopMode AutoScrollStopMode
765 if(GetProperty(TextLabel.Property.AUTO_SCROLL_STOP_MODE).Get(out temp) == false)
767 NUILog.Error("AutoScrollStopMode get error!");
772 return AutoScrollStopMode.FinishLoop;
774 return AutoScrollStopMode.Immediate;
776 return AutoScrollStopMode.FinishLoop;
781 SetProperty(TextLabel.Property.AUTO_SCROLL_STOP_MODE, new Tizen.NUI.PropertyValue((int)value));
786 /// The line count of the text.
788 /// <since_tizen> 3 </since_tizen>
794 GetProperty(TextLabel.Property.LINE_COUNT).Get(out temp);
800 /// The LineWrapMode property.<br />
801 /// line wrap mode when the text lines over layout width.<br />
803 /// <since_tizen> 4 </since_tizen>
804 public LineWrapMode LineWrapMode
809 if(GetProperty(TextLabel.Property.LINE_WRAP_MODE).Get(out temp) == false)
811 NUILog.Error("LineWrapMode get error!");
813 return (LineWrapMode)temp;
817 SetProperty(TextLabel.Property.LINE_WRAP_MODE, new Tizen.NUI.PropertyValue((int)value));
822 /// The text direction.
824 /// <since_tizen> 5 </since_tizen>
825 [EditorBrowsable(EditorBrowsableState.Never)]
826 public TextDirection TextDirection
831 GetProperty(TextLabel.Property.TEXT_DIRECTION).Get(out temp);
832 return (TextDirection)temp;