diff options
author | Seunghyun Choi <sh4682.choi@samsung.com> | 2016-12-21 18:11:54 +0900 |
---|---|---|
committer | Kangho Hur <kangho.hur@samsung.com> | 2017-04-24 13:36:47 +0900 |
commit | ef513157b7aac84c59a3184fc45146aa7c9a0b35 (patch) | |
tree | 275aeec8c8790b20717555d6c478e2f0a9c7f67f | |
parent | c47d7439267e1c515a0b5097e9e2299f5cfb4fc9 (diff) | |
download | xamarin-forms-ef513157b7aac84c59a3184fc45146aa7c9a0b35.tar.gz xamarin-forms-ef513157b7aac84c59a3184fc45146aa7c9a0b35.tar.bz2 xamarin-forms-ef513157b7aac84c59a3184fc45146aa7c9a0b35.zip |
Add Button Style
- Add Button Style(Circle, Bottom)
- Approval of the RFC is required.
(http://suprem.sec.samsung.net/confluence/display/SPTDTLC/%5BFormsTizen%5D+RFC+2+-+Button+Style)
Change-Id: I545e0cc2417298f90468b651030937665f547105
Signed-off-by: Seunghyun Choi <sh4682.choi@samsung.com>
5 files changed, 113 insertions, 2 deletions
diff --git a/Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/Button.cs b/Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/Button.cs new file mode 100644 index 00000000..e74650fc --- /dev/null +++ b/Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/Button.cs @@ -0,0 +1,30 @@ +namespace Xamarin.Forms.PlatformConfiguration.TizenSpecific +{ + using FormsElement = Forms.Button; + + public static class Button + { + public static readonly BindableProperty ButtonStyleProperty = BindableProperty.Create("ButtonStyle", typeof(ButtonStyle), typeof(FormsElement), ButtonStyle.Default); + + public static ButtonStyle GetButtonStyle(BindableObject element) + { + return (ButtonStyle)element.GetValue(ButtonStyleProperty); + } + + public static void SetButtonStyle(BindableObject element, ButtonStyle value) + { + element.SetValue(ButtonStyleProperty, value); + } + + public static ButtonStyle GetButtonStyle(this IPlatformElementConfiguration<Tizen, FormsElement> config) + { + return GetButtonStyle(config.Element); + } + + public static IPlatformElementConfiguration<Tizen, FormsElement> SetButtonStyle(this IPlatformElementConfiguration<Tizen, FormsElement> config, ButtonStyle value) + { + SetButtonStyle(config.Element, value); + return config; + } + } +} diff --git a/Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/ButtonStyle.cs b/Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/ButtonStyle.cs new file mode 100644 index 00000000..abe7bd81 --- /dev/null +++ b/Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/ButtonStyle.cs @@ -0,0 +1,9 @@ +namespace Xamarin.Forms.PlatformConfiguration.TizenSpecific +{ + public enum ButtonStyle + { + Default, + Circle, + Bottom + } +} diff --git a/Xamarin.Forms.Core/Xamarin.Forms.Core.csproj b/Xamarin.Forms.Core/Xamarin.Forms.Core.csproj index 07dd8f20..bf2fdeff 100644 --- a/Xamarin.Forms.Core/Xamarin.Forms.Core.csproj +++ b/Xamarin.Forms.Core/Xamarin.Forms.Core.csproj @@ -112,6 +112,8 @@ <Compile Include="PlatformConfiguration\iOSSpecific\VisualElement.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\WindowsSpecific\MasterDetailPage.cs" /> <Compile Include="PlatformConfiguration\WindowsSpecific\CollapseStyle.cs" /> <Compile Include="Configuration.cs" /> @@ -470,7 +472,6 @@ <Name>Xamarin.Forms.Platform</Name> </ProjectReference> </ItemGroup> - <ItemGroup /> <PropertyGroup> <PostBuildEvent> </PostBuildEvent> diff --git a/Xamarin.Forms.Platform.Tizen/Native/Button.cs b/Xamarin.Forms.Platform.Tizen/Native/Button.cs index 8f85da63..71ec0c10 100644 --- a/Xamarin.Forms.Platform.Tizen/Native/Button.cs +++ b/Xamarin.Forms.Platform.Tizen/Native/Button.cs @@ -20,7 +20,7 @@ namespace Xamarin.Forms.Platform.Tizen.Native /// <summary> /// The internal padding of the button, helps to determine the size. /// </summary> - readonly ESize _internalPadding; + ESize _internalPadding; /// <summary> /// Optional image, if set will be drawn on the button. @@ -201,6 +201,18 @@ namespace Xamarin.Forms.Platform.Tizen.Native var padding = _internalPadding; + if (Style == "circle") + { + var circleTextPadding = (EdjeObject["icon_text_padding"]?.Geometry.Height).GetValueOrDefault(0); + var circleHeight = padding.Height + ((rawSize.Width == 0) ? 0 : circleTextPadding + formattedSize.Height); + + return new ESize + { + Width = padding.Width, + Height = circleHeight + }; + } + if (rawSize.Width > availableWidth) { // if the raw text width is larger than the available width, use @@ -299,5 +311,30 @@ namespace Xamarin.Forms.Platform.Tizen.Native SetPartContent("icon", _image); } } + + public void UpdateStyle(string style) + { + if (Style != style) + { + Style = style; + + if (Style == "circle") + { + var circleSize = (EdjeObject["bg"]?.Geometry.Width).GetValueOrDefault(0); + _internalPadding = new ESize(circleSize, circleSize); + _span.HorizontalTextAlignment = TextAlignment.Center; + } + else if (Style == "bottom") + { + _internalPadding = GetInternalPadding(); + _span.HorizontalTextAlignment = TextAlignment.Auto; + } + else + { + _span.HorizontalTextAlignment = TextAlignment.Auto; + } + ApplyTextAndStyle(); + } + } } } diff --git a/Xamarin.Forms.Platform.Tizen/Renderers/ButtonRenderer.cs b/Xamarin.Forms.Platform.Tizen/Renderers/ButtonRenderer.cs index a34df549..8af7bb69 100644 --- a/Xamarin.Forms.Platform.Tizen/Renderers/ButtonRenderer.cs +++ b/Xamarin.Forms.Platform.Tizen/Renderers/ButtonRenderer.cs @@ -1,5 +1,8 @@ using System; +using System.ComponentModel; using EColor = ElmSharp.Color; +using Xamarin.Forms.PlatformConfiguration.TizenSpecific; +using Specific = Xamarin.Forms.PlatformConfiguration.TizenSpecific.Button; namespace Xamarin.Forms.Platform.Tizen { @@ -38,12 +41,23 @@ namespace Xamarin.Forms.Platform.Tizen if (e.NewElement != null) { + UpdateStyle(); Control.Clicked += ButtonClickedHandler; } base.OnElementChanged(e); } + protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) + { + base.OnElementPropertyChanged(sender, e); + + if (e.PropertyName == Specific.ButtonStyleProperty.PropertyName) + { + UpdateStyle(); + } + } + protected override Size MinimumSize() { return new Size(Control.MinimumWidth, Control.MinimumHeight); @@ -84,6 +98,26 @@ namespace Xamarin.Forms.Platform.Tizen } } + void UpdateStyle() + { + string style; + switch (Specific.GetButtonStyle(Element)) + { + case ButtonStyle.Circle: + style = "circle"; + break; + case ButtonStyle.Bottom: + style = "bottom"; + break; + default: + style = "default"; + break; + } + + Control.UpdateStyle(style); + ((IVisualElementController)Element).NativeSizeChanged(); + } + void UpdateBorder() { /* The simpler way is to create some specialized theme for button in |