[NUI] Add IsEnabled Property in View class for controling user interactions.
authorEverLEEst(SangHyeon Lee) <sh10233.lee@samsung.com>
Thu, 17 Feb 2022 07:50:00 +0000 (23:50 -0800)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Tue, 22 Mar 2022 08:34:14 +0000 (17:34 +0900)
src/Tizen.NUI.Components/Controls/Button.cs
src/Tizen.NUI/src/internal/Interop/Interop.ActorInternal.cs
src/Tizen.NUI/src/internal/Interop/Interop.ActorProperty.cs
src/Tizen.NUI/src/public/BaseComponents/View.cs
src/Tizen.NUI/src/public/BaseComponents/ViewBindableProperty.cs
src/Tizen.NUI/src/public/BaseComponents/ViewEnum.cs
src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs
test/Tizen.NUI.Devel.Tests.Ubuntu/Tizen.NUI.Devel.Tests/testcase/public/TSView.cs [new file with mode: 0644]
test/Tizen.NUI.StyleGuide/Examples/ButtonExample.cs

index 752b52b..ed9a3e6 100755 (executable)
@@ -75,7 +75,9 @@ namespace Tizen.NUI.Components
                 if (instance.isEnabled != newEnabled)
                 {
                     instance.isEnabled = newEnabled;
+                    // FIXME : InsEnabled Property should not change other property value.
                     instance.Sensitive = newEnabled;
+                    ((Control)instance).IsEnabled = newEnabled;
                     instance.UpdateState();
                 }
             }
index fed28c7..fb7ede3 100755 (executable)
@@ -218,6 +218,13 @@ namespace Tizen.NUI
             [return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.U1)]
             public static extern bool IsFocusableInTouch(global::System.Runtime.InteropServices.HandleRef jarg1);
 
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Actor_SetEnabled")]
+            public static extern void SetEanbled(global::System.Runtime.InteropServices.HandleRef jarg1, bool jarg2);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Actor_IsEnabled")]
+            [return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.U1)]
+            public static extern bool IsEnabled(global::System.Runtime.InteropServices.HandleRef jarg1);
+
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Actor_SetSizeScalePolicy")]
             public static extern void SetSizeScalePolicy(global::System.Runtime.InteropServices.HandleRef jarg1, int jarg2);
 
index a85431d..9d0c655 100755 (executable)
@@ -150,6 +150,9 @@ namespace Tizen.NUI
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Actor_Property_SENSITIVE_get")]
             public static extern int SensitiveGet();
 
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Actor_Property_ENABLED_get")]
+            public static extern int EnabledGet();
+
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Actor_Property_LEAVE_REQUIRED_get")]
             public static extern int LeaveRequiredGet();
 
index 7061abd..18ceac8 100755 (executable)
@@ -1815,6 +1815,25 @@ namespace Tizen.NUI.BaseComponents
         }
 
         /// <summary>
+        /// Gets or sets the status of whether the view should be enabled user interactions.
+        /// If a View is made disabled, then user interactions including touch, focus, and actiavation is disabled.
+        /// </summary>
+        /// <since_tizen> tizen_next </since_tizen>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public bool IsEnabled
+        {
+            get
+            {
+                return (bool)GetValue(IsEnabledProperty);
+            }
+            set
+            {
+                SetValue(IsEnabledProperty, value);
+                NotifyPropertyChanged();
+            }
+        }
+
+        /// <summary>
         /// Gets or sets the status of whether the view should receive a notification when touch or hover motion events leave the boundary of the view.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
index 3cfc50c..ca72073 100755 (executable)
@@ -1166,6 +1166,27 @@ namespace Tizen.NUI.BaseComponents
         }));
 
         /// <summary>
+        /// IsEnabledProperty
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static readonly BindableProperty IsEnabledProperty = BindableProperty.Create(nameof(Sensitive), typeof(bool), typeof(View), false, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) =>
+        {
+            var view = (View)bindable;
+            if (newValue != null)
+            {
+                newValue = view.OnEnabled((bool)newValue);
+                Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)view.SwigCPtr, View.Property.Enabled, new Tizen.NUI.PropertyValue((bool)newValue));
+            }
+        }),
+        defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
+        {
+            var view = (View)bindable;
+            bool temp = true;
+            Tizen.NUI.Object.GetProperty((System.Runtime.InteropServices.HandleRef)view.SwigCPtr, View.Property.Enabled).Get(out temp);
+            return temp;
+        }));
+
+        /// <summary>
         /// DispatchKeyEventsProperty
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
index 4f76b7d..d532c57 100755 (executable)
@@ -216,6 +216,7 @@ namespace Tizen.NUI.BaseComponents
             internal static readonly int WorldMatrix = Interop.ActorProperty.WorldMatrixGet();
             internal static readonly int NAME = Interop.ActorProperty.NameGet();
             internal static readonly int SENSITIVE = Interop.ActorProperty.SensitiveGet();
+            internal static readonly int Enabled = Interop.ActorProperty.EnabledGet();
             internal static readonly int LeaveRequired = Interop.ActorProperty.LeaveRequiredGet();
             internal static readonly int InheritOrientation = Interop.ActorProperty.InheritOrientationGet();
             internal static readonly int InheritScale = Interop.ActorProperty.InheritScaleGet();
index db7ef06..9c870c0 100755 (executable)
@@ -1270,6 +1270,29 @@ namespace Tizen.NUI.BaseComponents
             return false;
         }
 
+        /// <summary>
+        /// Internal callback of enabled property changes.
+        /// Inherited view can override this method to implements enabled property changes.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected virtual bool OnEnabled(bool enabled)
+        {
+            if (enableControlState)
+            {
+                if (enabled)
+                {
+                    ControlState -= ControlState.Disabled;
+                }
+                else
+                {
+                    ControlState += ControlState.Disabled;
+                }
+            }
+            return enabled;
+        }
+
+
+        
         private void DisConnectFromSignals()
         {
             if (HasBody() == false)
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
new file mode 100644 (file)
index 0000000..2060ed0
--- /dev/null
@@ -0,0 +1,72 @@
+using global::System;
+using NUnit.Framework;
+using NUnit.Framework.TUnit;
+using Tizen.NUI.Components;
+using Tizen.NUI.BaseComponents;
+
+namespace Tizen.NUI.Devel.Tests
+{
+    using tlog = Tizen.Log;
+
+    [TestFixture]
+    [Description("public/BaseComponents/View")]
+    public class ViewTest
+    {
+        private const string tag = "NUITEST";
+        private const int testSize = 100;
+        private const int testPosition = 100;
+
+        [SetUp]
+        public void Init()
+        {
+            tlog.Info(tag, "Init() is called!");
+        }
+
+        [TearDown]
+        public void Destroy()
+        {
+            tlog.Info(tag, "Destroy() is called!");
+        }
+
+        [Test]
+        [Category("P1")]
+        [Description("Get default value test for View.IsEnabled")]
+        [Property("SPEC", "Tizen.NUI.BaseComponents.View.IsEnabled")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "PRO")]
+        [Property("AUTHOR", "sh10233.lee@samsung.com")]
+        public void IsEnabled_CHECK_DEFAULT_VALUE()
+        {
+            /* TEST CODE */
+            View testView = new View();
+            var isEnabled = testView.IsEnabled;
+
+            Assert.AreEqual(true, isEnabled, "View IsEnabled should be true by default");
+
+            testView.Dispose();
+        }
+
+        [Test]
+        [Category("P1")]
+        [Description("Set value test for View.IsEnabled")]
+        [Property("SPEC", "Tizen.NUI.BaseComponents.View.IsEnabled")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "PRW")]
+        [Property("AUTHOR", "sh10233.lee@samsung.com")]
+        public void IsEnabled_SET_VALUE()
+        {
+            /* TEST CODE */
+            View testView = new View();
+            var isEnabled = testView.IsEnabled;
+
+            Assert.AreEqual(true, isEnabled, "View IsEnabled should be true by default");
+
+            testView.IsEnabled = false;
+
+            Assert.AreEqual(false, isEnabled, "View IsEnabled should be changed by set value");
+
+            testView.Dispose();
+        }
+
+    }
+}
index 65dd022..709541f 100644 (file)
@@ -80,6 +80,7 @@ namespace Tizen.NUI.StyleGuide
                 Text = "Disabled",
                 IsEnabled = false,
             };
+            disabledButton.EnableFocus();
             disabledButton.Clicked += (object obj, ClickedEventArgs ev) =>
             {
                 // This event should not be recieved. button is disabled.
@@ -98,6 +99,7 @@ namespace Tizen.NUI.StyleGuide
                 Log.Info(this.GetType().Name, "Selected Button Clicked\n");
                 if (obj is Button button)
                 {
+                   disabledButton.IsEnabled = button.IsSelected;
                    if (button.IsSelected)
                     {
                         button.Text = "Selected";