Fixed memory leak + added visibility UI node C# endpoints + size

This commit is contained in:
antopilo
2024-10-19 23:23:26 -04:00
parent cbf11abcf5
commit f1be4f7cef
4 changed files with 139 additions and 2 deletions

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -305,7 +305,7 @@ Ref<Scene> Window::GetScene()
bool Window::SetScene(Ref<Scene> newScene)
{
windowSetSceneDelegate.Broadcast(scene, newScene);
//windowSetSceneDelegate.Broadcast(scene, newScene);
scene = newScene;