From ce796607c168bb88dc66a55095f04d84b2540fbc Mon Sep 17 00:00:00 2001 From: "Eunki, Hong" Date: Fri, 16 Sep 2022 14:41:26 +0900 Subject: [PATCH] [NUI] Add View.ColorRed / ColorBlue / ColorGreen Property Previously, we can only change whole color components (RGBA) or change Opacity (A). If we change only RGB values without change Opacity value, we need to get opacity property first, and make new Color(). To change each components without create new Color class, We make new property to change each components. Signed-off-by: Eunki, Hong --- src/Tizen.NUI/src/public/BaseComponents/View.cs | 70 ++++++++++++++++ .../public/BaseComponents/ViewBindableProperty.cs | 98 +++++++++++++++++++++- .../src/public/BaseComponents/ViewEnum.cs | 4 + .../testcase/public/TSView.cs | 83 ++++++++++++++++++ 4 files changed, 254 insertions(+), 1 deletion(-) diff --git a/src/Tizen.NUI/src/public/BaseComponents/View.cs b/src/Tizen.NUI/src/public/BaseComponents/View.cs index 34ccf01..7c6b303 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/View.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/View.cs @@ -2773,6 +2773,10 @@ namespace Tizen.NUI.BaseComponents /// /// The Color of View. This is an RGBA value. + /// Each RGBA components match as , , , and . + /// This property will multiply the final color of this view. (BackgroundColor, BorderlineColor, BackgroundImage, etc). + /// For example, if view.BackgroundColor = Color.Yellow and view.Color = Color.Purple, this view will shown as Red. + /// Inherient of color value depend on . /// /// /// @@ -2806,6 +2810,72 @@ namespace Tizen.NUI.BaseComponents } /// + /// The Red component of View.Color. + /// + /// + /// + /// Animatable - This property can be animated using Animation class. + /// + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public float ColorRed + { + get + { + return (float)GetValue(ColorRedProperty); + } + set + { + SetValue(ColorRedProperty, value); + NotifyPropertyChanged(); + } + } + + /// + /// The Green component of View.Color. + /// + /// + /// + /// Animatable - This property can be animated using Animation class. + /// + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public float ColorGreen + { + get + { + return (float)GetValue(ColorGreenProperty); + } + set + { + SetValue(ColorGreenProperty, value); + NotifyPropertyChanged(); + } + } + + /// + /// The Blue component of View.Color. + /// + /// + /// + /// Animatable - This property can be animated using Animation class. + /// + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public float ColorBlue + { + get + { + return (float)GetValue(ColorBlueProperty); + } + set + { + SetValue(ColorBlueProperty, value); + NotifyPropertyChanged(); + } + } + + /// /// Set the layout on this View. Replaces any existing Layout. /// /// diff --git a/src/Tizen.NUI/src/public/BaseComponents/ViewBindableProperty.cs b/src/Tizen.NUI/src/public/BaseComponents/ViewBindableProperty.cs index 494d9d6..21570e8 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/ViewBindableProperty.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/ViewBindableProperty.cs @@ -154,7 +154,7 @@ namespace Tizen.NUI.BaseComponents defaultValueCreator: (bindable) => { var view = (View)bindable; - var tmpProperty = view.GetProperty(Interop.ActorProperty.ColorGet()); + var tmpProperty = view.GetProperty(View.Property.COLOR); if (view.internalColor == null) { @@ -168,6 +168,63 @@ namespace Tizen.NUI.BaseComponents } ); + /// + /// ColorRedProperty + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public static readonly BindableProperty ColorRedProperty = BindableProperty.Create(nameof(ColorRed), typeof(float), typeof(View), default(float), + propertyChanged: (bindable, oldValue, newValue) => + { + var view = (View)bindable; + view.SetColorRed((float?)newValue); + }, + defaultValueCreator: (bindable) => + { + var view = (View)bindable; + float temp = 0.0f; + Tizen.NUI.Object.GetProperty((System.Runtime.InteropServices.HandleRef)view.SwigCPtr, View.Property.ColorRed).Get(out temp); + return temp; + } + ); + + /// + /// ColorGreenProperty + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public static readonly BindableProperty ColorGreenProperty = BindableProperty.Create(nameof(ColorGreen), typeof(float), typeof(View), default(float), + propertyChanged: (bindable, oldValue, newValue) => + { + var view = (View)bindable; + view.SetColorGreen((float?)newValue); + }, + defaultValueCreator: (bindable) => + { + var view = (View)bindable; + float temp = 0.0f; + Tizen.NUI.Object.GetProperty((System.Runtime.InteropServices.HandleRef)view.SwigCPtr, View.Property.ColorGreen).Get(out temp); + return temp; + } + ); + + /// + /// ColorBlueProperty + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public static readonly BindableProperty ColorBlueProperty = BindableProperty.Create(nameof(ColorBlue), typeof(float), typeof(View), default(float), + propertyChanged: (bindable, oldValue, newValue) => + { + var view = (View)bindable; + view.SetColorBlue((float?)newValue); + }, + defaultValueCreator: (bindable) => + { + var view = (View)bindable; + float temp = 0.0f; + Tizen.NUI.Object.GetProperty((System.Runtime.InteropServices.HandleRef)view.SwigCPtr, View.Property.ColorBlue).Get(out temp); + return temp; + } + ); + /// BackgroundImageProperty [EditorBrowsable(EditorBrowsableState.Never)] public static readonly BindableProperty BackgroundImageProperty = BindableProperty.Create(nameof(BackgroundImage), typeof(string), typeof(View), default(string), @@ -2785,6 +2842,45 @@ namespace Tizen.NUI.BaseComponents throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } + private void SetColorRed(float? value) + { + if (value == null) + { + return; + } + + using var propertyValue = new Tizen.NUI.PropertyValue((float)value); + Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)SwigCPtr, View.Property.ColorRed, propertyValue); + if (NDalicPINVOKE.SWIGPendingException.Pending) + throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + private void SetColorGreen(float? value) + { + if (value == null) + { + return; + } + + using var propertyValue = new Tizen.NUI.PropertyValue((float)value); + Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)SwigCPtr, View.Property.ColorGreen, propertyValue); + if (NDalicPINVOKE.SWIGPendingException.Pending) + throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + private void SetColorBlue(float? value) + { + if (value == null) + { + return; + } + + using var propertyValue = new Tizen.NUI.PropertyValue((float)value); + Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)SwigCPtr, View.Property.ColorBlue, propertyValue); + if (NDalicPINVOKE.SWIGPendingException.Pending) + throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + private void SetOpacity(float? value) { if (value == null) diff --git a/src/Tizen.NUI/src/public/BaseComponents/ViewEnum.cs b/src/Tizen.NUI/src/public/BaseComponents/ViewEnum.cs index 3b76ce0..825e27d 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/ViewEnum.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/ViewEnum.cs @@ -224,6 +224,10 @@ namespace Tizen.NUI.BaseComponents internal static readonly int ScaleZ = Interop.ActorProperty.ScaleZGet(); internal static readonly int WorldScale = Interop.ActorProperty.WorldScaleGet(); internal static readonly int VISIBLE = Interop.ActorProperty.VisibleGet(); + internal static readonly int COLOR = Interop.ActorProperty.ColorGet(); + internal static readonly int ColorRed = Interop.ActorProperty.ColorRedGet(); + internal static readonly int ColorGreen = Interop.ActorProperty.ColorGreenGet(); + internal static readonly int ColorBlue = Interop.ActorProperty.ColorBlueGet(); internal static readonly int WorldColor = Interop.ActorProperty.WorldColorGet(); internal static readonly int WorldMatrix = Interop.ActorProperty.WorldMatrixGet(); internal static readonly int NAME = Interop.ActorProperty.NameGet(); diff --git a/test/Tizen.NUI.Devel.Tests.Ubuntu/Tizen.NUI.Devel.Tests/testcase/public/TSView.cs b/test/Tizen.NUI.Devel.Tests.Ubuntu/Tizen.NUI.Devel.Tests/testcase/public/TSView.cs index 6624350..b350ca8 100644 --- a/test/Tizen.NUI.Devel.Tests.Ubuntu/Tizen.NUI.Devel.Tests/testcase/public/TSView.cs +++ b/test/Tizen.NUI.Devel.Tests.Ubuntu/Tizen.NUI.Devel.Tests/testcase/public/TSView.cs @@ -124,5 +124,88 @@ namespace Tizen.NUI.Devel.Tests testView.Dispose(); } + + [Test] + [Category("P1")] + [Description("Get value test for View.ColorRed")] + [Property("SPEC", "Tizen.NUI.BaseComponents.View.ColorRed")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "PRW")] + [Property("AUTHOR", "eunkiki.hong@samsung.com")] + public void ColorRed_GET_SET_VALUE() + { + /* TEST CODE */ + View testView = new View(); + + Assert.AreEqual(1.0f, testView.ColorRed, "Default red value is 1.0f"); + + testView.ColorRed = 0.5f; + + Assert.AreEqual(0.5f, testView.ColorRed, "ColorRed set"); + Assert.AreEqual(new Color(0.5f, 1.0f, 1.0f, 1.0f), testView.Color, "ColorRed should change View.Color"); + + testView.Color = new Color(0.0f, 0.0f, 0.0f, 0.5f); + + Assert.AreEqual(new Color(0.0f, 0.0f, 0.0f, 0.5f), testView.Color, "Color set"); + Assert.AreEqual(0.0f, testView.ColorRed, "Color should change View.ColorRed"); + + testView.Dispose(); + } + + + [Test] + [Category("P1")] + [Description("Get value test for View.ColorGreen")] + [Property("SPEC", "Tizen.NUI.BaseComponents.View.ColorGreen")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "PRW")] + [Property("AUTHOR", "eunkiki.hong@samsung.com")] + public void ColorGreen_GET_SET_VALUE() + { + /* TEST CODE */ + View testView = new View(); + + Assert.AreEqual(1.0f, testView.ColorGreen, "Default green value is 1.0f"); + + testView.ColorGreen = 0.5f; + + Assert.AreEqual(0.5f, testView.ColorGreen, "ColorGreen set"); + Assert.AreEqual(new Color(1.0f, 0.5f, 1.0f, 1.0f), testView.Color, "ColorGreen should change View.Color"); + + testView.Color = new Color(0.0f, 0.0f, 0.0f, 0.5f); + + Assert.AreEqual(new Color(0.0f, 0.0f, 0.0f, 0.5f), testView.Color, "Color set"); + Assert.AreEqual(0.0f, testView.ColorGreen, "Color should change View.ColorGreen"); + + testView.Dispose(); + } + + + [Test] + [Category("P1")] + [Description("Get value test for View.ColorBlue")] + [Property("SPEC", "Tizen.NUI.BaseComponents.View.ColorBlue")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "PRW")] + [Property("AUTHOR", "eunkiki.hong@samsung.com")] + public void ColorBlue_GET_SET_VALUE() + { + /* TEST CODE */ + View testView = new View(); + + Assert.AreEqual(1.0f, testView.ColorBlue, "Default blue value is 1.0f"); + + testView.ColorBlue = 0.5f; + + Assert.AreEqual(0.5f, testView.ColorBlue, "ColorBlue set"); + Assert.AreEqual(new Color(1.0f, 1.0f, 0.5f, 1.0f), testView.Color, "ColorBlue should change View.Color"); + + testView.Color = new Color(0.0f, 0.0f, 0.0f, 0.5f); + + Assert.AreEqual(new Color(0.0f, 0.0f, 0.0f, 0.5f), testView.Color, "Color set"); + Assert.AreEqual(0.0f, testView.ColorBlue, "Color should change View.ColorBlue"); + + testView.Dispose(); + } } } -- 2.7.4