--- /dev/null
+using System;
+using Fitness.Views.Styles;
+using Tizen.NUI;
+using Tizen.NUI.BaseComponents;
+using Tizen.NUI.Components;
+
+namespace Fitness.Controls
+{
+ public class NinePatchButton : Button
+ {
+ public NinePatchButton()
+ {
+ this.Relayout += NinePatchButton_Relayout;
+ }
+
+ protected override void OnControlStateChanged(ControlStateChangedEventArgs controlStateChangedInfo)
+ {
+ UpdateButton();
+ }
+
+ private void NinePatchButton_Relayout(object sender, EventArgs e)
+ {
+ this.Relayout -= NinePatchButton_Relayout;
+ UpdateButton();
+ }
+
+ private static string AsPath(string url)
+ {
+ if (!String.IsNullOrEmpty(url) && url.Contains("*Resource*"))
+ {
+ string resource = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
+ url = url.Replace("*Resource*", resource);
+ }
+
+ return url;
+ }
+
+ private void UpdateButton(Color color, string url)
+ {
+ PropertyMap outputVisualMap = null;
+ if (color != null)
+ {
+ outputVisualMap = new Tizen.NUI.NPatchVisual()
+ {
+ URL = url,
+ MixColor = color,
+ }.OutputVisualMap;
+ }
+ else
+ {
+ outputVisualMap = new Tizen.NUI.NPatchVisual()
+ {
+ URL = url,
+ }.OutputVisualMap;
+ }
+
+ this.Background = outputVisualMap;
+ this.OverlayImage.Background = outputVisualMap;
+ }
+
+ private void UpdateButton()
+ {
+ if (ViewStyle is NinePatchButtonStyle style && !String.IsNullOrEmpty(style.NormalImageUrl))
+ {
+ if (ControlState == ControlState.Normal)
+ {
+ UpdateButton(style.NormalColor, AsPath(style.NormalImageUrl));
+ }
+ else if (ControlState == ControlState.Pressed)
+ {
+ UpdateButton(style.PressedColor, AsPath(style.PressedImageUrl ?? style.NormalImageUrl));
+ }
+ else if (ControlState == ControlState.Disabled)
+ {
+ UpdateButton(style.DisabledColor, AsPath(style.DisabledImageUrl ?? style.NormalImageUrl));
+ }
+ }
+ }
+ }
+}
{
public static class Buttons
{
- public static ButtonStyle Regular => new ButtonStyle
+ public static NinePatchButtonStyle Regular => new NinePatchButtonStyle
{
BackgroundColor = Color.Transparent,
- //BackgroundImage = new Selector<string>
- //{
- // Normal = NUIApplication.Current.DirectoryInfo.Resource + "styles/button/button_full_28px.png",
- // Pressed = NUIApplication.Current.DirectoryInfo.Resource + "styles/button/button_pressed.png",
- // Disabled = NUIApplication.Current.DirectoryInfo.Resource + "styles/button/button_disabled.png",
- //},
+ NormalImageUrl = "*Resource*/styles/button/button_full_28px.png",
Text = new TextLabelStyle
{
PixelSize = 32.0f,
},
};
- public static ButtonStyle Inverse => new ButtonStyle
+ public static NinePatchButtonStyle Inverse => new NinePatchButtonStyle
{
- BackgroundImage = new Selector<string>
- {
- Normal = NUIApplication.Current.DirectoryInfo.Resource + "styles/button/button_inverse.png",
- Pressed = NUIApplication.Current.DirectoryInfo.Resource + "styles/button/button_pressed.png",
- Disabled = NUIApplication.Current.DirectoryInfo.Resource + "styles/button/button_disabled.png",
- },
+ BackgroundColor = Color.Transparent,
+ NormalImageUrl = "*Resource*/styles/button/button_full_28px.png",
+ NormalColor = new Color(10f/255f, 14f/255f , 74f/255f, 1),
+ PressedColor = new Color(43f / 255f, 95f / 255f, 185f / 255f, 1),
Text = new TextLabelStyle
{
PixelSize = 32.0f,
},
};
- public static ButtonStyle Previous => new ButtonStyle
+ public static NinePatchButtonStyle Previous => new NinePatchButtonStyle
{
- BackgroundImage = new Selector<string>
- {
- Normal = NUIApplication.Current.DirectoryInfo.Resource + "styles/button/button_regular.png",
- Pressed = NUIApplication.Current.DirectoryInfo.Resource + "styles/button/button_pressed.png",
- Disabled = NUIApplication.Current.DirectoryInfo.Resource + "styles/button/button_disabled.png",
- },
+ BackgroundColor = Color.Transparent,
+ NormalImageUrl = "*Resource*/styles/button/button_full_28px.png",
Text = new TextLabelStyle
{
PixelSize = 24.0f,
IconRelativeOrientation = Button.IconOrientation.Left,
};
- public static ButtonStyle Next => new ButtonStyle
+ public static NinePatchButtonStyle Next => new NinePatchButtonStyle
{
- BackgroundImage = new Selector<string>
- {
- Normal = NUIApplication.Current.DirectoryInfo.Resource + "styles/button/button_regular.png",
- Pressed = NUIApplication.Current.DirectoryInfo.Resource + "styles/button/button_pressed.png",
- Disabled = NUIApplication.Current.DirectoryInfo.Resource + "styles/button/button_disabled.png",
- },
+ BackgroundColor = Color.Transparent,
+ NormalImageUrl = "*Resource*/styles/button/button_full_28px.png",
Text = new TextLabelStyle
{
PixelSize = 24.0f,