From 7db50880834d4999f2217ca209b7517f05796da7 Mon Sep 17 00:00:00 2001 From: Kangho Hur Date: Tue, 14 Feb 2017 12:42:06 +0900 Subject: Modify FontWeight type for flexibility This change is introduced in RFC-15 Change-Id: I8bc22b8818ccda3bee95c83e6979e39810e6b028 --- .../PlatformConfiguration/TizenSpecific/Entry.cs | 12 +++---- .../TizenSpecific/FontWeight.cs | 26 +++++++------- .../PlatformConfiguration/TizenSpecific/Label.cs | 12 +++---- Xamarin.Forms.Platform.Tizen/Native/Entry.cs | 2 +- Xamarin.Forms.Platform.Tizen/Native/FontWeight.cs | 21 ----------- Xamarin.Forms.Platform.Tizen/Native/Label.cs | 2 +- Xamarin.Forms.Platform.Tizen/Native/Span.cs | 41 +++------------------- .../Renderers/ButtonRenderer.cs | 2 -- .../Renderers/EntryRenderer.cs | 34 +----------------- .../Renderers/LabelRenderer.cs | 39 ++------------------ .../Xamarin.Forms.Platform.Tizen.csproj | 1 - 11 files changed, 35 insertions(+), 157 deletions(-) delete mode 100644 Xamarin.Forms.Platform.Tizen/Native/FontWeight.cs diff --git a/Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/Entry.cs b/Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/Entry.cs index c84dcc36..6572610a 100644 --- a/Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/Entry.cs +++ b/Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/Entry.cs @@ -4,24 +4,24 @@ namespace Xamarin.Forms.PlatformConfiguration.TizenSpecific public static class Entry { - public static readonly BindableProperty FontWeightProperty = BindableProperty.Create("FontWeight", typeof(FontWeight), typeof(FormsElement), FontWeight.None); + public static readonly BindableProperty FontWeightProperty = BindableProperty.Create("FontWeight", typeof(string), typeof(FormsElement), FontWeight.None); - public static FontWeight GetFontWeight(BindableObject element) + public static string GetFontWeight(BindableObject element) { - return (FontWeight)element.GetValue(FontWeightProperty); + return (string)element.GetValue(FontWeightProperty); } - public static void SetFontWeight(BindableObject element, FontWeight weight) + public static void SetFontWeight(BindableObject element, string weight) { element.SetValue(FontWeightProperty, weight); } - public static FontWeight GetFontWeight(this IPlatformElementConfiguration config) + public static string GetFontWeight(this IPlatformElementConfiguration config) { return GetFontWeight(config.Element); } - public static IPlatformElementConfiguration SetFontWeight(this IPlatformElementConfiguration config, FontWeight weight) + public static IPlatformElementConfiguration SetFontWeight(this IPlatformElementConfiguration config, string weight) { SetFontWeight(config.Element, weight); return config; diff --git a/Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/FontWeight.cs b/Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/FontWeight.cs index 8838bc07..763935b2 100644 --- a/Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/FontWeight.cs +++ b/Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/FontWeight.cs @@ -1,18 +1,18 @@ namespace Xamarin.Forms.PlatformConfiguration.TizenSpecific { - public enum FontWeight + public static class FontWeight { - None, - Normal, - Thin, - UltraLight, - Light, - Book, - Medium, - SemiBold, - Bold, - UltraBold, - Black, - ExtraBlack + public const string None = "None"; + public const string Normal = "Normal"; + public const string Thin = "Thin"; + public const string UltraLight = "UltraLight"; + public const string Light = "Light"; + public const string Book = "Book"; + public const string Medium = "Medium"; + public const string SemiBold = "SemiBold"; + public const string Bold = "Bold"; + public const string UltraBold = "UltraBold"; + public const string Black= "Black"; + public const string ExtraBlack= "ExtraBlack"; } } diff --git a/Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/Label.cs b/Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/Label.cs index d95daa83..f560057a 100644 --- a/Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/Label.cs +++ b/Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/Label.cs @@ -4,24 +4,24 @@ namespace Xamarin.Forms.PlatformConfiguration.TizenSpecific public static class Label { - public static readonly BindableProperty FontWeightProperty = BindableProperty.Create("FontWeight", typeof(FontWeight), typeof(FormsElement), FontWeight.None); + public static readonly BindableProperty FontWeightProperty = BindableProperty.Create("FontWeight", typeof(string), typeof(FormsElement), FontWeight.None); - public static FontWeight GetFontWeight(BindableObject element) + public static string GetFontWeight(BindableObject element) { - return (FontWeight)element.GetValue(FontWeightProperty); + return (string)element.GetValue(FontWeightProperty); } - public static void SetFontWeight(BindableObject element, FontWeight weight) + public static void SetFontWeight(BindableObject element, string weight) { element.SetValue(FontWeightProperty, weight); } - public static FontWeight GetFontWeight(this IPlatformElementConfiguration config) + public static string GetFontWeight(this IPlatformElementConfiguration config) { return GetFontWeight(config.Element); } - public static IPlatformElementConfiguration SetFontWeight(this IPlatformElementConfiguration config, FontWeight weight) + public static IPlatformElementConfiguration SetFontWeight(this IPlatformElementConfiguration config, string weight) { SetFontWeight(config.Element, weight); return config; diff --git a/Xamarin.Forms.Platform.Tizen/Native/Entry.cs b/Xamarin.Forms.Platform.Tizen/Native/Entry.cs index 003a298b..26b775c8 100644 --- a/Xamarin.Forms.Platform.Tizen/Native/Entry.cs +++ b/Xamarin.Forms.Platform.Tizen/Native/Entry.cs @@ -183,7 +183,7 @@ namespace Xamarin.Forms.Platform.Tizen.Native /// Gets or sets the font weight for the text. /// /// The weight of the font. - public FontWeight FontWeight + public string FontWeight { get { diff --git a/Xamarin.Forms.Platform.Tizen/Native/FontWeight.cs b/Xamarin.Forms.Platform.Tizen/Native/FontWeight.cs deleted file mode 100644 index 90bb6370..00000000 --- a/Xamarin.Forms.Platform.Tizen/Native/FontWeight.cs +++ /dev/null @@ -1,21 +0,0 @@ -namespace Xamarin.Forms.Platform.Tizen.Native -{ - /// - /// Enumerates values that describe options for line braking. - /// - public enum FontWeight - { - None, - Normal, - Thin, - UltraLight, - Light, - Book, - Medium, - SemiBold, - Bold, - UltraBold, - Black, - ExtraBlack - } -} diff --git a/Xamarin.Forms.Platform.Tizen/Native/Label.cs b/Xamarin.Forms.Platform.Tizen/Native/Label.cs index 231127c2..a75e6aa8 100644 --- a/Xamarin.Forms.Platform.Tizen/Native/Label.cs +++ b/Xamarin.Forms.Platform.Tizen/Native/Label.cs @@ -178,7 +178,7 @@ namespace Xamarin.Forms.Platform.Tizen.Native /// Gets or sets the font weight for the text. /// /// The weight of the font. - public FontWeight FontWeight + public string FontWeight { get { diff --git a/Xamarin.Forms.Platform.Tizen/Native/Span.cs b/Xamarin.Forms.Platform.Tizen/Native/Span.cs index 50d596a4..8120105f 100644 --- a/Xamarin.Forms.Platform.Tizen/Native/Span.cs +++ b/Xamarin.Forms.Platform.Tizen/Native/Span.cs @@ -1,6 +1,7 @@ using System; using System.Text; using EColor = ElmSharp.Color; +using Specific = Xamarin.Forms.PlatformConfiguration.TizenSpecific; namespace Xamarin.Forms.Platform.Tizen.Native { @@ -79,7 +80,7 @@ namespace Xamarin.Forms.Platform.Tizen.Native /// /// Gets or sets the font weight for the text. /// - public FontWeight FontWeight { get; set; } + public string FontWeight { get; set; } /// /// Gets or sets the line break mode for the text. @@ -117,7 +118,7 @@ namespace Xamarin.Forms.Platform.Tizen.Native Text = ""; FontFamily = ""; FontSize = -1; - FontWeight = FontWeight.None; + FontWeight = Specific.FontWeight.None; FontAttributes = FontAttributes.None; ForegroundColor = EColor.Default; BackgroundColor = EColor.Default; @@ -192,41 +193,9 @@ namespace Xamarin.Forms.Platform.Tizen.Native else { // FontWeight is only available in case of FontAttributes.Bold is not used. - switch (FontWeight) + if(FontWeight != Specific.FontWeight.None) { - case FontWeight.Bold: - _formattingString.Append("font_weight=Bold "); - break; - case FontWeight.SemiBold: - _formattingString.Append("font_weight=SemiBold "); - break; - case FontWeight.UltraBold: - _formattingString.Append("font_weight=UltraBold "); - break; - case FontWeight.Black: - _formattingString.Append("font_weight=Black "); - break; - case FontWeight.ExtraBlack: - _formattingString.Append("font_weight=ExtraBlack "); - break; - case FontWeight.Book: - _formattingString.Append("font_weight=Book "); - break; - case FontWeight.Light: - _formattingString.Append("font_weight=Light "); - break; - case FontWeight.Medium: - _formattingString.Append("font_weight=Medium "); - break; - case FontWeight.Normal: - _formattingString.Append("font_weight=Normal "); - break; - case FontWeight.Thin: - _formattingString.Append("font_weight=Thin "); - break; - case FontWeight.UltraLight: - _formattingString.Append("font_weight=UltraLight "); - break; + _formattingString.AppendFormat("font_weight={0} ", FontWeight); } } diff --git a/Xamarin.Forms.Platform.Tizen/Renderers/ButtonRenderer.cs b/Xamarin.Forms.Platform.Tizen/Renderers/ButtonRenderer.cs index eea46e80..39f26b4f 100644 --- a/Xamarin.Forms.Platform.Tizen/Renderers/ButtonRenderer.cs +++ b/Xamarin.Forms.Platform.Tizen/Renderers/ButtonRenderer.cs @@ -1,7 +1,5 @@ using System; -using System.ComponentModel; using EColor = ElmSharp.Color; -using Xamarin.Forms.PlatformConfiguration.TizenSpecific; using Specific = Xamarin.Forms.PlatformConfiguration.TizenSpecific.VisualElement; namespace Xamarin.Forms.Platform.Tizen diff --git a/Xamarin.Forms.Platform.Tizen/Renderers/EntryRenderer.cs b/Xamarin.Forms.Platform.Tizen/Renderers/EntryRenderer.cs index 46af3520..7e7c8925 100644 --- a/Xamarin.Forms.Platform.Tizen/Renderers/EntryRenderer.cs +++ b/Xamarin.Forms.Platform.Tizen/Renderers/EntryRenderer.cs @@ -130,39 +130,7 @@ namespace Xamarin.Forms.Platform.Tizen void UpdateFontWeight() { - var weight = Specific.GetFontWeight(Element); - Control.FontWeight = ConvertToNativeFontWeight(weight); - } - - Native.FontWeight ConvertToNativeFontWeight(FontWeight weight) - { - switch (weight) - { - case FontWeight.Bold: - return Native.FontWeight.Bold; - case FontWeight.SemiBold: - return Native.FontWeight.SemiBold; - case FontWeight.UltraBold: - return Native.FontWeight.UltraBold; - case FontWeight.Black: - return Native.FontWeight.Black; - case FontWeight.ExtraBlack: - return Native.FontWeight.ExtraBlack; - case FontWeight.Book: - return Native.FontWeight.Book; - case FontWeight.Light: - return Native.FontWeight.Light; - case FontWeight.Medium: - return Native.FontWeight.Medium; - case FontWeight.Normal: - return Native.FontWeight.Normal; - case FontWeight.Thin: - return Native.FontWeight.Thin; - case FontWeight.UltraLight: - return Native.FontWeight.UltraLight; - default: - return Native.FontWeight.None; - } + Control.FontWeight = Specific.GetFontWeight(Element); } } } diff --git a/Xamarin.Forms.Platform.Tizen/Renderers/LabelRenderer.cs b/Xamarin.Forms.Platform.Tizen/Renderers/LabelRenderer.cs index 3f26f4ea..49611e4b 100644 --- a/Xamarin.Forms.Platform.Tizen/Renderers/LabelRenderer.cs +++ b/Xamarin.Forms.Platform.Tizen/Renderers/LabelRenderer.cs @@ -1,5 +1,3 @@ -using Xamarin.Forms.PlatformConfiguration.TizenSpecific; - using EColor = ElmSharp.Color; using Specific = Xamarin.Forms.PlatformConfiguration.TizenSpecific.Label; @@ -75,7 +73,7 @@ namespace Xamarin.Forms.Platform.Tizen void UpdateFormattedText() { - if(Element.FormattedText != null) + if (Element.FormattedText != null) Control.FormattedText = ConvertFormattedText(Element.FormattedText); } @@ -104,9 +102,7 @@ namespace Xamarin.Forms.Platform.Tizen void UpdateFontWeight() { - var weight = Specific.GetFontWeight(Element); - - Control.FontWeight = ConvertToNativeFontWeight(weight); + Control.FontWeight = Specific.GetFontWeight(Element); } Native.LineBreakMode ConvertToNativeLineBreakMode(LineBreakMode mode) @@ -128,36 +124,5 @@ namespace Xamarin.Forms.Platform.Tizen return Native.LineBreakMode.WordWrap; } } - - Native.FontWeight ConvertToNativeFontWeight(FontWeight weight) - { - switch (weight) - { - case FontWeight.Bold: - return Native.FontWeight.Bold; - case FontWeight.SemiBold: - return Native.FontWeight.SemiBold; - case FontWeight.UltraBold: - return Native.FontWeight.UltraBold; - case FontWeight.Black: - return Native.FontWeight.Black; - case FontWeight.ExtraBlack: - return Native.FontWeight.ExtraBlack; - case FontWeight.Book: - return Native.FontWeight.Book; - case FontWeight.Light: - return Native.FontWeight.Light; - case FontWeight.Medium: - return Native.FontWeight.Medium; - case FontWeight.Normal: - return Native.FontWeight.Normal; - case FontWeight.Thin: - return Native.FontWeight.Thin; - case FontWeight.UltraLight: - return Native.FontWeight.UltraLight; - default: - return Native.FontWeight.None; - } - } } } diff --git a/Xamarin.Forms.Platform.Tizen/Xamarin.Forms.Platform.Tizen.csproj b/Xamarin.Forms.Platform.Tizen/Xamarin.Forms.Platform.Tizen.csproj index 5c8ac950..6f8a65c9 100644 --- a/Xamarin.Forms.Platform.Tizen/Xamarin.Forms.Platform.Tizen.csproj +++ b/Xamarin.Forms.Platform.Tizen/Xamarin.Forms.Platform.Tizen.csproj @@ -80,7 +80,6 @@ - -- cgit v1.2.3