Skip to content

Commit

Permalink
[NUI] Implement VisualObject feature for View using Visual feature
Browse files Browse the repository at this point in the history
It was hard to use Visual feature for `BaseComponents.View`

We only allow to use `VisualBase` only for `VisualView`, with name.
But there was some user side hardness when they want to use it

1. Subclass of View cannot use Visual feature
2. Some ImageVisual feature doesn't allow to used another visuals.

To resolve this issue,
let we make new class, named `Visuals.VisualBase` and let View use it.

TODO : Describe some class definition

Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
  • Loading branch information
Eunki, Hong committed May 14, 2024
1 parent d64306b commit 0cb1ba0
Show file tree
Hide file tree
Showing 13 changed files with 2,253 additions and 0 deletions.
135 changes: 135 additions & 0 deletions src/Tizen.NUI/src/internal/Common/VisualObjectsContainer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
// Copyright (c) 2019 Samsung Electronics Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

using System;
using System.Text;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Linq;
using System.ComponentModel;

namespace Tizen.NUI.Visuals
{
/// <summary>
/// TODO : Summary description for VisualObjectsContainer.
/// </summary>
internal class VisualObjectsContainer : BaseHandle
{
/// <summary>
/// Creates an empty visual object handle.
/// </summary>
public VisualObjectsContainer() : this(Interop.VisualObjectsContainer.NewVisualObjectsContainer(), true, false)
{
NDalicPINVOKE.ThrowExceptionIfExists();
}

/// <summary>
/// Creates an visual object with VisualObjectsContainer.
/// </summary>
public VisualObjectsContainer(Tizen.NUI.BaseComponents.View view) : this(Interop.VisualObjectsContainer.VisualObjectsContainerNew(Tizen.NUI.BaseComponents.View.getCPtr(view)), true)
{
NDalicPINVOKE.ThrowExceptionIfExists();
}

internal VisualObjectsContainer(global::System.IntPtr cPtr, bool cMemoryOwn) : this(cPtr, cMemoryOwn, cMemoryOwn)
{
}

internal VisualObjectsContainer(global::System.IntPtr cPtr, bool cMemoryOwn, bool cRegister) : base(cPtr, cMemoryOwn, cRegister)
{
}

public Tizen.NUI.BaseComponents.View GetView()
{
global::System.IntPtr cPtr = Interop.VisualObjectsContainer.GetOwner(SwigCPtr);
Tizen.NUI.BaseComponents.View ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Tizen.NUI.BaseComponents.View;
if (ret != null)
{
Interop.BaseHandle.DeleteBaseHandle(new global::System.Runtime.InteropServices.HandleRef(this, cPtr));
}
else
{
ret = new Tizen.NUI.BaseComponents.View(cPtr, true);
}
NDalicPINVOKE.ThrowExceptionIfExists();
return ret;
}

public Tizen.NUI.Visuals.VisualBase this[uint index]
{
get
{
return GetVisualObjectAt(index);
}
}

public uint GetVisualObjectsCount()
{
uint ret = Interop.VisualObjectsContainer.GetVisualObjectsCount(SwigCPtr);
NDalicPINVOKE.ThrowExceptionIfExists();
return ret;
}

public bool AddVisualObject(Tizen.NUI.Visuals.VisualBase visualObject)
{
bool ret = Interop.VisualObjectsContainer.AddVisualObject(SwigCPtr, Tizen.NUI.Visuals.VisualBase.getCPtr(visualObject));
NDalicPINVOKE.ThrowExceptionIfExists();
return ret;
}

public void RemoveVisualObject(Tizen.NUI.Visuals.VisualBase visualObject)
{
Interop.VisualObjectsContainer.RemoveVisualObject(SwigCPtr, Tizen.NUI.Visuals.VisualBase.getCPtr(visualObject));
NDalicPINVOKE.ThrowExceptionIfExists();
}

private Tizen.NUI.Visuals.VisualBase GetVisualObjectAt(uint index)
{
global::System.IntPtr cPtr = Interop.VisualObjectsContainer.GetVisualObjectAt(SwigCPtr, index);
Visuals.VisualBase ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Visuals.VisualBase;
if (ret != null)
{
Interop.BaseHandle.DeleteBaseHandle(new global::System.Runtime.InteropServices.HandleRef(this, cPtr));
}
else
{
ret = new Visuals.VisualBase(cPtr, true);
}
NDalicPINVOKE.ThrowExceptionIfExists();
return ret;
}

/// <summary>
/// Dispose for VisualObjectsContainer
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
protected override void Dispose(DisposeTypes type)
{
if (disposed)
{
return;
}

if (type == DisposeTypes.Explicit)
{
//Called by User
//Release your own managed resources here.
//You should release all of your own disposable objects here.
}

base.Dispose(type);
}
}
}
66 changes: 66 additions & 0 deletions src/Tizen.NUI/src/internal/Interop/Interop.VisualObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright(c) 2021 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

namespace Tizen.NUI
{
internal static partial class Interop
{
internal static partial class VisualObject
{
[global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_VisualObject_New")]
public static extern global::System.IntPtr VisualObjectNew();

[global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_VisualObject_GetContainer")]
public static extern global::System.IntPtr GetContainer(global::System.Runtime.InteropServices.HandleRef visualObject);

[global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_VisualObject_CreateVisual")]
public static extern void CreateVisual(global::System.Runtime.InteropServices.HandleRef visualObject, global::System.Runtime.InteropServices.HandleRef propertyMap);

[global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_VisualObject_RetrieveVisualProperty")]
public static extern void RetrieveVisualProperty(global::System.Runtime.InteropServices.HandleRef visualObject, global::System.Runtime.InteropServices.HandleRef propertyMap);


[global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_VisualObject_SetSiblingOrder")]
public static extern void SetSiblingOrder(global::System.Runtime.InteropServices.HandleRef visualObject, uint siblingOrder);

[global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_VisualObject_GetSiblingOrder")]
public static extern uint GetSiblingOrder(global::System.Runtime.InteropServices.HandleRef visualObject);


[global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_VisualObject_DetachFromContainer")]
public static extern void Detach(global::System.Runtime.InteropServices.HandleRef visualObject);

[global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_VisualObject_Raise")]
public static extern uint Raise(global::System.Runtime.InteropServices.HandleRef visualObject);

[global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_VisualObject_Lower")]
public static extern uint Lower(global::System.Runtime.InteropServices.HandleRef visualObject);

[global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_VisualObject_RaiseToTop")]
public static extern uint RaiseToTop(global::System.Runtime.InteropServices.HandleRef visualObject);

[global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_VisualObject_LowerToBottom")]
public static extern uint LowerToBottom(global::System.Runtime.InteropServices.HandleRef visualObject);

[global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_VisualObject_RaiseAbove")]
public static extern uint RaiseAbove(global::System.Runtime.InteropServices.HandleRef visualObject, global::System.Runtime.InteropServices.HandleRef target);

[global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_VisualObject_LowerBelow")]
public static extern uint LowerBelow(global::System.Runtime.InteropServices.HandleRef visualObject, global::System.Runtime.InteropServices.HandleRef target);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright(c) 2021 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

namespace Tizen.NUI
{
internal static partial class Interop
{
internal static partial class VisualObjectsContainer
{
[global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_new_VisualObjectsContainer__SWIG_0")]
public static extern global::System.IntPtr NewVisualObjectsContainer();

[global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_delete_VisualObjectsContainer")]
public static extern void DeleteVisualObjectsContainer(global::System.Runtime.InteropServices.HandleRef container);

[global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_VisualObjectsContainer_New")]
public static extern global::System.IntPtr VisualObjectsContainerNew(global::System.Runtime.InteropServices.HandleRef view);


[global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_VisualObjectsContainer_GetOwner")]
public static extern global::System.IntPtr GetOwner(global::System.Runtime.InteropServices.HandleRef container);

[global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_VisualObjectsContainer_GetVisualObjectsCount")]
public static extern uint GetVisualObjectsCount(global::System.Runtime.InteropServices.HandleRef container);

[global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_VisualObjectsContainer_GetVisualObjectAt")]
public static extern global::System.IntPtr GetVisualObjectAt(global::System.Runtime.InteropServices.HandleRef container, uint index);

[global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_VisualObjectsContainer_AddVisualObject")]
[return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.U1)]
public static extern bool AddVisualObject(global::System.Runtime.InteropServices.HandleRef container, global::System.Runtime.InteropServices.HandleRef viewObject);

[global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_VisualObjectsContainer_RemoveVisualObject")]
public static extern void RemoveVisualObject(global::System.Runtime.InteropServices.HandleRef container, global::System.Runtime.InteropServices.HandleRef viewObject);
}
}
}
3 changes: 3 additions & 0 deletions src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,9 @@ protected override void Dispose(DisposeTypes type)
internalCurrentScreenPosition?.Dispose();
internalCurrentScreenPosition = null;

visualContainer?.Dispose();
visualContainer = null;

if (type == DisposeTypes.Explicit)
{
//Called by User
Expand Down
72 changes: 72 additions & 0 deletions src/Tizen.NUI/src/public/BaseComponents/ViewVisual.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright(c) 2022 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.InteropServices;
using Tizen.NUI.Binding;

namespace Tizen.NUI.BaseComponents
{
/// <summary>
/// View is the base class for all views.
/// </summary>
/// <since_tizen> 3 </since_tizen>
public partial class View
{
private Tizen.NUI.Visuals.VisualObjectsContainer visualContainer = null;

/// <summary>
/// Add a visual object to the view.
/// </summary>
/// <remarks>
/// The visual is added to the top of the visuals.
/// If the container cannot add more than maxium count of objects
/// or the visual object is already added, It will be ignored.
/// </remarks>
/// <param name="visualObject">The visual object to add.</param>
/// <returns>True if the visual was added successfully, false otherwise.</returns>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool AddVisualObject(Tizen.NUI.Visuals.VisualBase visualObject)
{
EnsureVisualContainer();
return visualContainer.AddVisualObject(visualObject);
}

/// <summary>
/// Remove a visual object from the view.
/// </summary>
/// <remarks>
/// The all other VisualObject's SiblingOrder value will be changed automatically.
/// </remarks>
/// <param name="visualObject">The visual object to remove.</param>
[EditorBrowsable(EditorBrowsableState.Never)]
public void RemoveVisualObject(Tizen.NUI.Visuals.VisualBase visualObject)
{
EnsureVisualContainer();
visualContainer.AddVisualObject(visualObject);
}

private void EnsureVisualContainer()
{
if (visualContainer == null)
{
visualContainer = new Visuals.VisualObjectsContainer(this);
}
}
}
}
11 changes: 11 additions & 0 deletions src/Tizen.NUI/src/public/Common/PropertyMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,17 @@ public bool Remove(PropertyKey key)
return isRemoved;
}

/// <summary>
/// Removes the element by the specified integer key.
/// </summary>
/// <param name="key">The index key to find.</param>
/// <returns>True if the element is removed, false otherwise.</returns>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool Remove(int key)
{
return Interop.PropertyMap.Remove(SwigCPtr, key);
}

/// <summary>
/// Determines whether the PropertyMap contains the specified key.
/// </summary>
Expand Down
Loading

0 comments on commit 0cb1ba0

Please sign in to comment.