Skip to content

Commit

Permalink
[NUI] Apply comments at VisualBase (phase 1)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Eunki, Hong authored and hinohie committed Aug 12, 2024
1 parent 5845c2d commit a5fc1d8
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 21 deletions.
4 changes: 0 additions & 4 deletions src/Tizen.NUI/src/internal/Common/VisualObjectsContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,6 @@ private Tizen.NUI.Visuals.VisualBase GetVisualObjectAt(uint index)
{
Interop.BaseHandle.DeleteBaseHandle(new global::System.Runtime.InteropServices.HandleRef(this, cPtr));
}
else
{
ret = new Visuals.VisualBase(cPtr, true);
}
NDalicPINVOKE.ThrowExceptionIfExists();
return ret;
}
Expand Down
79 changes: 62 additions & 17 deletions src/Tizen.NUI/src/public/Visuals/VisualObject/VisualBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -186,15 +186,6 @@ internal void ConvertFromPropertyMap(PropertyMap inputMap)
#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)
{
}
Expand Down Expand Up @@ -237,7 +228,7 @@ public enum PropertyUpdateModeType
/// 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
Expand Down Expand Up @@ -337,7 +328,15 @@ public float Opacity
{
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
{
Expand All @@ -358,20 +357,32 @@ public float Opacity
/// 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
{
Expand Down Expand Up @@ -1017,7 +1028,17 @@ internal PropertyValue GetVisualProperty(int key)
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;
}
Expand Down Expand Up @@ -1070,6 +1091,30 @@ internal void ReqeustProcessorOnceEvent()
}
}

/// <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>
Expand Down

0 comments on commit a5fc1d8

Please sign in to comment.