From a1558fd9a25b4eade3f871a9e5a09df3223ab75d Mon Sep 17 00:00:00 2001 From: scawful Date: Fri, 19 Apr 2024 17:54:14 -0400 Subject: [PATCH] replace flags void* with std::shared_ptr --- src/app/gui/zeml.cc | 16 ++++++++-------- src/app/gui/zeml.h | 24 +++++++++++++----------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/app/gui/zeml.cc b/src/app/gui/zeml.cc index 82d73960..b428f697 100644 --- a/src/app/gui/zeml.cc +++ b/src/app/gui/zeml.cc @@ -190,7 +190,7 @@ void ParseFlags(const WidgetType& type, const std::string& flags, windowFlags |= flagMap[flag]; } } - attributes.flags = new ImGuiWindowFlags(windowFlags); + attributes.flags = std::make_unique(windowFlags); break; } case WidgetType::CollapsingHeader: { @@ -216,7 +216,7 @@ void ParseFlags(const WidgetType& type, const std::string& flags, treeFlags |= flagMap[flag]; } } - attributes.flags = new ImGuiTreeNodeFlags(treeFlags); + attributes.flags = std::make_unique(treeFlags); break; } case WidgetType::Table: { @@ -263,7 +263,7 @@ void ParseFlags(const WidgetType& type, const std::string& flags, } } // Reserve data to the void* pointer and assign flags - attributes.flags = new ImGuiTableFlags(tableFlags); + attributes.flags = std::make_unique(tableFlags); } break; case WidgetType::TableSetupColumn: { static std::map flagMap = { @@ -295,7 +295,7 @@ void ParseFlags(const WidgetType& type, const std::string& flags, } } // Reserve data to the void* pointer and assign flags - attributes.flags = new ImGuiTableColumnFlags(columnFlags); + attributes.flags = std::make_unique(columnFlags); } default: break; @@ -379,7 +379,7 @@ void Render(Node& node) { case WidgetType::Window: { ImGuiWindowFlags flags = ImGuiWindowFlags_None; if (node.attributes.flags) { - flags = *(ImGuiWindowFlags*)node.attributes.flags; + flags = *(ImGuiWindowFlags*)node.attributes.flags.get(); } if (ImGui::Begin(node.attributes.title.c_str(), nullptr, flags)) { for (auto& child : node.children) { @@ -406,7 +406,7 @@ void Render(Node& node) { case WidgetType::CollapsingHeader: { ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_None; if (node.attributes.flags) { - flags = *(ImGuiTreeNodeFlags*)node.attributes.flags; + flags = *(ImGuiTreeNodeFlags*)node.attributes.flags.get(); } if (ImGui::CollapsingHeader(node.attributes.title.c_str(), flags)) { for (auto& child : node.children) { @@ -433,7 +433,7 @@ void Render(Node& node) { case WidgetType::Table: { ImGuiTableFlags flags = ImGuiTableFlags_None; if (node.attributes.flags) { - flags = *(ImGuiTableFlags*)node.attributes.flags; + flags = *(ImGuiTableFlags*)node.attributes.flags.get(); } if (ImGui::BeginTable(node.attributes.id.c_str(), node.attributes.count, flags)) { @@ -446,7 +446,7 @@ void Render(Node& node) { case WidgetType::TableSetupColumn: { ImGuiTableColumnFlags flags = ImGuiTableColumnFlags_None; if (node.attributes.flags) { - flags = *(ImGuiTableColumnFlags*)node.attributes.flags; + flags = *(ImGuiTableColumnFlags*)node.attributes.flags.get(); } ImGui::TableSetupColumn(node.attributes.title.c_str(), flags); } break; diff --git a/src/app/gui/zeml.h b/src/app/gui/zeml.h index 3b474d5d..4d577cf7 100644 --- a/src/app/gui/zeml.h +++ b/src/app/gui/zeml.h @@ -5,7 +5,9 @@ #include #include +#include #include +#include #include #include #include @@ -87,17 +89,17 @@ enum class WidgetType { */ struct WidgetAttributes { std::string id; - std::string title; // For Window, Button - std::string text; // For Text, Button - double min; // For Slider - double max; // For Slider - double value; // For Slidecar - float width; // For Columns - int count = 0; // For Columns - ImVec2 size = ImVec2(0, 0); // For BeginChild - bool* selected = nullptr; // For Selectable - void* flags = nullptr; // For Various - void* data = nullptr; // For Various + std::string title; // For Window, Button + std::string text; // For Text, Button + double min; // For Slider + double max; // For Slider + double value; // For Slidecar + float width; // For Columns + int count = 0; // For Columns + ImVec2 size = ImVec2(0, 0); // For BeginChild + bool* selected = nullptr; // For Selectable + std::shared_ptr flags = nullptr; // For Various + void* data = nullptr; // For Various }; /**