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 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 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();
108 internal static readonly int TEXT_COLOR_ANIMATABLE = NDalicPINVOKE.TextLabel_Property_TEXT_COLOR_ANIMATABLE_get();
109 internal static readonly int LINE_COUNT = OUTLINE + 5;
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();
114 >>>>>>> parent of b621f76... Revert "[Tizen] Add properties of TextLabel/Editor"
116 internal static readonly int TEXT_COLOR_ANIMATABLE = NDalicPINVOKE.TextLabel_Property_TEXT_COLOR_ANIMATABLE_get();
118 >>>>>>> parent of bb0612e... Revert "[Tizen] Animatable TextColor Property for TextLabel"
122 /// Creates the TextLabel control.
124 public TextLabel() : this(NDalicPINVOKE.TextLabel_New__SWIG_0(), true)
126 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
131 /// Creates the TextLabel control.
133 /// <param name="text">The text to display</param>
134 public TextLabel(string text) : this(NDalicPINVOKE.TextLabel_New__SWIG_1(text), true)
136 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
139 internal TextLabel(TextLabel handle) : this(NDalicPINVOKE.new_TextLabel__SWIG_1(TextLabel.getCPtr(handle)), true)
141 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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 /// TranslatableText property.<br>
155 /// The text can be set SID value.<br>
157 /// <exception cref='ArgumentNullException'>
158 /// ResourceManager about multilingual is null
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 /// Text property.<br>
197 /// The text to display in UTF-8 format.<br>
204 GetProperty(TextLabel.Property.TEXT).Get(out temp);
209 SetProperty(TextLabel.Property.TEXT, new Tizen.NUI.PropertyValue(value));
214 /// FontFamily property.<br>
215 /// The requested font family to use.<br>
217 public string FontFamily
222 GetProperty(TextLabel.Property.FONT_FAMILY).Get(out temp);
227 SetProperty(TextLabel.Property.FONT_FAMILY, new Tizen.NUI.PropertyValue(value));
232 /// FontStyle property.<br>
233 /// The requested font style to use.<br>
235 public PropertyMap FontStyle
239 PropertyMap temp = new PropertyMap();
240 GetProperty(TextLabel.Property.FONT_STYLE).Get(temp);
245 SetProperty(TextLabel.Property.FONT_STYLE, new Tizen.NUI.PropertyValue(value));
250 /// PointSize property.<br>
251 /// The size of font in points.<br>
253 public float PointSize
258 GetProperty(TextLabel.Property.POINT_SIZE).Get(out temp);
263 SetProperty(TextLabel.Property.POINT_SIZE, new Tizen.NUI.PropertyValue(value));
268 /// MultiLine property.<br>
269 /// The single-line or multi-line layout option.<br>
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 /// HorizontalAlignment property.<br>
287 /// The line horizontal alignment.<br>
289 public HorizontalAlignment HorizontalAlignment
294 if (GetProperty(TextLabel.Property.HORIZONTAL_ALIGNMENT).Get(out temp) == false)
296 NUILog.Error("HorizontalAlignment get error!");
301 return HorizontalAlignment.Begin;
303 return HorizontalAlignment.Center;
305 return HorizontalAlignment.End;
307 return HorizontalAlignment.Begin;
312 string valueToString = "";
315 case HorizontalAlignment.Begin:
317 valueToString = "BEGIN";
320 case HorizontalAlignment.Center:
322 valueToString = "CENTER";
325 case HorizontalAlignment.End:
327 valueToString = "END";
332 valueToString = "BEGIN";
336 SetProperty(TextLabel.Property.HORIZONTAL_ALIGNMENT, new Tizen.NUI.PropertyValue(valueToString));
341 /// VerticalAlignment property.<br>
342 /// The line vertical alignment.<br>
344 public VerticalAlignment VerticalAlignment
349 if (GetProperty(TextLabel.Property.VERTICAL_ALIGNMENT).Get(out temp) == false)
351 NUILog.Error("VerticalAlignment get error!");
357 return VerticalAlignment.Top;
359 return VerticalAlignment.Center;
361 return VerticalAlignment.Bottom;
363 return VerticalAlignment.Bottom;
368 string valueToString = "";
371 case VerticalAlignment.Top:
373 valueToString = "TOP";
376 case VerticalAlignment.Center:
378 valueToString = "CENTER";
381 case VerticalAlignment.Bottom:
383 valueToString = "BOTTOM";
388 valueToString = "BOTTOM";
392 SetProperty(TextLabel.Property.VERTICAL_ALIGNMENT, new Tizen.NUI.PropertyValue(valueToString));
397 /// TextColor property.<br>
398 /// The color of the text.<br>
400 public Color TextColor
404 Color temp = new Color(0.0f, 0.0f, 0.0f, 0.0f);
405 GetProperty(TextLabel.Property.TEXT_COLOR).Get(temp);
410 SetProperty(TextLabel.Property.TEXT_COLOR, new Tizen.NUI.PropertyValue(value));
415 /// ShadowOffset property.<br>
416 /// The drop shadow offset 0 indicates no shadow.<br>
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 /// ShadowColor property.<br>
434 /// The color of a drop shadow.<br>
436 public Vector4 ShadowColor
440 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
441 GetProperty(TextLabel.Property.SHADOW_COLOR).Get(temp);
446 SetProperty(TextLabel.Property.SHADOW_COLOR, new Tizen.NUI.PropertyValue(value));
451 /// UnderlineEnabled property.<br>
452 /// The underline enabled flag.<br>
454 public bool UnderlineEnabled
459 GetProperty(TextLabel.Property.UNDERLINE_ENABLED).Get(out temp);
464 SetProperty(TextLabel.Property.UNDERLINE_ENABLED, new Tizen.NUI.PropertyValue(value));
469 /// UnderlineColor property.<br>
470 /// Overrides the underline height from font metrics.<br>
472 public Vector4 UnderlineColor
476 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
477 GetProperty(TextLabel.Property.UNDERLINE_COLOR).Get(temp);
482 SetProperty(TextLabel.Property.UNDERLINE_COLOR, new Tizen.NUI.PropertyValue(value));
487 /// UnderlineHeight property.<br>
488 /// Overrides the underline height from font metrics.<br>
490 public float UnderlineHeight
495 GetProperty(TextLabel.Property.UNDERLINE_HEIGHT).Get(out temp);
500 SetProperty(TextLabel.Property.UNDERLINE_HEIGHT, new Tizen.NUI.PropertyValue(value));
505 /// EnableMarkup property.<br>
506 /// Whether the mark-up processing is enabled.<br>
508 public bool EnableMarkup
513 GetProperty(TextLabel.Property.ENABLE_MARKUP).Get(out temp);
518 SetProperty(TextLabel.Property.ENABLE_MARKUP, new Tizen.NUI.PropertyValue(value));
523 /// EnableAutoScroll property.<br>
524 /// Starts or stops auto scrolling.<br>
526 public bool EnableAutoScroll
531 GetProperty(TextLabel.Property.ENABLE_AUTO_SCROLL).Get(out temp);
536 SetProperty(TextLabel.Property.ENABLE_AUTO_SCROLL, new Tizen.NUI.PropertyValue(value));
541 /// AutoScrollSpeed property.<br>
542 /// Sets the speed of scrolling in pixels per second.<br>
544 public int AutoScrollSpeed
549 GetProperty(TextLabel.Property.AUTO_SCROLL_SPEED).Get(out temp);
554 SetProperty(TextLabel.Property.AUTO_SCROLL_SPEED, new Tizen.NUI.PropertyValue(value));
559 /// AutoScrollLoopCount property.<br>
560 /// Number of complete loops when scrolling enabled.<br>
562 public int AutoScrollLoopCount
567 GetProperty(TextLabel.Property.AUTO_SCROLL_LOOP_COUNT).Get(out temp);
572 SetProperty(TextLabel.Property.AUTO_SCROLL_LOOP_COUNT, new Tizen.NUI.PropertyValue(value));
577 /// AutoScrollGap property.<br>
578 /// Gap before scrolling wraps.<br>
580 public float AutoScrollGap
585 GetProperty(TextLabel.Property.AUTO_SCROLL_GAP).Get(out temp);
590 SetProperty(TextLabel.Property.AUTO_SCROLL_GAP, new Tizen.NUI.PropertyValue(value));
595 /// LineSpacing property.<br>
596 /// The default extra space between lines in points.<br>
598 public float LineSpacing
603 GetProperty(TextLabel.Property.LINE_SPACING).Get(out temp);
608 SetProperty(TextLabel.Property.LINE_SPACING, new Tizen.NUI.PropertyValue(value));
613 /// Underline property.<br>
614 /// The default underline parameters.<br>
616 public PropertyMap Underline
620 PropertyMap temp = new PropertyMap();
621 GetProperty(TextLabel.Property.UNDERLINE).Get(temp);
626 SetProperty(TextLabel.Property.UNDERLINE, new Tizen.NUI.PropertyValue(value));
631 /// Shadow property.<br>
632 /// The default shadow parameters.<br>
634 public PropertyMap Shadow
638 PropertyMap temp = new PropertyMap();
639 GetProperty(TextLabel.Property.SHADOW).Get(temp);
644 SetProperty(TextLabel.Property.SHADOW, new Tizen.NUI.PropertyValue(value));
649 /// Emboss property.<br>
650 /// The default emboss parameters.<br>
657 GetProperty(TextLabel.Property.EMBOSS).Get( out temp);
662 SetProperty(TextLabel.Property.EMBOSS, new Tizen.NUI.PropertyValue(value));
667 /// Outline property.<br>
668 /// The default outline parameters.<br>
670 public string Outline
675 GetProperty(TextLabel.Property.OUTLINE).Get(out temp);
680 SetProperty(TextLabel.Property.OUTLINE, new Tizen.NUI.PropertyValue(value));
685 /// PixelSize property.<br>
686 /// The size of font in pixels.<br>
688 public float PixelSize
693 GetProperty(TextLabel.Property.PIXEL_SIZE).Get(out temp);
698 SetProperty(TextLabel.Property.PIXEL_SIZE, new Tizen.NUI.PropertyValue(value));
703 /// Ellipsis property.<br>
704 /// Enable or disable the ellipsis.<br>
711 GetProperty(TextLabel.Property.ELLIPSIS).Get(out temp);
716 SetProperty(TextLabel.Property.ELLIPSIS, new Tizen.NUI.PropertyValue(value));
721 /// AutoScrollLoopDelay property.<br>
722 /// do something.<br>
724 public float AutoScrollLoopDelay
729 GetProperty(TextLabel.Property.AUTO_SCROLL_LOOP_DELAY).Get(out temp);
734 SetProperty(TextLabel.Property.AUTO_SCROLL_LOOP_DELAY, new Tizen.NUI.PropertyValue(value));
739 /// AutoScrollStopMode property.<br>
740 /// do something.<br>
742 public AutoScrollStopMode AutoScrollStopMode
747 if(GetProperty(TextLabel.Property.AUTO_SCROLL_STOP_MODE).Get(out temp) == false)
749 NUILog.Error("AutoScrollStopMode get error!");
754 return AutoScrollStopMode.FinishLoop;
756 return AutoScrollStopMode.Immediate;
758 return AutoScrollStopMode.FinishLoop;
763 SetProperty(TextLabel.Property.AUTO_SCROLL_STOP_MODE, new Tizen.NUI.PropertyValue((int)value));
768 /// TextColorAnimatable property.<br>
769 /// The color of the text that can be animatated.<br>
770 /// Animation framework can be used to change the color of the text when not using mark up.<br>
771 /// Not possible when text is auto scrolling. <br>
773 public Color TextColorAnimatable
777 Color animatableColor = new Color(0.0f, 0.0f, 0.0f, 0.0f);
778 GetProperty(TextLabel.Property.TEXT_COLOR_ANIMATABLE).Get(animatableColor);
779 return animatableColor;
783 SetProperty(TextLabel.Property.TEXT_COLOR_ANIMATABLE, new Tizen.NUI.PropertyValue(value));
787 /// The line count of text.
794 GetProperty(TextLabel.Property.LINE_COUNT).Get(out temp);
800 /// LineWrapMode property.<br>
801 /// line wrap mode when the text lines over layout width.<br>
803 public LineWrapMode LineWrapMode
808 if(GetProperty(TextLabel.Property.LINE_WRAP_MODE).Get(out temp) == false)
810 NUILog.Error("LineWrapMode get error!");
814 case "WRAP_MODE_WORD":
815 return LineWrapMode.Word;
816 case "WRAP_MODE_CHARACTER":
817 return LineWrapMode.Character;
819 return LineWrapMode.Word;
827 case LineWrapMode.Word:
829 temp = "WRAP_MODE_WORD";
832 case LineWrapMode.Character:
834 temp = "WRAP_MODE_CHARACTER";
838 SetProperty(TextLabel.Property.LINE_WRAP_MODE, new Tizen.NUI.PropertyValue(temp));