X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2FTizen.NUI%2Fsrc%2Fpublic%2FBaseComponents%2FTextLabel.cs;h=ebb6b79d02c711e9e58a752f85c4169a28706ed5;hb=758886b19557b20f9f767dafd31da792d874174c;hp=b85325e059b9583ddb284b5bf9a17a5917d76302;hpb=390d8b354bcf125cf24978fd6c9eeef72b6199a3;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs b/src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs index b85325e..ebb6b79 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs @@ -1,5 +1,5 @@ /* - * Copyright(c) 2020 Samsung Electronics Co., Ltd. + * Copyright(c) 2021 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,9 +17,11 @@ extern alias TizenSystemSettings; using TizenSystemSettings.Tizen.System; + using System; using System.Globalization; using System.ComponentModel; +using Tizen.NUI.Text; using Tizen.NUI.Binding; namespace Tizen.NUI.BaseComponents @@ -31,7 +33,7 @@ namespace Tizen.NUI.BaseComponents /// 3 public partial class TextLabel : View { - private class TextLayout : LayoutItem + internal class TextLabelLayout : LayoutItem { protected override void OnMeasure(MeasureSpecification widthMeasureSpec, MeasureSpecification heightMeasureSpec) { @@ -49,17 +51,20 @@ namespace Tizen.NUI.BaseComponents } else { + var minSize = Owner.MinimumSize; + var maxSize = Owner.MaximumSize; + var naturalSize = Owner.GetNaturalSize(); + if (heightMeasureSpec.Mode == MeasureSpecification.ModeType.Exactly) { // GetWidthForHeight is not implemented. - totalWidth = Owner.GetNaturalSize().Width; + totalWidth = Math.Min(Math.Max(naturalSize.Width, minSize.Width), (maxSize.Width < 0 ? Int32.MaxValue : maxSize.Width)); widthMeasureSpec = new MeasureSpecification(new LayoutLength(totalWidth), MeasureSpecification.ModeType.Exactly); } else { - Vector3 naturalSize = Owner.GetNaturalSize(); - totalWidth = naturalSize.Width; - totalHeight = naturalSize.Height; + totalWidth = Math.Min(Math.Max(naturalSize.Width, minSize.Width), (maxSize.Width < 0 ? Int32.MaxValue : maxSize.Width)); + totalHeight = Math.Min(Math.Max(naturalSize.Height, minSize.Height), (maxSize.Height < 0 ? Int32.MaxValue : maxSize.Height)); heightMeasureSpec = new MeasureSpecification(new LayoutLength(totalHeight), MeasureSpecification.ModeType.Exactly); widthMeasureSpec = new MeasureSpecification(new LayoutLength(totalWidth), MeasureSpecification.ModeType.Exactly); @@ -76,25 +81,35 @@ namespace Tizen.NUI.BaseComponents static TextLabel() { } + private static SystemFontTypeChanged systemFontTypeChanged = new SystemFontTypeChanged(); + private static SystemLocaleLanguageChanged systemLocaleLanguageChanged = new SystemLocaleLanguageChanged(); + static private string defaultStyleName = "Tizen.NUI.BaseComponents.TextLabel"; + static private string defaultFontFamily = "BreezeSans"; private string textLabelSid = null; - private bool systemlangTextFlag = false; private TextLabelSelectorData selectorData; + private string fontFamily = defaultFontFamily; + private float fontSizeScale = 1.0f; + private bool hasSystemLanguageChanged = false; + private bool hasSystemFontSizeChanged = false; + private bool hasSystemFontTypeChanged = false; + + private Color internalTextColor; + private Color internalAnchorColor; + private Color internalAnchorClickedColor; /// /// Creates the TextLabel control. /// /// 3 - public TextLabel() : this(Interop.TextLabel.New(), true) + public TextLabel() : this(Interop.TextLabel.New(ThemeManager.GetStyle(defaultStyleName) == null ? false : true), true) { if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - Layout = new TextLayout(); } /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI). [EditorBrowsable(EditorBrowsableState.Never)] - public TextLabel(TextLabelStyle viewStyle) : this(Interop.TextLabel.New(), true, viewStyle) + public TextLabel(TextLabelStyle viewStyle) : this(Interop.TextLabel.New(ThemeManager.GetStyle(defaultStyleName) == null ? false : true), true, viewStyle) { - Layout = new TextLayout(); } /// @@ -103,10 +118,9 @@ namespace Tizen.NUI.BaseComponents /// false : Not displayed (hidden), true : displayed (shown) /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI). [EditorBrowsable(EditorBrowsableState.Never)] - public TextLabel(bool shown) : this(Interop.TextLabel.New(), true) + public TextLabel(bool shown) : this(Interop.TextLabel.New(ThemeManager.GetStyle(defaultStyleName) == null ? false : true), true) { if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - Layout = new TextLayout(); SetVisible(shown); } @@ -115,10 +129,9 @@ namespace Tizen.NUI.BaseComponents /// /// The text to display /// 3 - public TextLabel(string text) : this(Interop.TextLabel.New(text), true) + public TextLabel(string text) : this(Interop.TextLabel.New(text, ThemeManager.GetStyle(defaultStyleName) == null ? false : true), true) { if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - Layout = new TextLayout(); } /// @@ -128,10 +141,9 @@ namespace Tizen.NUI.BaseComponents /// false : Not displayed (hidden), true : displayed (shown) /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI). [EditorBrowsable(EditorBrowsableState.Never)] - public TextLabel(string text, bool shown) : this(Interop.TextLabel.New(text), true) + public TextLabel(string text, bool shown) : this(Interop.TextLabel.New(text, ThemeManager.GetStyle(defaultStyleName) == null ? false : true), true) { if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - Layout = new TextLayout(); SetVisible(shown); } @@ -145,7 +157,7 @@ namespace Tizen.NUI.BaseComponents } } - internal TextLabel(global::System.IntPtr cPtr, bool cMemoryOwn, ViewStyle viewStyle, bool shown = true) : base(Interop.TextLabel.Upcast(cPtr), cMemoryOwn, viewStyle) + internal TextLabel(global::System.IntPtr cPtr, bool cMemoryOwn, ViewStyle viewStyle, bool shown = true) : base(cPtr, cMemoryOwn, viewStyle) { if (!shown) { @@ -153,7 +165,7 @@ namespace Tizen.NUI.BaseComponents } } - internal TextLabel(global::System.IntPtr cPtr, bool cMemoryOwn, bool shown = true) : base(Interop.TextLabel.Upcast(cPtr), cMemoryOwn, null) + internal TextLabel(global::System.IntPtr cPtr, bool cMemoryOwn, bool shown = true) : base(cPtr, cMemoryOwn, null) { if (!shown) { @@ -161,6 +173,11 @@ namespace Tizen.NUI.BaseComponents } } + private bool HasStyle() + { + return ThemeManager.GetStyle(this.GetType()) == null ? false : true; + } + /// /// The TranslatableText property.
/// The text can set the SID value.
@@ -178,7 +195,6 @@ namespace Tizen.NUI.BaseComponents set { SetValue(TranslatableTextProperty, value); - selectorData?.TranslatableText.UpdateIfNeeds(this, value); } } private string translatableText @@ -199,10 +215,10 @@ namespace Tizen.NUI.BaseComponents if (translatableText != null) { Text = translatableText; - if (systemlangTextFlag == false) + if (hasSystemLanguageChanged == false) { - SystemSettings.LocaleLanguageChanged += SystemSettings_LocaleLanguageChanged; - systemlangTextFlag = true; + systemLocaleLanguageChanged.Add(SystemSettingsLocaleLanguageChanged); + hasSystemLanguageChanged = true; } } else @@ -227,8 +243,7 @@ namespace Tizen.NUI.BaseComponents set { SetValue(TextProperty, value); - selectorData?.Text.UpdateIfNeeds(this, value); - NotifyPropertyChangedAndRequestLayout(); + NotifyPropertyChanged(); } } @@ -246,16 +261,67 @@ namespace Tizen.NUI.BaseComponents set { SetValue(FontFamilyProperty, value); - selectorData?.FontFamily.UpdateIfNeeds(this, value); - NotifyPropertyChangedAndRequestLayout(); + NotifyPropertyChanged(); + } + } + + private string InternalFontFamily + { + get + { + if (HasStyle()) + return fontFamily; + else + return Object.InternalGetPropertyString(this.SwigCPtr, TextLabel.Property.FontFamily); + } + set + { + string newFontFamily; + + if (string.Equals(fontFamily, value)) return; + + fontFamily = value; + if (fontFamily == Tizen.NUI.FontFamily.UseSystemSetting) + { + try + { + newFontFamily = SystemSettings.FontType; + } + catch (Exception e) + { + Console.WriteLine("{0} Exception caught.", e); + newFontFamily = defaultFontFamily; + } + AddSystemSettingsFontTypeChanged(); + } + else + { + newFontFamily = fontFamily; + RemoveSystemSettingsFontTypeChanged(); + } + + SetInternalFontFamily(newFontFamily); } } + private void SetInternalFontFamily(string fontFamily) + { + Object.InternalSetPropertyString(this.SwigCPtr, TextLabel.Property.FontFamily, (string)fontFamily); + RequestLayout(); + } + /// /// The FontStyle property.
/// The requested font style to use.
+ /// The fontStyle map contains the following keys :
+ /// + /// width (string)The width key defines occupied by each glyph. (values: ultraCondensed, extraCondensed, condensed, semiCondensed, normal, semiExpanded, expanded, extraExpanded, ultraExpanded) + /// weight (string)The weight key defines the thickness or darkness of the glyphs. (values: thin, ultraLight, extraLight, light, demiLight, semiLight, book, normal, regular, medium, demiBold, semiBold, bold, ultraBold, extraBold, black, heavy, extraBlack) + /// slant (string)The slant key defines whether to use italics. (values: normal, roman, italic, oblique) + /// ///
/// 3 + [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1721: Property names should not match get methods")] public PropertyMap FontStyle { get @@ -265,8 +331,52 @@ namespace Tizen.NUI.BaseComponents set { SetValue(FontStyleProperty, value); - NotifyPropertyChangedAndRequestLayout(); + NotifyPropertyChanged(); + } + } + + /// + /// Set FontStyle to TextLabel.
+ ///
+ /// The FontStyle + /// + /// SetFontStyle specifies the requested font style through .
+ ///
+ /// + /// The following example demonstrates how to use the SetFontStyle method. + /// + /// var fontStyle = new Tizen.NUI.Text.FontStyle(); + /// fontStyle.Width = FontWidthType.Expanded; + /// fontStyle.Weight = FontWeightType.Bold; + /// fontStyle.Slant = FontSlantType.Italic; + /// label.SetFontStyle(fontStyle); + /// + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public void SetFontStyle(FontStyle fontStyle) + { + using (var fontStyleMap = TextMapHelper.GetFontStyleMap(fontStyle)) + { + SetValue(FontStyleProperty, fontStyleMap); + } + } + + /// + /// Get FontStyle from TextLabel.
+ ///
+ /// The FontStyle + /// + /// + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public FontStyle GetFontStyle() + { + FontStyle fontStyle; + using (var fontStyleMap = (PropertyMap)GetValue(FontStyleProperty)) + { + fontStyle = TextMapHelper.GetFontStyleStruct(fontStyleMap); } + return fontStyle; } /// @@ -274,6 +384,7 @@ namespace Tizen.NUI.BaseComponents /// The size of font in points.
///
/// 3 + [Binding.TypeConverter(typeof(PointSizeTypeConverter))] public float PointSize { get @@ -283,8 +394,7 @@ namespace Tizen.NUI.BaseComponents set { SetValue(PointSizeProperty, value); - selectorData?.PointSize.UpdateIfNeeds(this, value); - NotifyPropertyChangedAndRequestLayout(); + NotifyPropertyChanged(); } } @@ -302,7 +412,7 @@ namespace Tizen.NUI.BaseComponents set { SetValue(MultiLineProperty, value); - NotifyPropertyChangedAndRequestLayout(); + NotifyPropertyChanged(); } } @@ -362,7 +472,6 @@ namespace Tizen.NUI.BaseComponents set { SetValue(TextColorProperty, value); - selectorData?.TextColor.UpdateIfNeeds(this, value); NotifyPropertyChanged(); } } @@ -376,25 +485,48 @@ namespace Tizen.NUI.BaseComponents /// Deprecated.(API Level 6) Use Shadow instead. /// The property cascade chaining set is possible. For example, this (textLabel.ShadowOffset.X = 0.1f;) is possible. /// - [Obsolete("Please do not use this ShadowOffset(Deprecated). Please use Shadow instead.")] + [Obsolete("Do not use this ShadowOffset(Deprecated). Use Shadow instead.")] public Vector2 ShadowOffset { get { - Vector2 shadowOffset = new Vector2(); - Shadow.Find(TextLabel.Property.SHADOW, "offset")?.Get(shadowOffset); - return new Vector2(OnShadowOffsetChanged, shadowOffset.X, shadowOffset.Y); + return GetValue(ShadowOffsetProperty) as Vector2; } set { - PropertyMap temp = new PropertyMap(); - temp.Insert("offset", new PropertyValue(value)); + SetValue(ShadowOffsetProperty, value); + } + } - PropertyMap shadowMap = Shadow; - shadowMap.Merge(temp); + private Vector2 InternalShadowOffset + { + get + { + float x = 0.0f, y = 0.0f; + using (var propertyValue = Shadow.Find(TextLabel.Property.SHADOW, "offset")) + using (var shadowOffset = new Vector2()) + { + if (null != propertyValue) + { + propertyValue.Get(shadowOffset); + x = shadowOffset.X; + y = shadowOffset.Y; + } + } + return new Vector2(OnShadowOffsetChanged, x, y); + } + set + { + using (var map = new PropertyMap()) + { + map.Add("offset", value); - SetValue(ShadowProperty, shadowMap); - NotifyPropertyChanged(); + var shadowMap = Shadow; + shadowMap.Merge(map); + + SetValue(ShadowProperty, shadowMap); + NotifyPropertyChanged(); + } } } @@ -407,25 +539,48 @@ namespace Tizen.NUI.BaseComponents /// Deprecated.(API Level 6) Use Shadow instead. /// The property cascade chaining set is possible. For example, this (textLabel.ShadowColor.X = 0.1f;) is possible. /// - [Obsolete("Please do not use this ShadowColor(Deprecated). Please use Shadow instead.")] + [Obsolete("Do not use this ShadowColor(Deprecated). Use Shadow instead.")] public Vector4 ShadowColor { get { - Vector4 shadowColor = new Vector4(); - Shadow.Find(TextLabel.Property.SHADOW, "color")?.Get(shadowColor); - return new Vector4(OnShadowColorChanged, shadowColor.X, shadowColor.Y, shadowColor.Z, shadowColor.W); + return GetValue(ShadowColorProperty) as Vector4; } set { - PropertyMap temp = new PropertyMap(); - temp.Insert("color", new PropertyValue(value)); - - PropertyMap shadowMap = Shadow; - shadowMap.Merge(temp); + SetValue(ShadowColorProperty, value); + } + } - SetValue(ShadowProperty, shadowMap); - NotifyPropertyChanged(); + private Vector4 InternalShadowColor + { + get + { + float x = 0.0f, y = 0.0f, z = 0.0f, w = 0.0f; + using (var propertyValue = Shadow.Find(TextLabel.Property.SHADOW, "color")) + using (var shadowColor = new Vector4()) + { + if (null != propertyValue) + { + propertyValue.Get(shadowColor); + x = shadowColor.X; + y = shadowColor.Y; + z = shadowColor.Z; + w = shadowColor.W; + } + } + return new Vector4(OnShadowColorChanged, x, y, z, w); + } + set + { + using (var map = new PropertyMap()) + { + map.Add("color", value); + var shadowMap = Shadow; + shadowMap.Merge(map); + SetValue(ShadowProperty, shadowMap); + NotifyPropertyChanged(); + } } } @@ -437,26 +592,43 @@ namespace Tizen.NUI.BaseComponents /// /// Deprecated.(API Level 6) Use Underline instead. /// - [Obsolete("Please do not use this UnderlineEnabled(Deprecated). Please use Underline instead.")] + [Obsolete("Do not use this UnderlineEnabled(Deprecated). Use Underline instead.")] public bool UnderlineEnabled { get { + return (bool)GetValue(UnderlineEnabledProperty); + } + set + { + SetValue(UnderlineEnabledProperty, value); + } + } + + private bool InternalUnderlineEnabled + { + get + { bool underlineEnabled = false; - Underline.Find(TextLabel.Property.UNDERLINE, "enable")?.Get(out underlineEnabled); + using (var propertyValue = Underline.Find(TextLabel.Property.UNDERLINE, "enable")) + { + if (propertyValue != null) + { + propertyValue.Get(out underlineEnabled); + } + } return underlineEnabled; } set { - PropertyMap temp = new PropertyMap(); - temp.Add("enable", new PropertyValue(value)); - - PropertyMap undelineMap = Underline; - undelineMap.Merge(temp); - - SetValue(UnderlineProperty, undelineMap); - NotifyPropertyChanged(); - + using (var map = new PropertyMap()) + { + map.Add("enable", value); + var undelineMap = Underline; + undelineMap.Merge(map); + SetValue(UnderlineProperty, undelineMap); + NotifyPropertyChanged(); + } } } @@ -469,25 +641,48 @@ namespace Tizen.NUI.BaseComponents /// Deprecated.(API Level 6) Use Underline instead. /// The property cascade chaining set is possible. For example, this (textLabel.UnderlineColor.X = 0.1f;) is possible. /// - [Obsolete("Please do not use this UnderlineColor(Deprecated). Please use Underline instead.")] + [Obsolete("Do not use this UnderlineColor(Deprecated). Use Underline instead.")] public Vector4 UnderlineColor { get { - Vector4 underlineColor = new Vector4(); - Underline.Find(TextLabel.Property.UNDERLINE, "color")?.Get(underlineColor); - return new Vector4(OnUnderlineColorChanged, underlineColor.X, underlineColor.Y, underlineColor.Z, underlineColor.W); + return GetValue(UnderlineColorProperty) as Vector4; } set { - PropertyMap temp = new PropertyMap(); - temp.Insert("color", new PropertyValue(value)); - - PropertyMap undelineMap = Underline; - undelineMap.Merge(temp); + SetValue(UnderlineColorProperty, value); + } + } - SetValue(UnderlineProperty, undelineMap); - NotifyPropertyChanged(); + private Vector4 InternalUnderlineColor + { + get + { + float x = 0.0f, y = 0.0f, z = 0.0f, w = 0.0f; + using (var propertyValue = Underline.Find(TextLabel.Property.UNDERLINE, "color")) + using (var underlineColor = new Vector4()) + { + if (null != propertyValue) + { + propertyValue.Get(underlineColor); + x = underlineColor.X; + y = underlineColor.Y; + z = underlineColor.Z; + w = underlineColor.W; + } + } + return new Vector4(OnUnderlineColorChanged, x, y, z, w); + } + set + { + using (var map = new PropertyMap()) + { + map.Add("color", value); + var undelineMap = Underline; + undelineMap.Merge(map); + SetValue(UnderlineProperty, undelineMap); + NotifyPropertyChanged(); + } } } @@ -499,25 +694,43 @@ namespace Tizen.NUI.BaseComponents /// /// Deprecated.(API Level 6) Use Underline instead. /// - [Obsolete("Please do not use this UnderlineHeight(Deprecated). Please use Underline instead.")] + [Obsolete("Do not use this UnderlineHeight(Deprecated). Use Underline instead.")] public float UnderlineHeight { get { + return (float)GetValue(UnderlineHeightProperty); + } + set + { + SetValue(UnderlineHeightProperty, value); + } + } + + private float InternalUnderlineHeight + { + get + { float underlineHeight = 0.0f; - Underline.Find(TextLabel.Property.UNDERLINE, "height")?.Get(out underlineHeight); + using (var propertyValue = Underline.Find(TextLabel.Property.UNDERLINE, "height")) + { + if (null != propertyValue) + { + propertyValue.Get(out underlineHeight); + } + } return underlineHeight; } set { - PropertyMap temp = new PropertyMap(); - temp.Insert("height", new PropertyValue(value)); - - PropertyMap undelineMap = Underline; - undelineMap.Merge(temp); - - SetValue(UnderlineProperty, undelineMap); - NotifyPropertyChanged(); + using (var map = new PropertyMap()) + { + map.Add("height", value); + var undelineMap = Underline; + undelineMap.Merge(map); + SetValue(UnderlineProperty, undelineMap); + NotifyPropertyChanged(); + } } } @@ -625,15 +838,40 @@ namespace Tizen.NUI.BaseComponents set { SetValue(LineSpacingProperty, value); - NotifyPropertyChangedAndRequestLayout(); + NotifyPropertyChanged(); + } + } + + /// + /// The relative height of the line (a factor that will be multiplied by text height).
+ /// If the value is less than 1, the lines could to be overlapped. + ///
+ [EditorBrowsable(EditorBrowsableState.Never)] + public float RelativeLineHeight + { + get + { + return (float)GetValue(RelativeLineHeightProperty); + } + set + { + SetValue(RelativeLineHeightProperty, value); + NotifyPropertyChanged(); } } /// /// The Underline property.
/// The default underline parameters.
+ /// The underline map contains the following keys :
+ /// + /// enable (bool)Whether the underline is enabled (the default value is false) + /// color (Color)The color of the underline (If not provided then the color of the text is used) + /// height (float)The height in pixels of the underline (the default value is 1.f) + /// ///
/// 3 + [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1721: Property names should not match get methods")] public PropertyMap Underline { get @@ -648,10 +886,61 @@ namespace Tizen.NUI.BaseComponents } /// + /// Set Underline to TextLabel.
+ ///
+ /// The Underline + /// + /// SetUnderline specifies the underline of the text through .
+ ///
+ /// + /// The following example demonstrates how to use the SetUnderline method. + /// + /// var underline = new Tizen.NUI.Text.Underline(); + /// underline.Enable = true; + /// underline.Color = new Color("#3498DB"); + /// underline.Height = 2.0f; + /// label.SetUnderline(underline); + /// + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public void SetUnderline(Underline underline) + { + using (var underlineMap = TextMapHelper.GetUnderlineMap(underline)) + { + SetValue(UnderlineProperty, underlineMap); + } + } + + /// + /// Get Underline from TextLabel.
+ ///
+ /// The Underline + /// + /// + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public Underline GetUnderline() + { + Underline underline; + using (var underlineMap = (PropertyMap)GetValue(UnderlineProperty)) + { + underline = TextMapHelper.GetUnderlineStruct(underlineMap); + } + return underline; + } + + /// /// The Shadow property.
/// The default shadow parameters.
+ /// The shadow map contains the following keys :
+ /// + /// color (Color)The color of the shadow (the default color is Color.Black) + /// offset (Vector2)The offset in pixels of the shadow (If not provided then the shadow is not enabled) + /// blurRadius (float)The radius of the Gaussian blur for the soft shadow (If not provided then the soft shadow is not enabled) + /// ///
/// 3 + [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1721: Property names should not match get methods")] public PropertyMap Shadow { get @@ -666,6 +955,50 @@ namespace Tizen.NUI.BaseComponents } /// + /// Set Shadow to TextLabel.
+ ///
+ /// The Shadow + /// + /// SetShadow specifies the shadow of the text through .
+ ///
+ /// + /// The following example demonstrates how to use the SetShadow method. + /// + /// var shadow = new Tizen.NUI.Text.Shadow(); + /// shadow.Offset = new Vector2(3, 3); + /// shadow.Color = new Color("#F1C40F"); + /// shadow.BlurRadius = 4.0f; + /// label.SetShadow(shadow); + /// + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public void SetShadow(Tizen.NUI.Text.Shadow shadow) + { + using (var shadowMap = TextMapHelper.GetShadowMap(shadow)) + { + SetValue(ShadowProperty, shadowMap); + } + } + + /// + /// Get Shadow from TextLabel.
+ ///
+ /// The Shadow + /// + /// + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public Tizen.NUI.Text.Shadow GetShadow() + { + Tizen.NUI.Text.Shadow shadow; + using (var shadowMap = (PropertyMap)GetValue(ShadowProperty)) + { + shadow = TextMapHelper.GetShadowStruct(shadowMap); + } + return shadow; + } + + /// /// Describes a text shadow for a TextLabel. /// It is null by default. /// @@ -679,7 +1012,6 @@ namespace Tizen.NUI.BaseComponents set { SetValue(TextShadowProperty, value); - selectorData?.TextShadow.UpdateIfNeeds(this, value); NotifyPropertyChanged(); } } @@ -705,8 +1037,14 @@ namespace Tizen.NUI.BaseComponents /// /// The Outline property.
/// The default outline parameters.
+ /// The outline map contains the following keys :
+ /// + /// color (Color)The color of the outline (the default color is Color.White) + /// width (float)The width in pixels of the outline (If not provided then the outline is not enabled) + /// ///
/// 3 + [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1721: Property names should not match get methods")] public PropertyMap Outline { get @@ -721,10 +1059,101 @@ namespace Tizen.NUI.BaseComponents } /// + /// Set Outline to TextLabel.
+ ///
+ /// The Outline + /// + /// SetOutline specifies the outline of the text through .
+ ///
+ /// + /// The following example demonstrates how to use the SetOutline method. + /// + /// var outline = new Tizen.NUI.Text.Outline(); + /// outline.Width = 2.0f; + /// outline.Color = new Color("#45B39D"); + /// label.SetOutline(outline); + /// + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public void SetOutline(Outline outline) + { + using (var outlineMap = TextMapHelper.GetOutlineMap(outline)) + { + SetValue(OutlineProperty, outlineMap); + } + } + + /// + /// Get Outline from TextLabel.
+ ///
+ /// The Outline + /// + /// + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public Outline GetOutline() + { + Outline outline; + using (var outlineMap = (PropertyMap)GetValue(OutlineProperty)) + { + outline = TextMapHelper.GetOutlineStruct(outlineMap); + } + return outline; + } + + /// + /// Set Strikethrough to TextLabel.
+ ///
+ /// The Strikethrough + /// + /// SetStrikethrough specifies the strikethrough of the text through .
+ ///
+ /// + /// The following example demonstrates how to use the SetStrikethrough method. + /// + /// var strikethrough = new Tizen.NUI.Text.Strikethrough(); + /// strikethrough.Enable = true; + /// strikethrough.Color = new Color("#3498DB"); + /// strikethrough.Height = 2.0f; + /// label.SetStrikethrough(strikethrough); + /// + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public void SetStrikethrough(Strikethrough strikethrough) + { + using (var map = TextMapHelper.GetStrikethroughMap(strikethrough)) + using (var propertyValue = new PropertyValue(map)) + { + SetProperty(TextLabel.Property.Strikethrough, propertyValue); + } + } + + /// + /// Get Strikethrough from TextLabel.
+ ///
+ /// The Strikethrough + /// + /// + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public Strikethrough GetStrikethrough() + { + Strikethrough strikethrough; + using (var propertyValue = GetProperty(TextLabel.Property.Strikethrough)) + using (var map = new PropertyMap()) + { + propertyValue.Get(map); + strikethrough = TextMapHelper.GetStrikethroughStruct(map); + } + return strikethrough; + } + + /// /// The PixelSize property.
/// The size of font in pixels.
///
/// 3 + [Binding.TypeConverter(typeof(FloatGraphicsTypeConverter))] public float PixelSize { get @@ -734,8 +1163,7 @@ namespace Tizen.NUI.BaseComponents set { SetValue(PixelSizeProperty, value); - selectorData?.PixelSize.UpdateIfNeeds(this, value); - NotifyPropertyChangedAndRequestLayout(); + NotifyPropertyChanged(); } } @@ -758,8 +1186,26 @@ namespace Tizen.NUI.BaseComponents } /// + /// The ellipsis position of the text. + /// Specifies which portion of the text should be replaced with an ellipsis when the text size exceeds the layout size.
+ ///
+ /// 9 + public EllipsisPosition EllipsisPosition + { + get + { + return (EllipsisPosition)GetValue(EllipsisPositionProperty); + } + set + { + SetValue(EllipsisPositionProperty, value); + NotifyPropertyChanged(); + } + } + + /// /// The AutoScrollLoopDelay property.
- /// Do something.
+ /// The amount of time to delay the starting time of auto scrolling and further loops.
///
/// 3 public float AutoScrollLoopDelay @@ -777,7 +1223,8 @@ namespace Tizen.NUI.BaseComponents /// /// The AutoScrollStopMode property.
- /// Do something.
+ /// The auto scrolling stop behaviour.
+ /// The default value is AutoScrollStopMode.FinishLoop.
///
/// 3 public AutoScrollStopMode AutoScrollStopMode @@ -801,9 +1248,12 @@ namespace Tizen.NUI.BaseComponents { get { - int temp = 0; - GetProperty(TextLabel.Property.LineCount).Get(out temp); - return temp; + int lineCount = 0; + using (var propertyValue = GetProperty(TextLabel.Property.LineCount)) + { + propertyValue.Get(out lineCount); + } + return lineCount; } } @@ -828,24 +1278,25 @@ namespace Tizen.NUI.BaseComponents /// /// The direction of the text such as left to right or right to left. /// - /// 5 - /// This will be released at Tizen.NET API Level 5, so currently this would be used as inhouse API. + /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI). [EditorBrowsable(EditorBrowsableState.Never)] public TextDirection TextDirection { get { - int temp = 0; - GetProperty(TextLabel.Property.TextDirection).Get(out temp); - return (TextDirection)temp; + int textDirection = 0; + using (var propertyValue = GetProperty(TextLabel.Property.TextDirection)) + { + propertyValue.Get(out textDirection); + } + return (TextDirection)textDirection; } } /// /// The vertical line alignment of the text. /// - /// 5 - /// This will be released at Tizen.NET API Level 5, so currently this would be used as inhouse API. + /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI). [EditorBrowsable(EditorBrowsableState.Never)] public VerticalLineAlignment VerticalLineAlignment { @@ -880,14 +1331,17 @@ namespace Tizen.NUI.BaseComponents /// /// The text fit parameters.
/// The textFit map contains the following keys :
- /// - enable (bool type) : True to enable the text fit or false to disable(the default value is false)
- /// - minSize (float type) : Minimum Size for text fit(the default value is 10.f)
- /// - maxSize (float type) : Maximum Size for text fit(the default value is 100.f)
- /// - stepSize (float type) : Step Size for font increase(the default value is 1.f)
- /// - fontSize (string type) : The size type of font, You can choose between "pointSize" or "pixelSize". (the default value is "pointSize")
+ /// + /// enable (bool)True to enable the text fit or false to disable (the default value is false) + /// minSize (float)Minimum Size for text fit (the default value is 10.f) + /// maxSize (float)Maximum Size for text fit (the default value is 100.f) + /// stepSize (float)Step Size for font increase (the default value is 1.f) + /// fontSize (string)The size type of font, You can choose between "pointSize" or "pixelSize". (the default value is "pointSize") + /// ///
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI). [EditorBrowsable(EditorBrowsableState.Never)] + [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1721: Property names should not match get methods")] public PropertyMap TextFit { get @@ -902,9 +1356,59 @@ namespace Tizen.NUI.BaseComponents } /// + /// Set TextFit to TextLabel.
+ ///
+ /// The TextFit + /// + /// SetTextFit specifies the textFit of the text through .
+ ///
+ /// + /// The following example demonstrates how to use the SetTextFit method. + /// + /// var textFit = new Tizen.NUI.Text.TextFit(); + /// textFit.Enable = true; + /// textFit.MinSize = 10.0f; + /// textFit.MaxSize = 100.0f; + /// textFit.StepSize = 5.0f; + /// textFit.FontSizeType = FontSizeType.PointSize; + /// label.SetTextFit(textFit); + /// + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public void SetTextFit(TextFit textFit) + { + using (var textFitMap = TextMapHelper.GetTextFitMap(textFit)) + { + SetValue(TextFitProperty, textFitMap); + } + } + + /// + /// Get TextFit from TextLabel.
+ ///
+ /// The TextFit + /// + /// TextFit is always returned based on PointSize.
+ /// If the user sets FontSizeType to PixelSize, then MinSize, MaxSize, and StepSize are converted based on PointSize and returned.
+ /// + ///
+ [EditorBrowsable(EditorBrowsableState.Never)] + public TextFit GetTextFit() + { + TextFit textFit; + using (var textFitMap = (PropertyMap)GetValue(TextFitProperty)) + { + textFit = TextMapHelper.GetTextFitStruct(textFitMap); + } + return textFit; + } + + /// /// The MinLineSize property.
+ /// The height of the line in points.
+ /// If the font size is larger than the line size, it works with the font size.
///
- /// 8 + /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI). [EditorBrowsable(EditorBrowsableState.Never)] public float MinLineSize { @@ -915,22 +1419,164 @@ namespace Tizen.NUI.BaseComponents set { SetValue(MinLineSizeProperty, value); - NotifyPropertyChangedAndRequestLayout(); + NotifyPropertyChanged(); + } + } + + /// + /// The spaces between characters in Pixels. + /// + /// A positive value will make the characters far apart (expanded) and a negative value will bring them closer (condensed).
+ /// The default value is 0.f which does nothing. + ///
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)] + public float CharacterSpacing + { + get + { + return (float)GetValue(CharacterSpacingProperty); + } + set + { + SetValue(CharacterSpacingProperty, value); + NotifyPropertyChanged(); + } + } + + /// + /// The AnchorColor property.
+ /// The color of the anchor.
+ /// This property is used as the default color of the markup anchor tag.
+ /// If there is a color attribute in the markup anchor tag, the markup attribute takes precedence. + ///
+ /// + /// The property cascade chaining set is possible. For example, this (textLabel.AnchorColor.X = 0.1f;) is possible. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public Color AnchorColor + { + get + { + Color color = (Color)GetValue(AnchorColorProperty); + return new Color(OnAnchorColorChanged, color.R, color.G, color.B, color.A); + } + set + { + SetValue(AnchorColorProperty, value); + NotifyPropertyChanged(); + } + } + + /// + /// The AnchorClickedColor property.
+ /// The color of the clicked anchor.
+ /// This property is used as the default clicked color of the markup anchor tag.
+ /// If there is a color attribute in the markup anchor tag, the markup attribute takes precedence. + ///
+ /// + /// The property cascade chaining set is possible. For example, this (textLabel.AnchorClickedColor.X = 0.1f;) is possible. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public Color AnchorClickedColor + { + get + { + Color color = (Color)GetValue(AnchorClickedColorProperty); + return new Color(OnAnchorClickedColorChanged, color.R, color.G, color.B, color.A); + } + set + { + SetValue(AnchorClickedColorProperty, value); + NotifyPropertyChanged(); } } - private TextLabelSelectorData SelectorData + /// + /// The FontSizeScale property for scaling the specified font size up or down.
+ /// The default value is 1.0.
+ /// The given font size scale value is used for multiplying the specified font size before querying fonts.
+ /// If FontSizeScale.UseSystemSetting, will use the SystemSettings.FontSize internally.
+ ///
+ /// 9 + public float FontSizeScale { get { - if (selectorData == null) + return (float)GetValue(FontSizeScaleProperty); + } + set + { + SetValue(FontSizeScaleProperty, value); + NotifyPropertyChanged(); + } + } + + private float InternalFontSizeScale + { + get + { + return fontSizeScale; + } + set + { + float newFontSizeScale; + + if (fontSizeScale == value) return; + + fontSizeScale = value; + if (fontSizeScale == Tizen.NUI.FontSizeScale.UseSystemSetting) { - selectorData = new TextLabelSelectorData(); + SystemSettingsFontSize systemSettingsFontSize; + + try + { + systemSettingsFontSize = SystemSettings.FontSize; + } + catch (Exception e) + { + Console.WriteLine("{0} Exception caught.", e); + systemSettingsFontSize = SystemSettingsFontSize.Normal; + } + newFontSizeScale = TextUtils.GetFontSizeScale(systemSettingsFontSize); + AddSystemSettingsFontSizeChanged(); } - return selectorData; + else + { + newFontSizeScale = fontSizeScale; + RemoveSystemSettingsFontSizeChanged(); + } + + SetInternalFontSizeScale(newFontSizeScale); + } + } + + private void SetInternalFontSizeScale(float fontSizeScale) + { + Object.InternalSetPropertyFloat(this.SwigCPtr, TextLabel.Property.FontSizeScale, (float)fontSizeScale); + RequestLayout(); + } + + /// + /// The EnableFontSizeScale property.
+ /// Whether the font size scale is enabled. (The default value is true) + ///
+ [EditorBrowsable(EditorBrowsableState.Never)] + public bool EnableFontSizeScale + { + get + { + return (bool)GetValue(EnableFontSizeScaleProperty); + } + set + { + SetValue(EnableFontSizeScaleProperty, value); + NotifyPropertyChanged(); } } + private TextLabelSelectorData EnsureSelectorData() => selectorData ?? (selectorData = new TextLabelSelectorData()); + /// /// Downcasts a handle to textLabel handle /// @@ -938,9 +1584,8 @@ namespace Tizen.NUI.BaseComponents /// /// Thrown when handle is null. /// 3 - /// Please do not use! this will be deprecated! - /// Instead please use as keyword. - [Obsolete("Please do not use! This will be deprecated! Please use as keyword instead! " + + /// Do not use this, that will be deprecated. Use as keyword instead. + [Obsolete("Do not use this, that will be deprecated. Use as keyword instead. " + "Like: " + "BaseHandle handle = new TextLabel(\"Hello World!\"); " + "TextLabel label = handle as TextLabel")] @@ -965,11 +1610,18 @@ namespace Tizen.NUI.BaseComponents return; } - if (systemlangTextFlag) + internalTextColor?.Dispose(); + internalAnchorColor?.Dispose(); + internalAnchorClickedColor?.Dispose(); + + if (hasSystemLanguageChanged) { - SystemSettings.LocaleLanguageChanged -= SystemSettings_LocaleLanguageChanged; + systemLocaleLanguageChanged.Remove(SystemSettingsLocaleLanguageChanged); } + RemoveSystemSettingsFontTypeChanged(); + RemoveSystemSettingsFontSizeChanged(); + if (type == DisposeTypes.Explicit) { //Called by User @@ -978,12 +1630,15 @@ namespace Tizen.NUI.BaseComponents selectorData?.Reset(this); } - base.Dispose(type); - } + if (this.HasBody()) + { + if (textLabelTextFitChangedCallbackDelegate != null) + { + TextFitChangedSignal().Disconnect(textLabelTextFitChangedCallbackDelegate); + } + } - internal static global::System.Runtime.InteropServices.HandleRef getCPtr(TextLabel obj) - { - return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.SwigCPtr; + base.Dispose(type); } /// This will not be public opened. @@ -1002,6 +1657,11 @@ namespace Tizen.NUI.BaseComponents return new TextLabelStyle(); } + internal override LayoutItem CreateDefaultLayout() + { + return new TextLabelLayout(); + } + /// /// Invoked whenever the binding context of the textlabel changes. Implement this method to add class handling for this event. /// @@ -1010,14 +1670,92 @@ namespace Tizen.NUI.BaseComponents base.OnBindingContextChanged(); } - private void SystemSettings_LocaleLanguageChanged(object sender, LocaleLanguageChangedEventArgs e) + private void SystemSettingsLocaleLanguageChanged(object sender, LocaleLanguageChangedEventArgs e) { Text = NUIApplication.MultilingualResourceManager?.GetString(textLabelSid, new CultureInfo(e.Value.Replace("_", "-"))); } - private void NotifyPropertyChangedAndRequestLayout() + private void SystemSettingsFontSizeChanged(object sender, FontSizeChangedEventArgs e) + { + float newFontSizeScale = TextUtils.GetFontSizeScale(e.Value); + SetInternalFontSizeScale(newFontSizeScale); + } + + private void AddSystemSettingsFontSizeChanged() + { + if (hasSystemFontSizeChanged != true) + { + try + { + SystemFontSizeChangedManager.Add(SystemSettingsFontSizeChanged); + hasSystemFontSizeChanged = true; + } + catch (Exception e) + { + Console.WriteLine("{0} Exception caught.", e); + hasSystemFontSizeChanged = false; + } + } + } + + private void RemoveSystemSettingsFontSizeChanged() + { + if (hasSystemFontSizeChanged == true) + { + try + { + SystemFontSizeChangedManager.Remove(SystemSettingsFontSizeChanged); + hasSystemFontSizeChanged = false; + } + catch (Exception e) + { + Console.WriteLine("{0} Exception caught.", e); + hasSystemFontSizeChanged = true; + } + } + } + + private void SystemSettingsFontTypeChanged(object sender, FontTypeChangedEventArgs e) + { + SetInternalFontFamily(e.Value); + } + + private void AddSystemSettingsFontTypeChanged() + { + if (HasStyle() && !hasSystemFontTypeChanged) + { + try + { + systemFontTypeChanged.Add(SystemSettingsFontTypeChanged); + hasSystemFontTypeChanged = true; + } + catch (Exception e) + { + Console.WriteLine("{0} Exception caught.", e); + hasSystemFontTypeChanged = false; + } + } + } + + private void RemoveSystemSettingsFontTypeChanged() + { + if (hasSystemFontTypeChanged) + { + try + { + systemFontTypeChanged.Remove(SystemSettingsFontTypeChanged); + hasSystemFontTypeChanged = false; + } + catch (Exception e) + { + Console.WriteLine("{0} Exception caught.", e); + hasSystemFontTypeChanged = true; + } + } + } + + private void RequestLayout() { - NotifyPropertyChanged(); Layout?.RequestLayout(); } @@ -1037,6 +1775,7 @@ namespace Tizen.NUI.BaseComponents internal static readonly int AutoScrollLoopCount = Interop.TextLabel.AutoScrollLoopCountGet(); internal static readonly int AutoScrollGap = Interop.TextLabel.AutoScrollGapGet(); internal static readonly int LineSpacing = Interop.TextLabel.LineSpacingGet(); + internal static readonly int RelativeLineHeight = Interop.TextLabel.RelativeLineHeightGet(); internal static readonly int UNDERLINE = Interop.TextLabel.UnderlineGet(); internal static readonly int SHADOW = Interop.TextLabel.ShadowGet(); internal static readonly int EMBOSS = Interop.TextLabel.EmbossGet(); @@ -1052,6 +1791,13 @@ namespace Tizen.NUI.BaseComponents internal static readonly int MatchSystemLanguageDirection = Interop.TextLabel.MatchSystemLanguageDirectionGet(); internal static readonly int TextFit = Interop.TextLabel.TextFitGet(); internal static readonly int MinLineSize = Interop.TextLabel.MinLineSizeGet(); + internal static readonly int FontSizeScale = Interop.TextLabel.FontSizeScaleGet(); + internal static readonly int EnableFontSizeScale = Interop.TextLabel.EnableFontSizeScaleGet(); + internal static readonly int EllipsisPosition = Interop.TextLabel.EllipsisPositionGet(); + internal static readonly int Strikethrough = Interop.TextLabel.StrikethroughGet(); + internal static readonly int CharacterSpacing = Interop.TextLabel.CharacterSpacingGet(); + internal static readonly int AnchorColor = Interop.TextLabel.AnchorColorGet(); + internal static readonly int AnchorClickedColor = Interop.TextLabel.AnchorClickedColorGet(); } private void OnShadowColorChanged(float x, float y, float z, float w) @@ -1070,5 +1816,13 @@ namespace Tizen.NUI.BaseComponents { UnderlineColor = new Vector4(x, y, z, w); } + private void OnAnchorColorChanged(float r, float g, float b, float a) + { + AnchorColor = new Color(r, g, b, a); + } + private void OnAnchorClickedColorChanged(float r, float g, float b, float a) + { + AnchorClickedColor = new Color(r, g, b, a); + } } }