Fixed memory leak + added visibility UI node C# endpoints + size
This commit is contained in:
@@ -84,6 +84,60 @@ Coral::ManagedObject GetNativeInstanceNodeICall(const Coral::String& canvasUUID,
|
||||
return Coral::ManagedObject();
|
||||
}
|
||||
|
||||
Coral::Bool32 GetVisibilityICall(const Coral::String& canvasUUID, const Coral::String& nodeUUID)
|
||||
{
|
||||
if (!ResourceManager::IsResourceLoaded(UUIDFromString(canvasUUID)))
|
||||
{
|
||||
Logger::Log("Error getting native instance of UI node, canvas is not loaded.", ".net/ui", CRITICAL);
|
||||
}
|
||||
|
||||
Ref<UIResource> uiResource = ResourceManager::GetResource<UIResource>(UUIDFromString(canvasUUID));
|
||||
Ref<Canvas> canvas = uiResource->GetCanvas();
|
||||
Ref<Node> node = std::static_pointer_cast<NuakeUI::Node>(canvas->GetNodeByUUID(UUIDFromString(nodeUUID)));
|
||||
return node->ComputedStyle.Visibility == VisibilityType::Show;
|
||||
}
|
||||
|
||||
void SetWidthPercentageICall(const Coral::String& canvasUUID, const Coral::String& nodeUUID, float percentage)
|
||||
{
|
||||
if (!ResourceManager::IsResourceLoaded(UUIDFromString(canvasUUID)))
|
||||
{
|
||||
Logger::Log("Error getting native instance of UI node, canvas is not loaded.", ".net/ui", CRITICAL);
|
||||
}
|
||||
|
||||
Ref<UIResource> uiResource = ResourceManager::GetResource<UIResource>(UUIDFromString(canvasUUID));
|
||||
Ref<Canvas> canvas = uiResource->GetCanvas();
|
||||
Ref<Node> node = std::static_pointer_cast<NuakeUI::Node>(canvas->GetNodeByUUID(UUIDFromString(nodeUUID)));
|
||||
node->ComputedStyle.Width.type = LengthType::Percentage;
|
||||
node->ComputedStyle.Width.value = percentage;
|
||||
}
|
||||
|
||||
void SetHeightPercentageICall(const Coral::String& canvasUUID, const Coral::String& nodeUUID, float percentage)
|
||||
{
|
||||
if (!ResourceManager::IsResourceLoaded(UUIDFromString(canvasUUID)))
|
||||
{
|
||||
Logger::Log("Error getting native instance of UI node, canvas is not loaded.", ".net/ui", CRITICAL);
|
||||
}
|
||||
|
||||
Ref<UIResource> uiResource = ResourceManager::GetResource<UIResource>(UUIDFromString(canvasUUID));
|
||||
Ref<Canvas> canvas = uiResource->GetCanvas();
|
||||
Ref<Node> node = std::static_pointer_cast<NuakeUI::Node>(canvas->GetNodeByUUID(UUIDFromString(nodeUUID)));
|
||||
node->ComputedStyle.Height.type = LengthType::Percentage;
|
||||
node->ComputedStyle.Height.value = percentage;
|
||||
}
|
||||
|
||||
void SetVisibilityICall(const Coral::String& canvasUUID, const Coral::String& nodeUUID, Coral::Bool32 visible)
|
||||
{
|
||||
if (!ResourceManager::IsResourceLoaded(UUIDFromString(canvasUUID)))
|
||||
{
|
||||
Logger::Log("Error getting native instance of UI node, canvas is not loaded.", ".net/ui", CRITICAL);
|
||||
}
|
||||
|
||||
Ref<UIResource> uiResource = ResourceManager::GetResource<UIResource>(UUIDFromString(canvasUUID));
|
||||
Ref<Canvas> canvas = uiResource->GetCanvas();
|
||||
Ref<Node> node = std::static_pointer_cast<NuakeUI::Node>(canvas->GetNodeByUUID(UUIDFromString(nodeUUID)));
|
||||
node->ComputedStyle.Visibility = visible ? VisibilityType::Show : VisibilityType::Hidden;
|
||||
}
|
||||
|
||||
Coral::String GetTextNodeTextICall(const Coral::String& canvasUUID, const Coral::String& nodeUUID)
|
||||
{
|
||||
if(!ResourceManager::IsResourceLoaded(UUIDFromString(canvasUUID)))
|
||||
@@ -118,6 +172,15 @@ void UINetAPI::RegisterMethods()
|
||||
RegisterMethod("Node.HasNativeInstanceICall", &HasNativeInstanceICall);
|
||||
RegisterMethod("Node.GetNativeInstanceNodeICall", &GetNativeInstanceNodeICall);
|
||||
|
||||
// Styling
|
||||
RegisterMethod("Node.GetVisibilityICall", &GetVisibilityICall);
|
||||
RegisterMethod("Node.SetVisibilityICall", &SetVisibilityICall);
|
||||
|
||||
//RegisterMethod("Node.GetWidthPercentageICall", &GetWidthPercentageICall);
|
||||
RegisterMethod("Node.SetWidthPercentageICall", &SetWidthPercentageICall);
|
||||
// RegisterMethod("Node.GetHeightPercentageICall", &GetHeightPercentageICall);
|
||||
RegisterMethod("Node.SetHeightPercentageICall", &SetHeightPercentageICall);
|
||||
|
||||
RegisterMethod("TextNode.GetTextNodeTextICall", &GetTextNodeTextICall);
|
||||
RegisterMethod("TextNode.SetTextNodeTextICall", &SetTextNodeTextICall);
|
||||
}
|
||||
@@ -92,7 +92,7 @@ namespace NuakeUI
|
||||
{
|
||||
std::vector<StyleRule> relationStyles;
|
||||
|
||||
auto allRules = mStyleSheet->Rules;
|
||||
auto& allRules = mStyleSheet->Rules;
|
||||
for (auto& i : inheritedRules)
|
||||
{
|
||||
allRules.push_back(i);
|
||||
|
||||
@@ -305,7 +305,7 @@ Ref<Scene> Window::GetScene()
|
||||
|
||||
bool Window::SetScene(Ref<Scene> newScene)
|
||||
{
|
||||
windowSetSceneDelegate.Broadcast(scene, newScene);
|
||||
//windowSetSceneDelegate.Broadcast(scene, newScene);
|
||||
|
||||
scene = newScene;
|
||||
|
||||
|
||||
@@ -69,11 +69,25 @@ namespace Nuake.Net
|
||||
}
|
||||
}
|
||||
|
||||
public enum Visibility
|
||||
{
|
||||
Hidden,
|
||||
Visible,
|
||||
}
|
||||
|
||||
|
||||
public class Node
|
||||
{
|
||||
internal static unsafe delegate*<NativeString, NativeString, NativeString, NativeString> FindChildByIDICall;
|
||||
internal static unsafe delegate*<NativeString, NativeString, bool> HasNativeInstanceICall;
|
||||
internal static unsafe delegate*<NativeString, NativeString, NativeInstance<Node>> GetNativeInstanceNodeICall;
|
||||
internal static unsafe delegate*<NativeString, NativeString, Bool32, void> SetVisibilityICall;
|
||||
internal static unsafe delegate*<NativeString, NativeString, Bool32> GetVisibilityICall;
|
||||
|
||||
internal static unsafe delegate*<NativeString, NativeString, float> GetHeightPercentageICall;
|
||||
internal static unsafe delegate*<NativeString, NativeString, float, void> SetHeightPercentageICall;
|
||||
internal static unsafe delegate*<NativeString, NativeString, float> GetWidthPercentageICall;
|
||||
internal static unsafe delegate*<NativeString, NativeString, float, void> SetWidthPercentageICall;
|
||||
|
||||
public string UUID;
|
||||
public string CanvasUUID;
|
||||
@@ -88,6 +102,66 @@ namespace Nuake.Net
|
||||
public string ID { get; set; } = "";
|
||||
public List<string> Classes { get; set; } = new();
|
||||
|
||||
public float GetWidthPercentage()
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
return GetHeightPercentageICall(CanvasUUID, UUID);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetWidthPercentage(float percentage)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
if (percentage < 0.0f)
|
||||
{
|
||||
throw new ArgumentException("Percentage has to be greater than 0.");
|
||||
}
|
||||
|
||||
SetWidthPercentageICall(CanvasUUID, UUID, percentage);
|
||||
}
|
||||
}
|
||||
|
||||
public float GetHeightPercentage()
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
return GetHeightPercentageICall(CanvasUUID, UUID);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetHeightPercentage(float percentage)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
if(percentage < 0.0f)
|
||||
{
|
||||
throw new ArgumentException("Percentage has to be greater than 0.");
|
||||
}
|
||||
|
||||
SetHeightPercentageICall(CanvasUUID, UUID, percentage);
|
||||
}
|
||||
}
|
||||
|
||||
public Visibility Visibility
|
||||
{
|
||||
get
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
return GetVisibilityICall(CanvasUUID, UUID) ? Visibility.Visible : Visibility.Hidden;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
SetVisibilityICall(CanvasUUID, UUID, value == Visibility.Visible);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Traverse the DOM starting from this node to find a child from a unique ID
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user