[NUI] Apply comments at VisualBase (phase 1)
authorEunki, Hong <eunkiki.hong@samsung.com>
Mon, 5 Aug 2024 03:56:51 +0000 (12:56 +0900)
committerSeoyeon2Kim <34738918+Seoyeon2Kim@users.noreply.github.com>
Tue, 13 Aug 2024 06:45:22 +0000 (15:45 +0900)
Apply some comments that report at PR #6079

- `Color.A` getter apply `Opacity` changeness
- Make `VisualFittingMode` have no effect for `ColorVisual` and `BorderVisual`
- `GetVisualProperty` return valid value after call `GetCurrentVisualProperty`
- Make `VisualBase` class as abstract. Let we don't allow to call this class constructor.

Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
src/Tizen.NUI/src/internal/Common/VisualObjectsContainer.cs
src/Tizen.NUI/src/public/Visuals/VisualObject/VisualBase.cs

index 767b2eb882b6da3a6c42e0b11fc29f3a4faffe8b..2d1a31eeb7984ce1b9015e4f5955297b5bbd0dd6 100644 (file)
@@ -159,10 +159,6 @@ namespace Tizen.NUI.Visuals
             {
                 Interop.BaseHandle.DeleteBaseHandle(new global::System.Runtime.InteropServices.HandleRef(this, cPtr));
             }
-            else
-            {
-                ret = new Visuals.VisualBase(cPtr, true);
-            }
             NDalicPINVOKE.ThrowExceptionIfExists();
             return ret;
         }
index b82bcc0e2741ebbbbcdfa0f1c17768777671141a..fdb836ac80bf6e653ed176e6417e0ba810354e5d 100644 (file)
@@ -35,7 +35,7 @@ namespace Tizen.NUI.Visuals
     /// animation.AnimateTo(view, "BorderlineOffset", -1.0f);
     /// </code>
     [EditorBrowsable(EditorBrowsableState.Never)]
-    public class VisualBase : BaseHandle
+    public abstract class VisualBase : BaseHandle
     {
         #region Internal And Private
         internal PropertyMap cachedVisualPropertyMap = null;
@@ -186,15 +186,6 @@ namespace Tizen.NUI.Visuals
         #endregion
 
         #region Constructor
-        /// <summary>
-        /// Creates an visual object.
-        /// </summary>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public VisualBase() : this(Interop.VisualObject.VisualObjectNew(), true)
-        {
-            NDalicPINVOKE.ThrowExceptionIfExists();
-        }
-
         internal VisualBase(global::System.IntPtr cPtr, bool cMemoryOwn) : this(cPtr, cMemoryOwn, cMemoryOwn)
         {
         }
@@ -237,7 +228,7 @@ namespace Tizen.NUI.Visuals
         /// and the visuals with larger sibling order are drawn top.
         ///
         /// It will be changed automatically when the visuals are added to the view.
-        /// The default value is 0.
+        /// It is 0 before being added to the view.
         /// </remarks>
         [EditorBrowsable(EditorBrowsableState.Never)]
         public uint SiblingOrder
@@ -337,7 +328,15 @@ namespace Tizen.NUI.Visuals
         {
             set
             {
-                UpdateVisualProperty((int)Tizen.NUI.Visual.Property.Opacity, new PropertyValue(value), false);
+                using Tizen.NUI.Color currentVisualColor = Color;
+                if (currentVisualColor.A != value)
+                {
+                    using Tizen.NUI.Color visualColor = new Tizen.NUI.Color(currentVisualColor.R, currentVisualColor.G, currentVisualColor.B, value);
+                    UpdateVisualProperty((int)Tizen.NUI.Visual.Property.MixColor, new PropertyValue(visualColor), false);
+
+                    // warning : We should set cached Opacity after set MixColor.
+                    UpdateVisualProperty((int)Tizen.NUI.Visual.Property.Opacity, new PropertyValue(value), false);
+                }
             }
             get
             {
@@ -358,20 +357,32 @@ namespace Tizen.NUI.Visuals
         /// The default value is VisualFittingModeType.DontCare.
         /// If user set one of Transform property, it will be set as VisualFittingModeType.DontCare automatically.
         /// </remarks>
+        /// <remarks>
+        /// Fitting mode is only available when the visual has original size.
+        /// For example, ImageVisual and TextVisual support FittingMode, but ColorVisual and BorderVisual don't support.
+        /// If visual doesn't have original size, Property set will be ignored.
+        /// </remarks>
         [EditorBrowsable(EditorBrowsableState.Never)]
         public VisualFittingModeType FittingMode
         {
             set
             {
-                if (value != VisualFittingModeType.DontCare)
+                if (IsFittingModeAvailable())
                 {
-                    visualFittingModeApplied = true;
+                    if (value != VisualFittingModeType.DontCare)
+                    {
+                        visualFittingModeApplied = true;
+                    }
+                    else
+                    {
+                        visualFittingModeApplied = false;
+                    }
+                    UpdateVisualProperty((int)Tizen.NUI.Visual.Property.VisualFittingMode, new PropertyValue((int)value));
                 }
                 else
                 {
-                    visualFittingModeApplied = false;
+                    Tizen.Log.Error("NUI", $"Fitting mode is not supported by this visual type:{Type}. Set as DontCare\n");
                 }
-                UpdateVisualProperty((int)Tizen.NUI.Visual.Property.VisualFittingMode, new PropertyValue((int)value));
             }
             get
             {
@@ -1017,7 +1028,17 @@ namespace Tizen.NUI.Visuals
             if (ret == null)
             {
                 // If we cannot find result from cached map, Get value from native engine.
-                GetCurrentVisualProperty(key);
+                ret = GetCurrentVisualProperty(key);
+                
+                // Update cached value here
+                if (ret != null)
+                {
+                    if (cachedVisualPropertyMap == null)
+                    {
+                        cachedVisualPropertyMap = new PropertyMap();
+                    }
+                    cachedVisualPropertyMap[key] = ret;
+                }
             }
             return ret;
         }
@@ -1070,6 +1091,30 @@ namespace Tizen.NUI.Visuals
             }
         }
 
+        /// <summary>
+        /// Check whether given visual object is available to be use fitting mode or not.
+        /// </summary>
+        internal bool IsFittingModeAvailable()
+        {
+            switch (internalType)
+            {
+                case (int)Tizen.NUI.Visual.Type.Image:
+                case (int)Tizen.NUI.Visual.Type.NPatch:
+                case (int)Tizen.NUI.Visual.Type.AnimatedImage:
+                case (int)Tizen.NUI.Visual.Type.Text:
+                {
+                    return true;
+                }
+                case (int)Tizen.NUI.Visual.Type.Invalid:
+                case (int)Tizen.NUI.Visual.Type.Border:
+                case (int)Tizen.NUI.Visual.Type.Color:
+                {
+                    return false;
+                }
+            }
+            return false;
+        }
+
         /// <summary>
         /// Dispose for VisualObject
         /// </summary>