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 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 public TextLabel() : this(NDalicPINVOKE.TextLabel_New__SWIG_0(), true)
118 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
123 /// Creates the TextLabel control.
125 /// <param name="text">The text to display</param>
126 public TextLabel(string text) : this(NDalicPINVOKE.TextLabel_New__SWIG_1(text), true)
128 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
131 internal TextLabel(TextLabel handle) : this(NDalicPINVOKE.new_TextLabel__SWIG_1(TextLabel.getCPtr(handle)), true)
133 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
137 [Obsolete("Please do not use! this will be deprecated")]
138 public new static TextLabel DownCast(BaseHandle handle)
140 TextLabel ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as TextLabel;
142 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
146 /// TranslatableText property.<br>
147 /// The text can be set SID value.<br>
149 /// <exception cref='ArgumentNullException'>
150 /// ResourceManager about multilingual is null
152 public string TranslatableText
160 if (NUIApplication.MultilingualResourceManager == null)
162 throw new ArgumentNullException("ResourceManager about multilingual is null");
164 string translatableText = null;
165 textLabelSid = value;
166 translatableText = NUIApplication.MultilingualResourceManager?.GetString(textLabelSid, new CultureInfo(SystemSettings.LocaleLanguage.Replace("_", "-")));
167 if (translatableText != null)
169 Text = translatableText;
170 if (systemlangTextFlag == false)
172 SystemSettings.LocaleLanguageChanged += new WeakEventHandler<LocaleLanguageChangedEventArgs>(SystemSettings_LocaleLanguageChanged).Handler;
173 systemlangTextFlag = true;
182 private void SystemSettings_LocaleLanguageChanged(object sender, LocaleLanguageChangedEventArgs e)
184 Text = NUIApplication.MultilingualResourceManager?.GetString(textLabelSid, new CultureInfo(e.Value.Replace("_", "-")));
188 /// Text property.<br>
189 /// The text to display in UTF-8 format.<br>
196 GetProperty(TextLabel.Property.TEXT).Get(out temp);
201 SetProperty(TextLabel.Property.TEXT, new Tizen.NUI.PropertyValue(value));
206 /// FontFamily property.<br>
207 /// The requested font family to use.<br>
209 public string FontFamily
214 GetProperty(TextLabel.Property.FONT_FAMILY).Get(out temp);
219 SetProperty(TextLabel.Property.FONT_FAMILY, new Tizen.NUI.PropertyValue(value));
224 /// FontStyle property.<br>
225 /// The requested font style to use.<br>
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 /// PointSize property.<br>
243 /// The size of font in points.<br>
245 public float PointSize
250 GetProperty(TextLabel.Property.POINT_SIZE).Get(out temp);
255 SetProperty(TextLabel.Property.POINT_SIZE, new Tizen.NUI.PropertyValue(value));
260 /// MultiLine property.<br>
261 /// The single-line or multi-line layout option.<br>
263 public bool MultiLine
268 GetProperty(TextLabel.Property.MULTI_LINE).Get(out temp);
273 SetProperty(TextLabel.Property.MULTI_LINE, new Tizen.NUI.PropertyValue(value));
278 /// HorizontalAlignment property.<br>
279 /// The line horizontal alignment.<br>
281 public HorizontalAlignment HorizontalAlignment
286 if (GetProperty(TextLabel.Property.HORIZONTAL_ALIGNMENT).Get(out temp) == false)
288 NUILog.Error("HorizontalAlignment get error!");
293 return HorizontalAlignment.Begin;
295 return HorizontalAlignment.Center;
297 return HorizontalAlignment.End;
299 return HorizontalAlignment.Begin;
304 string valueToString = "";
307 case HorizontalAlignment.Begin:
309 valueToString = "BEGIN";
312 case HorizontalAlignment.Center:
314 valueToString = "CENTER";
317 case HorizontalAlignment.End:
319 valueToString = "END";
324 valueToString = "BEGIN";
328 SetProperty(TextLabel.Property.HORIZONTAL_ALIGNMENT, new Tizen.NUI.PropertyValue(valueToString));
333 /// VerticalAlignment property.<br>
334 /// The line vertical alignment.<br>
336 public VerticalAlignment VerticalAlignment
341 if (GetProperty(TextLabel.Property.VERTICAL_ALIGNMENT).Get(out temp) == false)
343 NUILog.Error("VerticalAlignment get error!");
349 return VerticalAlignment.Top;
351 return VerticalAlignment.Center;
353 return VerticalAlignment.Bottom;
355 return VerticalAlignment.Bottom;
360 string valueToString = "";
363 case VerticalAlignment.Top:
365 valueToString = "TOP";
368 case VerticalAlignment.Center:
370 valueToString = "CENTER";
373 case VerticalAlignment.Bottom:
375 valueToString = "BOTTOM";
380 valueToString = "BOTTOM";
384 SetProperty(TextLabel.Property.VERTICAL_ALIGNMENT, new Tizen.NUI.PropertyValue(valueToString));
389 /// TextColor property.<br>
390 /// The color of the text.<br>
392 public Color TextColor
396 Color temp = new Color(0.0f, 0.0f, 0.0f, 0.0f);
397 GetProperty(TextLabel.Property.TEXT_COLOR).Get(temp);
402 SetProperty(TextLabel.Property.TEXT_COLOR, new Tizen.NUI.PropertyValue(value));
407 /// ShadowOffset property.<br>
408 /// The drop shadow offset 0 indicates no shadow.<br>
410 public Vector2 ShadowOffset
414 Vector2 temp = new Vector2(0.0f, 0.0f);
415 GetProperty(TextLabel.Property.SHADOW_OFFSET).Get(temp);
420 SetProperty(TextLabel.Property.SHADOW_OFFSET, new Tizen.NUI.PropertyValue(value));
425 /// ShadowColor property.<br>
426 /// The color of a drop shadow.<br>
428 public Vector4 ShadowColor
432 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
433 GetProperty(TextLabel.Property.SHADOW_COLOR).Get(temp);
438 SetProperty(TextLabel.Property.SHADOW_COLOR, new Tizen.NUI.PropertyValue(value));
443 /// UnderlineEnabled property.<br>
444 /// The underline enabled flag.<br>
446 public bool UnderlineEnabled
451 GetProperty(TextLabel.Property.UNDERLINE_ENABLED).Get(out temp);
456 SetProperty(TextLabel.Property.UNDERLINE_ENABLED, new Tizen.NUI.PropertyValue(value));
461 /// UnderlineColor property.<br>
462 /// Overrides the underline height from font metrics.<br>
464 public Vector4 UnderlineColor
468 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
469 GetProperty(TextLabel.Property.UNDERLINE_COLOR).Get(temp);
474 SetProperty(TextLabel.Property.UNDERLINE_COLOR, new Tizen.NUI.PropertyValue(value));
479 /// UnderlineHeight property.<br>
480 /// Overrides the underline height from font metrics.<br>
482 public float UnderlineHeight
487 GetProperty(TextLabel.Property.UNDERLINE_HEIGHT).Get(out temp);
492 SetProperty(TextLabel.Property.UNDERLINE_HEIGHT, new Tizen.NUI.PropertyValue(value));
497 /// EnableMarkup property.<br>
498 /// Whether the mark-up processing is enabled.<br>
500 public bool EnableMarkup
505 GetProperty(TextLabel.Property.ENABLE_MARKUP).Get(out temp);
510 SetProperty(TextLabel.Property.ENABLE_MARKUP, new Tizen.NUI.PropertyValue(value));
515 /// EnableAutoScroll property.<br>
516 /// Starts or stops auto scrolling.<br>
518 public bool EnableAutoScroll
523 GetProperty(TextLabel.Property.ENABLE_AUTO_SCROLL).Get(out temp);
528 SetProperty(TextLabel.Property.ENABLE_AUTO_SCROLL, new Tizen.NUI.PropertyValue(value));
533 /// AutoScrollSpeed property.<br>
534 /// Sets the speed of scrolling in pixels per second.<br>
536 public int AutoScrollSpeed
541 GetProperty(TextLabel.Property.AUTO_SCROLL_SPEED).Get(out temp);
546 SetProperty(TextLabel.Property.AUTO_SCROLL_SPEED, new Tizen.NUI.PropertyValue(value));
551 /// AutoScrollLoopCount property.<br>
552 /// Number of complete loops when scrolling enabled.<br>
554 public int AutoScrollLoopCount
559 GetProperty(TextLabel.Property.AUTO_SCROLL_LOOP_COUNT).Get(out temp);
564 SetProperty(TextLabel.Property.AUTO_SCROLL_LOOP_COUNT, new Tizen.NUI.PropertyValue(value));
569 /// AutoScrollGap property.<br>
570 /// Gap before scrolling wraps.<br>
572 public float AutoScrollGap
577 GetProperty(TextLabel.Property.AUTO_SCROLL_GAP).Get(out temp);
582 SetProperty(TextLabel.Property.AUTO_SCROLL_GAP, new Tizen.NUI.PropertyValue(value));
587 /// LineSpacing property.<br>
588 /// The default extra space between lines in points.<br>
590 public float LineSpacing
595 GetProperty(TextLabel.Property.LINE_SPACING).Get(out temp);
600 SetProperty(TextLabel.Property.LINE_SPACING, new Tizen.NUI.PropertyValue(value));
605 /// Underline property.<br>
606 /// The default underline parameters.<br>
608 public PropertyMap Underline
612 PropertyMap temp = new PropertyMap();
613 GetProperty(TextLabel.Property.UNDERLINE).Get(temp);
618 SetProperty(TextLabel.Property.UNDERLINE, new Tizen.NUI.PropertyValue(value));
623 /// Shadow property.<br>
624 /// The default shadow parameters.<br>
626 public PropertyMap Shadow
630 PropertyMap temp = new PropertyMap();
631 GetProperty(TextLabel.Property.SHADOW).Get(temp);
636 SetProperty(TextLabel.Property.SHADOW, new Tizen.NUI.PropertyValue(value));
641 /// Emboss property.<br>
642 /// The default emboss parameters.<br>
649 GetProperty(TextLabel.Property.EMBOSS).Get( out temp);
654 SetProperty(TextLabel.Property.EMBOSS, new Tizen.NUI.PropertyValue(value));
659 /// Outline property.<br>
660 /// The default outline parameters.<br>
662 public string Outline
667 GetProperty(TextLabel.Property.OUTLINE).Get(out temp);
672 SetProperty(TextLabel.Property.OUTLINE, new Tizen.NUI.PropertyValue(value));
677 /// PixelSize property.<br>
678 /// The size of font in pixels.<br>
680 public float PixelSize
685 GetProperty(TextLabel.Property.PIXEL_SIZE).Get(out temp);
690 SetProperty(TextLabel.Property.PIXEL_SIZE, new Tizen.NUI.PropertyValue(value));
695 /// Ellipsis property.<br>
696 /// Enable or disable the ellipsis.<br>
703 GetProperty(TextLabel.Property.ELLIPSIS).Get(out temp);
708 SetProperty(TextLabel.Property.ELLIPSIS, new Tizen.NUI.PropertyValue(value));
713 /// AutoScrollLoopDelay property.<br>
714 /// do something.<br>
716 public float AutoScrollLoopDelay
721 GetProperty(TextLabel.Property.AUTO_SCROLL_LOOP_DELAY).Get(out temp);
726 SetProperty(TextLabel.Property.AUTO_SCROLL_LOOP_DELAY, new Tizen.NUI.PropertyValue(value));
731 /// AutoScrollStopMode property.<br>
732 /// do something.<br>
734 public AutoScrollStopMode AutoScrollStopMode
739 if(GetProperty(TextLabel.Property.AUTO_SCROLL_STOP_MODE).Get(out temp) == false)
741 NUILog.Error("AutoScrollStopMode get error!");
746 return AutoScrollStopMode.FinishLoop;
748 return AutoScrollStopMode.Immediate;
750 return AutoScrollStopMode.FinishLoop;
755 SetProperty(TextLabel.Property.AUTO_SCROLL_STOP_MODE, new Tizen.NUI.PropertyValue((int)value));
760 /// TextColorAnimatable property.<br>
761 /// The color of the text that can be animatated.<br>
762 /// Animation framework can be used to change the color of the text when not using mark up.<br>
763 /// Not possible when text is auto scrolling. <br>
765 public Color TextColorAnimatable
769 Color animatableColor = new Color(0.0f, 0.0f, 0.0f, 0.0f);
770 GetProperty(TextLabel.Property.TEXT_COLOR_ANIMATABLE).Get(animatableColor);
771 return animatableColor;
775 SetProperty(TextLabel.Property.TEXT_COLOR_ANIMATABLE, new Tizen.NUI.PropertyValue(value));
779 /// The line count of text.
786 GetProperty(TextLabel.Property.LINE_COUNT).Get(out temp);
792 /// LineWrapMode property.<br>
793 /// line wrap mode when the text lines over layout width.<br>
795 public LineWrapMode LineWrapMode
800 if(GetProperty(TextLabel.Property.LINE_WRAP_MODE).Get(out temp) == false)
802 NUILog.Error("LineWrapMode get error!");
806 case "WRAP_MODE_WORD":
807 return LineWrapMode.Word;
808 case "WRAP_MODE_CHARACTER":
809 return LineWrapMode.Character;
811 return LineWrapMode.Word;
819 case LineWrapMode.Word:
821 temp = "WRAP_MODE_WORD";
824 case LineWrapMode.Character:
826 temp = "WRAP_MODE_CHARACTER";
830 SetProperty(TextLabel.Property.LINE_WRAP_MODE, new Tizen.NUI.PropertyValue(temp));