1 /** Copyright (c) 2017 Samsung Electronics Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
17 extern alias TizenSystemSettings;
18 using TizenSystemSettings.Tizen.System;
20 using System.Globalization;
21 namespace Tizen.NUI.BaseComponents
25 /// A control which renders a short text string.<br>
26 /// Text labels are lightweight, non-editable, and do not respond to the user input.<br>
28 public class TextLabel : View
30 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
31 private string textLabelSid = null;
32 private bool systemlangTextFlag = false;
33 internal TextLabel(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.TextLabel_SWIGUpcast(cPtr), cMemoryOwn)
35 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
38 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(TextLabel obj)
40 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
46 protected override void Dispose(DisposeTypes type)
53 if(type == DisposeTypes.Explicit)
56 //Release your own managed resources here.
57 //You should release all of your own disposable objects here.
60 //Release your own unmanaged resources here.
61 //You should not access any managed member here except static instance.
62 //because the execution order of Finalizes is non-deterministic.
64 if (swigCPtr.Handle != global::System.IntPtr.Zero)
69 NDalicPINVOKE.delete_TextLabel(swigCPtr);
71 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
77 internal new class Property
79 internal static readonly int RENDERING_BACKEND = NDalicPINVOKE.TextLabel_Property_RENDERING_BACKEND_get();
80 internal static readonly int TEXT = NDalicPINVOKE.TextLabel_Property_TEXT_get();
81 internal static readonly int FONT_FAMILY = NDalicPINVOKE.TextLabel_Property_FONT_FAMILY_get();
82 internal static readonly int FONT_STYLE = NDalicPINVOKE.TextLabel_Property_FONT_STYLE_get();
83 internal static readonly int POINT_SIZE = NDalicPINVOKE.TextLabel_Property_POINT_SIZE_get();
84 internal static readonly int MULTI_LINE = NDalicPINVOKE.TextLabel_Property_MULTI_LINE_get();
85 internal static readonly int HORIZONTAL_ALIGNMENT = NDalicPINVOKE.TextLabel_Property_HORIZONTAL_ALIGNMENT_get();
86 internal static readonly int VERTICAL_ALIGNMENT = NDalicPINVOKE.TextLabel_Property_VERTICAL_ALIGNMENT_get();
87 internal static readonly int TEXT_COLOR = NDalicPINVOKE.TextLabel_Property_TEXT_COLOR_get();
88 internal static readonly int SHADOW_OFFSET = NDalicPINVOKE.TextLabel_Property_SHADOW_OFFSET_get();
89 internal static readonly int SHADOW_COLOR = NDalicPINVOKE.TextLabel_Property_SHADOW_COLOR_get();
90 internal static readonly int UNDERLINE_ENABLED = NDalicPINVOKE.TextLabel_Property_UNDERLINE_ENABLED_get();
91 internal static readonly int UNDERLINE_COLOR = NDalicPINVOKE.TextLabel_Property_UNDERLINE_COLOR_get();
92 internal static readonly int UNDERLINE_HEIGHT = NDalicPINVOKE.TextLabel_Property_UNDERLINE_HEIGHT_get();
93 internal static readonly int ENABLE_MARKUP = NDalicPINVOKE.TextLabel_Property_ENABLE_MARKUP_get();
94 internal static readonly int ENABLE_AUTO_SCROLL = NDalicPINVOKE.TextLabel_Property_ENABLE_AUTO_SCROLL_get();
95 internal static readonly int AUTO_SCROLL_SPEED = NDalicPINVOKE.TextLabel_Property_AUTO_SCROLL_SPEED_get();
96 internal static readonly int AUTO_SCROLL_LOOP_COUNT = NDalicPINVOKE.TextLabel_Property_AUTO_SCROLL_LOOP_COUNT_get();
97 internal static readonly int AUTO_SCROLL_GAP = NDalicPINVOKE.TextLabel_Property_AUTO_SCROLL_GAP_get();
98 internal static readonly int LINE_SPACING = NDalicPINVOKE.TextLabel_Property_LINE_SPACING_get();
99 internal static readonly int UNDERLINE = NDalicPINVOKE.TextLabel_Property_UNDERLINE_get();
100 internal static readonly int SHADOW = NDalicPINVOKE.TextLabel_Property_SHADOW_get();
101 internal static readonly int EMBOSS = NDalicPINVOKE.TextLabel_Property_EMBOSS_get();
102 internal static readonly int OUTLINE = NDalicPINVOKE.TextLabel_Property_OUTLINE_get();
103 internal static readonly int PIXEL_SIZE = NDalicManualPINVOKE.TextLabel_Property_PIXEL_SIZE_get();
104 internal static readonly int ELLIPSIS = NDalicManualPINVOKE.TextLabel_Property_ELLIPSIS_get();
105 internal static readonly int AUTO_SCROLL_STOP_MODE = NDalicManualPINVOKE.TextLabel_Property_AUTO_SCROLL_STOP_MODE_get();
106 internal static readonly int AUTO_SCROLL_LOOP_DELAY = NDalicManualPINVOKE.TextLabel_Property_AUTO_SCROLL_LOOP_DELAY_get();
107 internal static readonly int LINE_COUNT = NDalicManualPINVOKE.TextLabel_Property_LINE_COUNT_get();
108 internal static readonly int LINE_WRAP_MODE = NDalicManualPINVOKE.TextLabel_Property_LINE_WRAP_MODE_get();
109 internal static readonly int TEXT_COLOR_ANIMATABLE = NDalicPINVOKE.TextLabel_Property_TEXT_COLOR_ANIMATABLE_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")]
140 public new static TextLabel DownCast(BaseHandle handle)
142 TextLabel ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as TextLabel;
144 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
148 /// The TranslatableText property.<br>
149 /// The text can set the SID value.<br>
151 /// <exception cref='ArgumentNullException'>
152 /// ResourceManager about multilingual is null.
154 /// <since_tizen> 4 </since_tizen>
155 public string TranslatableText
163 if (NUIApplication.MultilingualResourceManager == null)
165 throw new ArgumentNullException("ResourceManager about multilingual is null");
167 string translatableText = null;
168 textLabelSid = value;
169 translatableText = NUIApplication.MultilingualResourceManager?.GetString(textLabelSid, new CultureInfo(SystemSettings.LocaleLanguage.Replace("_", "-")));
170 if (translatableText != null)
172 Text = translatableText;
173 if (systemlangTextFlag == false)
175 SystemSettings.LocaleLanguageChanged += new WeakEventHandler<LocaleLanguageChangedEventArgs>(SystemSettings_LocaleLanguageChanged).Handler;
176 systemlangTextFlag = true;
185 private void SystemSettings_LocaleLanguageChanged(object sender, LocaleLanguageChangedEventArgs e)
187 Text = NUIApplication.MultilingualResourceManager?.GetString(textLabelSid, new CultureInfo(e.Value.Replace("_", "-")));
191 /// The Text property.<br>
192 /// The text to display in the UTF-8 format.<br>
194 /// <since_tizen> 3 </since_tizen>
200 GetProperty(TextLabel.Property.TEXT).Get(out temp);
205 SetProperty(TextLabel.Property.TEXT, new Tizen.NUI.PropertyValue(value));
210 /// The FontFamily property.<br>
211 /// The requested font family to use.<br>
213 /// <since_tizen> 3 </since_tizen>
214 public string FontFamily
219 GetProperty(TextLabel.Property.FONT_FAMILY).Get(out temp);
224 SetProperty(TextLabel.Property.FONT_FAMILY, new Tizen.NUI.PropertyValue(value));
229 /// The FontStyle property.<br>
230 /// The requested font style to use.<br>
232 /// <since_tizen> 3 </since_tizen>
233 public PropertyMap FontStyle
237 PropertyMap temp = new PropertyMap();
238 GetProperty(TextLabel.Property.FONT_STYLE).Get(temp);
243 SetProperty(TextLabel.Property.FONT_STYLE, new Tizen.NUI.PropertyValue(value));
248 /// The PointSize property.<br>
249 /// The size of font in points.<br>
251 /// <since_tizen> 3 </since_tizen>
252 public float PointSize
257 GetProperty(TextLabel.Property.POINT_SIZE).Get(out temp);
262 SetProperty(TextLabel.Property.POINT_SIZE, new Tizen.NUI.PropertyValue(value));
267 /// The MultiLine property.<br>
268 /// The single-line or multi-line layout option.<br>
270 /// <since_tizen> 3 </since_tizen>
271 public bool MultiLine
276 GetProperty(TextLabel.Property.MULTI_LINE).Get(out temp);
281 SetProperty(TextLabel.Property.MULTI_LINE, new Tizen.NUI.PropertyValue(value));
286 /// The HorizontalAlignment property.<br>
287 /// The line horizontal alignment.<br>
289 /// <since_tizen> 3 </since_tizen>
290 public HorizontalAlignment HorizontalAlignment
295 if (GetProperty(TextLabel.Property.HORIZONTAL_ALIGNMENT).Get(out temp) == false)
297 NUILog.Error("HorizontalAlignment get error!");
302 return HorizontalAlignment.Begin;
304 return HorizontalAlignment.Center;
306 return HorizontalAlignment.End;
308 return HorizontalAlignment.Begin;
313 string valueToString = "";
316 case HorizontalAlignment.Begin:
318 valueToString = "BEGIN";
321 case HorizontalAlignment.Center:
323 valueToString = "CENTER";
326 case HorizontalAlignment.End:
328 valueToString = "END";
333 valueToString = "BEGIN";
337 SetProperty(TextLabel.Property.HORIZONTAL_ALIGNMENT, new Tizen.NUI.PropertyValue(valueToString));
342 /// The VerticalAlignment property.<br>
343 /// The line vertical alignment.<br>
345 /// <since_tizen> 3 </since_tizen>
346 public VerticalAlignment VerticalAlignment
351 if (GetProperty(TextLabel.Property.VERTICAL_ALIGNMENT).Get(out temp) == false)
353 NUILog.Error("VerticalAlignment get error!");
359 return VerticalAlignment.Top;
361 return VerticalAlignment.Center;
363 return VerticalAlignment.Bottom;
365 return VerticalAlignment.Bottom;
370 string valueToString = "";
373 case VerticalAlignment.Top:
375 valueToString = "TOP";
378 case VerticalAlignment.Center:
380 valueToString = "CENTER";
383 case VerticalAlignment.Bottom:
385 valueToString = "BOTTOM";
390 valueToString = "BOTTOM";
394 SetProperty(TextLabel.Property.VERTICAL_ALIGNMENT, new Tizen.NUI.PropertyValue(valueToString));
399 /// The TextColor property.<br>
400 /// The color of the text.<br>
402 /// <since_tizen> 3 </since_tizen>
403 public Color TextColor
407 Color temp = new Color(0.0f, 0.0f, 0.0f, 0.0f);
408 GetProperty(TextLabel.Property.TEXT_COLOR).Get(temp);
413 SetProperty(TextLabel.Property.TEXT_COLOR, new Tizen.NUI.PropertyValue(value));
418 /// The ShadowOffset property.<br>
419 /// The drop shadow offset 0 indicates no shadow.<br>
421 /// <since_tizen> 3 </since_tizen>
422 public Vector2 ShadowOffset
426 Vector2 temp = new Vector2(0.0f, 0.0f);
427 GetProperty(TextLabel.Property.SHADOW_OFFSET).Get(temp);
432 SetProperty(TextLabel.Property.SHADOW_OFFSET, new Tizen.NUI.PropertyValue(value));
437 /// The ShadowColor property.<br>
438 /// The color of a drop shadow.<br>
440 /// <since_tizen> 3 </since_tizen>
441 public Vector4 ShadowColor
445 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
446 GetProperty(TextLabel.Property.SHADOW_COLOR).Get(temp);
451 SetProperty(TextLabel.Property.SHADOW_COLOR, new Tizen.NUI.PropertyValue(value));
456 /// The UnderlineEnabled property.<br>
457 /// The underline enabled flag.<br>
459 /// <since_tizen> 3 </since_tizen>
460 public bool UnderlineEnabled
465 GetProperty(TextLabel.Property.UNDERLINE_ENABLED).Get(out temp);
470 SetProperty(TextLabel.Property.UNDERLINE_ENABLED, new Tizen.NUI.PropertyValue(value));
475 /// The UnderlineColor property.<br>
476 /// Overrides the underline height from font metrics.<br>
478 /// <since_tizen> 3 </since_tizen>
479 public Vector4 UnderlineColor
483 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
484 GetProperty(TextLabel.Property.UNDERLINE_COLOR).Get(temp);
489 SetProperty(TextLabel.Property.UNDERLINE_COLOR, new Tizen.NUI.PropertyValue(value));
494 /// The UnderlineHeight property.<br>
495 /// Overrides the underline height from font metrics.<br>
497 /// <since_tizen> 3 </since_tizen>
498 public float UnderlineHeight
503 GetProperty(TextLabel.Property.UNDERLINE_HEIGHT).Get(out temp);
508 SetProperty(TextLabel.Property.UNDERLINE_HEIGHT, new Tizen.NUI.PropertyValue(value));
513 /// The EnableMarkup property.<br>
514 /// Whether the mark-up processing is enabled.<br>
516 /// <since_tizen> 3 </since_tizen>
517 public bool EnableMarkup
522 GetProperty(TextLabel.Property.ENABLE_MARKUP).Get(out temp);
527 SetProperty(TextLabel.Property.ENABLE_MARKUP, new Tizen.NUI.PropertyValue(value));
532 /// The EnableAutoScroll property.<br>
533 /// Starts or stops auto scrolling.<br>
535 /// <since_tizen> 3 </since_tizen>
536 public bool EnableAutoScroll
541 GetProperty(TextLabel.Property.ENABLE_AUTO_SCROLL).Get(out temp);
546 SetProperty(TextLabel.Property.ENABLE_AUTO_SCROLL, new Tizen.NUI.PropertyValue(value));
551 /// The AutoScrollSpeed property.<br>
552 /// Sets the speed of scrolling in pixels per second.<br>
554 /// <since_tizen> 3 </since_tizen>
555 public int AutoScrollSpeed
560 GetProperty(TextLabel.Property.AUTO_SCROLL_SPEED).Get(out temp);
565 SetProperty(TextLabel.Property.AUTO_SCROLL_SPEED, new Tizen.NUI.PropertyValue(value));
570 /// The AutoScrollLoopCount property.<br>
571 /// Number of complete loops when scrolling enabled.<br>
573 /// <since_tizen> 3 </since_tizen>
574 public int AutoScrollLoopCount
579 GetProperty(TextLabel.Property.AUTO_SCROLL_LOOP_COUNT).Get(out temp);
584 SetProperty(TextLabel.Property.AUTO_SCROLL_LOOP_COUNT, new Tizen.NUI.PropertyValue(value));
589 /// The AutoScrollGap property.<br>
590 /// Gap before scrolling wraps.<br>
592 /// <since_tizen> 3 </since_tizen>
593 public float AutoScrollGap
598 GetProperty(TextLabel.Property.AUTO_SCROLL_GAP).Get(out temp);
603 SetProperty(TextLabel.Property.AUTO_SCROLL_GAP, new Tizen.NUI.PropertyValue(value));
608 /// The LineSpacing property.<br>
609 /// The default extra space between lines in points.<br>
611 /// <since_tizen> 3 </since_tizen>
612 public float LineSpacing
617 GetProperty(TextLabel.Property.LINE_SPACING).Get(out temp);
622 SetProperty(TextLabel.Property.LINE_SPACING, new Tizen.NUI.PropertyValue(value));
627 /// The Underline property.<br>
628 /// The default underline parameters.<br>
630 /// <since_tizen> 3 </since_tizen>
631 public PropertyMap Underline
635 PropertyMap temp = new PropertyMap();
636 GetProperty(TextLabel.Property.UNDERLINE).Get(temp);
641 SetProperty(TextLabel.Property.UNDERLINE, new Tizen.NUI.PropertyValue(value));
646 /// The Shadow property.<br>
647 /// The default shadow parameters.<br>
649 /// <since_tizen> 3 </since_tizen>
650 public PropertyMap Shadow
654 PropertyMap temp = new PropertyMap();
655 GetProperty(TextLabel.Property.SHADOW).Get(temp);
660 SetProperty(TextLabel.Property.SHADOW, new Tizen.NUI.PropertyValue(value));
665 /// The Emboss property.<br>
666 /// The default emboss parameters.<br>
668 /// <since_tizen> 3 </since_tizen>
674 GetProperty(TextLabel.Property.EMBOSS).Get( out temp);
679 SetProperty(TextLabel.Property.EMBOSS, new Tizen.NUI.PropertyValue(value));
684 /// The Outline property.<br>
685 /// The default outline parameters.<br>
687 /// <since_tizen> 3 </since_tizen>
688 public string Outline
693 GetProperty(TextLabel.Property.OUTLINE).Get(out temp);
698 SetProperty(TextLabel.Property.OUTLINE, new Tizen.NUI.PropertyValue(value));
703 /// The PixelSize property.<br>
704 /// The size of font in pixels.<br>
706 /// <since_tizen> 3 </since_tizen>
707 public float PixelSize
712 GetProperty(TextLabel.Property.PIXEL_SIZE).Get(out temp);
717 SetProperty(TextLabel.Property.PIXEL_SIZE, new Tizen.NUI.PropertyValue(value));
722 /// The Ellipsis property.<br>
723 /// Enable or disable the ellipsis.<br>
725 /// <since_tizen> 3 </since_tizen>
731 GetProperty(TextLabel.Property.ELLIPSIS).Get(out temp);
736 SetProperty(TextLabel.Property.ELLIPSIS, new Tizen.NUI.PropertyValue(value));
741 /// The AutoScrollLoopDelay property.<br>
742 /// Do something.<br>
744 /// <since_tizen> 3 </since_tizen>
745 public float AutoScrollLoopDelay
750 GetProperty(TextLabel.Property.AUTO_SCROLL_LOOP_DELAY).Get(out temp);
755 SetProperty(TextLabel.Property.AUTO_SCROLL_LOOP_DELAY, new Tizen.NUI.PropertyValue(value));
760 /// The AutoScrollStopMode property.<br>
761 /// Do something.<br>
763 /// <since_tizen> 3 </since_tizen>
764 public AutoScrollStopMode AutoScrollStopMode
769 if(GetProperty(TextLabel.Property.AUTO_SCROLL_STOP_MODE).Get(out temp) == false)
771 NUILog.Error("AutoScrollStopMode get error!");
776 return AutoScrollStopMode.FinishLoop;
778 return AutoScrollStopMode.Immediate;
780 return AutoScrollStopMode.FinishLoop;
785 SetProperty(TextLabel.Property.AUTO_SCROLL_STOP_MODE, new Tizen.NUI.PropertyValue((int)value));
790 /// The TextColorAnimatable property.<br>
791 /// The color of the text that can be animatated.<br>
792 /// Animation framework can be used to change the color of the text when not using mark up.<br>
793 /// Not possible when text is auto scrolling. <br>
795 /// <since_tizen> 4 </since_tizen>
796 public Color TextColorAnimatable
800 Color animatableColor = new Color(0.0f, 0.0f, 0.0f, 0.0f);
801 GetProperty(TextLabel.Property.TEXT_COLOR_ANIMATABLE).Get(animatableColor);
802 return animatableColor;
806 SetProperty(TextLabel.Property.TEXT_COLOR_ANIMATABLE, new Tizen.NUI.PropertyValue(value));
810 /// The line count of the text.
812 /// <since_tizen> 4 </since_tizen>
818 GetProperty(TextLabel.Property.LINE_COUNT).Get(out temp);
824 /// The LineWrapMode property.<br>
825 /// line wrap mode when the text lines over layout width.<br>
827 /// <since_tizen> 4 </since_tizen>
828 public LineWrapMode LineWrapMode
833 if(GetProperty(TextLabel.Property.LINE_WRAP_MODE).Get(out temp) == false)
835 NUILog.Error("LineWrapMode get error!");
839 case "WRAP_MODE_WORD":
840 return LineWrapMode.Word;
841 case "WRAP_MODE_CHARACTER":
842 return LineWrapMode.Character;
844 return LineWrapMode.Word;
852 case LineWrapMode.Word:
854 temp = "WRAP_MODE_WORD";
857 case LineWrapMode.Character:
859 temp = "WRAP_MODE_CHARACTER";
863 SetProperty(TextLabel.Property.LINE_WRAP_MODE, new Tizen.NUI.PropertyValue(temp));