diff options
author | Kangho Hur <kangho.hur@samsung.com> | 2017-01-24 14:09:11 +0900 |
---|---|---|
committer | Kangho Hur <kangho.hur@samsung.com> | 2017-04-24 13:36:52 +0900 |
commit | b4d15c3fa75dd0bdf2600f80c7623adf06ba84e0 (patch) | |
tree | 7fb6e1e6c53122dfd5953d3dad0646e713ffdca7 | |
parent | bb9c8517a890e4a9d1a96e1f99bc9123dcc8a0a6 (diff) | |
download | xamarin-forms-b4d15c3fa75dd0bdf2600f80c7623adf06ba84e0.tar.gz xamarin-forms-b4d15c3fa75dd0bdf2600f80c7623adf06ba84e0.tar.bz2 xamarin-forms-b4d15c3fa75dd0bdf2600f80c7623adf06ba84e0.zip |
Add FontWeight for Label and Entry
- 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, 288 insertions, 4 deletions
diff --git a/Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/Entry.cs b/Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/Entry.cs new file mode 100644 index 00000000..c84dcc36 --- /dev/null +++ b/Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/Entry.cs @@ -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 index 00000000..8838bc07 --- /dev/null +++ b/Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/FontWeight.cs @@ -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 index 00000000..d95daa83 --- /dev/null +++ b/Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/Label.cs @@ -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; + } + } +} diff --git a/Xamarin.Forms.Core/Xamarin.Forms.Core.csproj b/Xamarin.Forms.Core/Xamarin.Forms.Core.csproj index bca78f26..80d03e17 100644 --- a/Xamarin.Forms.Core/Xamarin.Forms.Core.csproj +++ b/Xamarin.Forms.Core/Xamarin.Forms.Core.csproj @@ -110,11 +110,14 @@ <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" /> diff --git a/Xamarin.Forms.Platform.Tizen/Native/Entry.cs b/Xamarin.Forms.Platform.Tizen/Native/Entry.cs index 808155c5..003a298b 100644 --- a/Xamarin.Forms.Platform.Tizen/Native/Entry.cs +++ b/Xamarin.Forms.Platform.Tizen/Native/Entry.cs @@ -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 index 00000000..90bb6370 --- /dev/null +++ b/Xamarin.Forms.Platform.Tizen/Native/FontWeight.cs @@ -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 + } +} diff --git a/Xamarin.Forms.Platform.Tizen/Native/Label.cs b/Xamarin.Forms.Platform.Tizen/Native/Label.cs index 9d52cde2..231127c2 100644 --- a/Xamarin.Forms.Platform.Tizen/Native/Label.cs +++ b/Xamarin.Forms.Platform.Tizen/Native/Label.cs @@ -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> diff --git a/Xamarin.Forms.Platform.Tizen/Native/Span.cs b/Xamarin.Forms.Platform.Tizen/Native/Span.cs index 4a5daf3c..028e9db9 100644 --- a/Xamarin.Forms.Platform.Tizen/Native/Span.cs +++ b/Xamarin.Forms.Platform.Tizen/Native/Span.cs @@ -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 "); diff --git a/Xamarin.Forms.Platform.Tizen/Renderers/EntryRenderer.cs b/Xamarin.Forms.Platform.Tizen/Renderers/EntryRenderer.cs index 95828c04..46af3520 100644 --- a/Xamarin.Forms.Platform.Tizen/Renderers/EntryRenderer.cs +++ b/Xamarin.Forms.Platform.Tizen/Renderers/EntryRenderer.cs @@ -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; + } + } } } diff --git a/Xamarin.Forms.Platform.Tizen/Renderers/LabelRenderer.cs b/Xamarin.Forms.Platform.Tizen/Renderers/LabelRenderer.cs index 9f4157ed..a1c07134 100644 --- a/Xamarin.Forms.Platform.Tizen/Renderers/LabelRenderer.cs +++ b/Xamarin.Forms.Platform.Tizen/Renderers/LabelRenderer.cs @@ -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; + } + } } } diff --git a/Xamarin.Forms.Platform.Tizen/Xamarin.Forms.Platform.Tizen.csproj b/Xamarin.Forms.Platform.Tizen/Xamarin.Forms.Platform.Tizen.csproj index 818e4803..012512b1 100644 --- a/Xamarin.Forms.Platform.Tizen/Xamarin.Forms.Platform.Tizen.csproj +++ b/Xamarin.Forms.Platform.Tizen/Xamarin.Forms.Platform.Tizen.csproj @@ -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" /> @@ -160,4 +161,4 @@ <_FullFrameworkReferenceAssemblyPaths>$(MSBuildThisFileDirectory)</_FullFrameworkReferenceAssemblyPaths> <AutoUnifyAssemblyReferences>true</AutoUnifyAssemblyReferences> </PropertyGroup> -</Project> +</Project>
\ No newline at end of file diff --git a/packaging/xamarin-forms-tizen.spec b/packaging/xamarin-forms-tizen.spec index f9778baa..968fd92a 100644 --- a/packaging/xamarin-forms-tizen.spec +++ b/packaging/xamarin-forms-tizen.spec @@ -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 |