Add FontWeight for Label and Entry
authorKangho Hur <kangho.hur@samsung.com>
Tue, 24 Jan 2017 05:09:11 +0000 (14:09 +0900)
committerKangho Hur <kangho.hur@samsung.com>
Mon, 10 Jul 2017 02:11:18 +0000 (11:11 +0900)
- This change is for the referernce application (Clock) to follow UX guideline. (Internal only).
- We will improve design and implementation of this APIs in the next release, if requred.

Change-Id: Ifac91174a5859adecc9ec6bff1a1d568512ee70b

12 files changed:
Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/Entry.cs [new file with mode: 0644]
Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/FontWeight.cs [new file with mode: 0644]
Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/Label.cs [new file with mode: 0644]
Xamarin.Forms.Core/Xamarin.Forms.Core.csproj
Xamarin.Forms.Platform.Tizen/Native/Entry.cs
Xamarin.Forms.Platform.Tizen/Native/FontWeight.cs [new file with mode: 0644]
Xamarin.Forms.Platform.Tizen/Native/Label.cs
Xamarin.Forms.Platform.Tizen/Native/Span.cs
Xamarin.Forms.Platform.Tizen/Renderers/EntryRenderer.cs
Xamarin.Forms.Platform.Tizen/Renderers/LabelRenderer.cs
Xamarin.Forms.Platform.Tizen/Xamarin.Forms.Platform.Tizen.csproj
packaging/xamarin-forms-tizen.spec

diff --git a/Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/Entry.cs b/Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/Entry.cs
new file mode 100644 (file)
index 0000000..c84dcc3
--- /dev/null
@@ -0,0 +1,30 @@
+namespace Xamarin.Forms.PlatformConfiguration.TizenSpecific
+{
+       using FormsElement = Forms.Entry;
+
+       public static class Entry
+       {
+               public static readonly BindableProperty FontWeightProperty = BindableProperty.Create("FontWeight", typeof(FontWeight), typeof(FormsElement), FontWeight.None);
+
+               public static FontWeight GetFontWeight(BindableObject element)
+               {
+                       return (FontWeight)element.GetValue(FontWeightProperty);
+               }
+
+               public static void SetFontWeight(BindableObject element, FontWeight weight)
+               {
+                       element.SetValue(FontWeightProperty, weight);
+               }
+
+               public static FontWeight GetFontWeight(this IPlatformElementConfiguration<Tizen, FormsElement> config)
+               {
+                       return GetFontWeight(config.Element);
+               }
+
+               public static IPlatformElementConfiguration<Tizen, FormsElement> SetFontWeight(this IPlatformElementConfiguration<Tizen, FormsElement> config, FontWeight 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
new file mode 100644 (file)
index 0000000..8838bc0
--- /dev/null
@@ -0,0 +1,18 @@
+namespace Xamarin.Forms.PlatformConfiguration.TizenSpecific
+{
+       public enum FontWeight
+       {
+               None,
+               Normal,
+               Thin,
+               UltraLight,
+               Light,
+               Book,
+               Medium,
+               SemiBold,
+               Bold,
+               UltraBold,
+               Black,
+               ExtraBlack
+       }
+}
diff --git a/Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/Label.cs b/Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/Label.cs
new file mode 100644 (file)
index 0000000..d95daa8
--- /dev/null
@@ -0,0 +1,30 @@
+namespace Xamarin.Forms.PlatformConfiguration.TizenSpecific
+{
+       using FormsElement = Forms.Label;
+
+       public static class Label
+       {
+               public static readonly BindableProperty FontWeightProperty = BindableProperty.Create("FontWeight", typeof(FontWeight), typeof(FormsElement), FontWeight.None);
+
+               public static FontWeight GetFontWeight(BindableObject element)
+               {
+                       return (FontWeight)element.GetValue(FontWeightProperty);
+               }
+
+               public static void SetFontWeight(BindableObject element, FontWeight weight)
+               {
+                       element.SetValue(FontWeightProperty, weight);
+               }
+
+               public static FontWeight GetFontWeight(this IPlatformElementConfiguration<Tizen, FormsElement> config)
+               {
+                       return GetFontWeight(config.Element);
+               }
+
+               public static IPlatformElementConfiguration<Tizen, FormsElement> SetFontWeight(this IPlatformElementConfiguration<Tizen, FormsElement> config, FontWeight weight)
+               {
+                       SetFontWeight(config.Element, weight);
+                       return config;
+               }
+       }
+}
index 84f132d..a184c38 100644 (file)
     <Compile Include="PlatformConfiguration\iOSSpecific\UIStatusBarAnimation.cs" />
     <Compile Include="PlatformConfiguration\iOSSpecific\UpdateMode.cs" />
     <Compile Include="PlatformConfiguration\iOSSpecific\VisualElement.cs" />
+    <Compile Include="PlatformConfiguration\TizenSpecific\Entry.cs" />
+    <Compile Include="PlatformConfiguration\TizenSpecific\Label.cs" />
     <Compile Include="PlatformConfiguration\TizenSpecific\Image.cs" />
     <Compile Include="PlatformConfiguration\TizenSpecific\ProgressBar.cs" />
     <Compile Include="PlatformConfiguration\TizenSpecific\Button.cs" />
     <Compile Include="PlatformConfiguration\TizenSpecific\ButtonStyle.cs" />
     <Compile Include="PlatformConfiguration\TizenSpecific\Switch.cs" />
+    <Compile Include="PlatformConfiguration\TizenSpecific\FontWeight.cs" />
     <Compile Include="PlatformConfiguration\TizenSpecific\SwitchStyle.cs" />
     <Compile Include="PlatformConfiguration\WindowsSpecific\MasterDetailPage.cs" />
     <Compile Include="PlatformConfiguration\WindowsSpecific\CollapseStyle.cs" />
index 808155c..003a298 100644 (file)
@@ -1,4 +1,4 @@
-using System;
+using System;
 using ElmSharp;
 using EEntry = ElmSharp.Entry;
 using EColor = ElmSharp.Color;
@@ -180,6 +180,30 @@ namespace Xamarin.Forms.Platform.Tizen.Native
                }
 
                /// <summary>
+               /// Gets or sets the font weight for the text.
+               /// </summary>
+               /// <value>The weight of the font.</value>
+               public FontWeight FontWeight
+               {
+                       get
+                       {
+                               return _span.FontWeight;
+                       }
+
+                       set
+                       {
+                               if (value != _span.FontWeight)
+                               {
+                                       _span.FontWeight = value;
+                                       ApplyTextAndStyle();
+
+                                       _placeholderSpan.FontWeight = value;
+                                       ApplyPlaceholderAndStyle();
+                               }
+                       }
+               }
+
+               /// <summary>
                /// Gets or sets the horizontal text alignment of both text and placeholder.
                /// </summary>
                /// <value>The horizontal text alignment of both text and placeholder.</value>
diff --git a/Xamarin.Forms.Platform.Tizen/Native/FontWeight.cs b/Xamarin.Forms.Platform.Tizen/Native/FontWeight.cs
new file mode 100644 (file)
index 0000000..90bb637
--- /dev/null
@@ -0,0 +1,21 @@
+namespace Xamarin.Forms.Platform.Tizen.Native
+{
+       /// <summary>
+       /// Enumerates values that describe options for line braking.
+       /// </summary>
+       public enum FontWeight
+       {
+               None,
+               Normal,
+               Thin,
+               UltraLight,
+               Light,
+               Book,
+               Medium,
+               SemiBold,
+               Bold,
+               UltraBold,
+               Black,
+               ExtraBlack
+       }
+}
index 9d52cde..231127c 100644 (file)
@@ -175,6 +175,27 @@ namespace Xamarin.Forms.Platform.Tizen.Native
                }
 
                /// <summary>
+               /// Gets or sets the font weight for the text.
+               /// </summary>
+               /// <value>The weight of the font.</value>
+               public FontWeight FontWeight
+               {
+                       get
+                       {
+                               return _span.FontWeight;
+                       }
+
+                       set
+                       {
+                               if (value != _span.FontWeight)
+                               {
+                                       _span.FontWeight = value;
+                                       ApplyTextAndStyle();
+                               }
+                       }
+               }
+
+               /// <summary>
                /// Gets or sets the line wrap option.
                /// </summary>
                /// <value>The line break mode.</value>
index 4a5daf3..028e9db 100644 (file)
@@ -77,6 +77,11 @@ namespace Xamarin.Forms.Platform.Tizen.Native
                public double FontSize { get; set; }
 
                /// <summary>
+               /// Gets or sets the font weight for the text.
+               /// </summary>
+               public FontWeight FontWeight { get; set; }
+
+               /// <summary>
                /// Gets or sets the line break mode for the text.
                /// See <see cref="LineBreakMode"/> for information about LineBreakMode.
                /// </summary>
@@ -112,6 +117,7 @@ namespace Xamarin.Forms.Platform.Tizen.Native
                        Text = "";
                        FontFamily = "";
                        FontSize = -1;
+                       FontWeight = FontWeight.None;
                        FontAttributes = FontAttributes.None;
                        ForegroundColor = EColor.Default;
                        BackgroundColor = EColor.Default;
@@ -183,6 +189,47 @@ namespace Xamarin.Forms.Platform.Tizen.Native
                        {
                                _formattingString.Append("font_weight=Bold ");
                        }
+                       else
+                       {
+                               // FontWeight is only available in case of FontAttributes.Bold is not used.
+                               switch (FontWeight)
+                               {
+                                       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;
+                               }
+                       }
+
                        if ((FontAttributes & FontAttributes.Italic) != 0)
                        {
                                _formattingString.Append("font_style=italic ");
index 95828c0..46af352 100644 (file)
@@ -1,5 +1,8 @@
-using System;
+using System;
+using Xamarin.Forms.PlatformConfiguration.TizenSpecific;
+
 using EColor = ElmSharp.Color;
+using Specific = Xamarin.Forms.PlatformConfiguration.TizenSpecific.Entry;
 
 namespace Xamarin.Forms.Platform.Tizen
 {
@@ -21,6 +24,7 @@ namespace Xamarin.Forms.Platform.Tizen
                        RegisterPropertyHandler(Entry.KeyboardProperty, UpdateKeyboard);
                        RegisterPropertyHandler(Entry.PlaceholderProperty, UpdatePlaceholder);
                        RegisterPropertyHandler(Entry.PlaceholderColorProperty, UpdatePlaceholderColor);
+                       RegisterPropertyHandler(Specific.FontWeightProperty, UpdateFontWeight);
                }
 
                protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
@@ -123,5 +127,42 @@ namespace Xamarin.Forms.Platform.Tizen
                {
                        Control.PlaceholderColor = Element.PlaceholderColor.IsDefault ? s_defaultPlaceholderColor : Element.PlaceholderColor.ToNative();
                }
+
+               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;
+                       }
+               }
        }
 }
index 9f4157e..a1c0713 100644 (file)
@@ -1,4 +1,7 @@
+using Xamarin.Forms.PlatformConfiguration.TizenSpecific;
+
 using EColor = ElmSharp.Color;
+using Specific = Xamarin.Forms.PlatformConfiguration.TizenSpecific.Label;
 
 namespace Xamarin.Forms.Platform.Tizen
 {
@@ -19,6 +22,7 @@ namespace Xamarin.Forms.Platform.Tizen
                        RegisterPropertyHandler(Label.HorizontalTextAlignmentProperty, UpdateTextAlignment);
                        RegisterPropertyHandler(Label.VerticalTextAlignmentProperty, UpdateTextAlignment);
                        RegisterPropertyHandler(Label.FormattedTextProperty, UpdateFormattedText);
+                       RegisterPropertyHandler(Specific.FontWeightProperty, UpdateFontWeight);
                }
 
                protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
@@ -117,6 +121,19 @@ namespace Xamarin.Forms.Platform.Tizen
                        Control.LineBreakMode = ConvertToNativeLineBreakMode(Element.LineBreakMode);
                }
 
+               void UpdateFontWeight()
+               {
+                       var weight = Specific.GetFontWeight(Element);
+                       if (Control.FormattedText != null)
+                       {
+                               foreach (var span in Control.FormattedText.Spans)
+                               {
+                                       span.FontWeight = ConvertToNativeFontWeight(weight);
+                               }
+                       }
+                       Control.FontWeight = ConvertToNativeFontWeight(weight);
+               }
+
                Native.LineBreakMode ConvertToNativeLineBreakMode(LineBreakMode mode)
                {
                        switch (mode)
@@ -136,5 +153,36 @@ 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;
+                       }
+               }
        }
 }
index 818e480..012512b 100644 (file)
@@ -79,6 +79,7 @@
     <Compile Include="Native\Keyboard.cs" />
     <Compile Include="Native\Label.cs" />
     <Compile Include="Native\LayoutEventArgs.cs" />
+    <Compile Include="Native\FontWeight.cs" />
     <Compile Include="Native\LineBreakMode.cs" />
     <Compile Include="Native\ListView.cs" />
     <Compile Include="Native\MasterDetailPage.cs" />
     <_FullFrameworkReferenceAssemblyPaths>$(MSBuildThisFileDirectory)</_FullFrameworkReferenceAssemblyPaths>
     <AutoUnifyAssemblyReferences>true</AutoUnifyAssemblyReferences>
   </PropertyGroup>
-</Project>
+</Project>
\ No newline at end of file
index f9778ba..968fd92 100644 (file)
@@ -1,7 +1,7 @@
 %define XF_VERSION 2.3.3.175
 
 # Increase this XF_TIZEN_VERSION when any public APIs of Xamarin.Forms.Platform.Tizen are changed.
-%define XF_TIZEN_VERSION beta-006
+%define XF_TIZEN_VERSION beta-007
 
 Name: xamarin-forms-tizen
 Summary: Xamarin.Forms for Tizen platform