From cfa6fd0bfccc729a204fb1ad3b247f16f558c973 Mon Sep 17 00:00:00 2001 From: "k.stepaniuk" Date: Thu, 3 Dec 2020 13:03:56 +0100 Subject: [PATCH] Applying 9Patch to ExercisingView Signed-off-by: k.stepaniuk --- Fitness/Controls/NinePatchButton.cs | 80 ++++++++++++++++++++++ Fitness/FitnessApp.cs | 3 +- Fitness/Views/Styles/Buttons.cs | 41 ++++------- Fitness/Views/Styles/NinePatchButtonStyle.cs | 14 ++++ Fitness/res/styles/button/button_outline_28px.png | Bin 0 -> 1240 bytes 5 files changed, 108 insertions(+), 30 deletions(-) create mode 100644 Fitness/Controls/NinePatchButton.cs create mode 100644 Fitness/Views/Styles/NinePatchButtonStyle.cs create mode 100644 Fitness/res/styles/button/button_outline_28px.png diff --git a/Fitness/Controls/NinePatchButton.cs b/Fitness/Controls/NinePatchButton.cs new file mode 100644 index 0000000..a078ab8 --- /dev/null +++ b/Fitness/Controls/NinePatchButton.cs @@ -0,0 +1,80 @@ +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)); + } + } + } + } +} diff --git a/Fitness/FitnessApp.cs b/Fitness/FitnessApp.cs index 80a889c..a1508f1 100644 --- a/Fitness/FitnessApp.cs +++ b/Fitness/FitnessApp.cs @@ -15,8 +15,7 @@ namespace Fitness public void Initialize() { - //NavigationService.Instance.NavigateToMainView(); - NavigationService.Instance.NavigateToExercisingView(); + NavigationService.Instance.NavigateToMainView(); } protected override void OnCreate() diff --git a/Fitness/Views/Styles/Buttons.cs b/Fitness/Views/Styles/Buttons.cs index 99d740a..97e262b 100644 --- a/Fitness/Views/Styles/Buttons.cs +++ b/Fitness/Views/Styles/Buttons.cs @@ -6,15 +6,10 @@ namespace Fitness.Views.Styles { public static class Buttons { - public static ButtonStyle Regular => new ButtonStyle + public static NinePatchButtonStyle Regular => new NinePatchButtonStyle { BackgroundColor = Color.Transparent, - //BackgroundImage = new Selector - //{ - // 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, @@ -28,14 +23,12 @@ namespace Fitness.Views.Styles }, }; - public static ButtonStyle Inverse => new ButtonStyle + public static NinePatchButtonStyle Inverse => new NinePatchButtonStyle { - BackgroundImage = new Selector - { - 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, @@ -44,14 +37,10 @@ namespace Fitness.Views.Styles }, }; - public static ButtonStyle Previous => new ButtonStyle + public static NinePatchButtonStyle Previous => new NinePatchButtonStyle { - BackgroundImage = new Selector - { - 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, @@ -72,14 +61,10 @@ namespace Fitness.Views.Styles IconRelativeOrientation = Button.IconOrientation.Left, }; - public static ButtonStyle Next => new ButtonStyle + public static NinePatchButtonStyle Next => new NinePatchButtonStyle { - BackgroundImage = new Selector - { - 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, diff --git a/Fitness/Views/Styles/NinePatchButtonStyle.cs b/Fitness/Views/Styles/NinePatchButtonStyle.cs new file mode 100644 index 0000000..9ba6bb4 --- /dev/null +++ b/Fitness/Views/Styles/NinePatchButtonStyle.cs @@ -0,0 +1,14 @@ +using Tizen.NUI.Components; + +namespace Fitness.Views.Styles +{ + public class NinePatchButtonStyle : ButtonStyle + { + public string NormalImageUrl { get; set; } + public string PressedImageUrl { get; set; } + public string DisabledImageUrl { get; set; } + public Tizen.NUI.Color NormalColor { get; set; } + public Tizen.NUI.Color PressedColor { get; set; } + public Tizen.NUI.Color DisabledColor { get; set; } + } +} diff --git a/Fitness/res/styles/button/button_outline_28px.png b/Fitness/res/styles/button/button_outline_28px.png new file mode 100644 index 0000000000000000000000000000000000000000..a638f6e35cc00e6d8965e8f99697bbdb67dc6c1a GIT binary patch literal 1240 zcmV;}1Sk86P)6audbL-2u@)Wx z9{~FC{5UhRxomRxCO0>^x$HSPIY~Bm_dnk|JEO9gVU=aI>ut z5x&ojQxUoJA5Q%JSXKGH?P09}H?zAU@<>FU`iswPj0+L@>960a%I8_f?7$uHmWaHl z?B=g;mW>7n|ElVFZr3g$NCX23fp8GiA&#{q20Dklhp zKy5;0ASU1;!Zc$#;ARFVUW>^6L?`#=q>ulBIT2Vl2!QmkE~?OEGzV^GEWDinK2X&V zIyJ)|6y<-h1eb`{J)~A{o41f^~xc;F~_sf8r86y4B zT@fzl<-EnZlu9oC`yzs2#Pz)^urKw%9rPDBU}qxow&1~~`)*~P@9~p}JP;8K-}9P1 zP6qDc{n z`J2F9T=)}~eBmx@TIwXO?p#$jE6>RSCotf3qN*>aU3eM(XJ&{z`c9CQhPR`@o!ejC zbz#gpjmX+2mPdFPJB;#XVw`UPUm0#E`VMehT*~!p;LhzIeKlwktbA(d)}8Ak!132u z^4{xql?Y}QTn`IB0(?hAp7q(1PvCkSX1=Q`I7fgZ<|Gs_0@*A{+s3D>=lMYf7k#0s z>;Hi#Kad*Q=xReD;n^w-UCmE(oRVArx;^=tIN>_?%G8kdHr<>Q2IMYD zZc9OKL}$s(LrLA((nNQay1Zt^KS@fKiXp0o>*~gq0(hk^k0O5#U%63R=Z2M!y0JbL z_|?_r6_<2I-B@X@Xr~g8skN=E%c}?OmY!Rdv{saI$)%`$^8*NFr$}dMt!)|b#LZDn z5DhlFs(REZYb%SH8I_lz$8<*Q6qcQq15XTIWNY{eyarOhwfDXfX^Aqc=GXp?Hi2DlDKTUWGV5PQ>((QPwM1w2M2 z*M3C-5kz27)wEe1T)I4~ABhhddQZTFi18g+haa?Yr zW_~&yFF`V<#S-bDs5UonMFFa_7RzdrYYDbK&(VKfyq_U^v%5$D0000