From 263c5f6830f9538480a334f5f3f199feda6127c2 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Tue, 5 Aug 2025 23:32:27 +0200 Subject: [PATCH] impr: Added icons to all tools --- .../include/hex/api/content_registry.hpp | 3 +- lib/libimhex/source/api/content_registry.cpp | 4 +-- .../builtin/source/content/tools_entries.cpp | 35 ++++++++++--------- .../source/content/views/view_tools.cpp | 10 +++--- 4 files changed, 27 insertions(+), 25 deletions(-) diff --git a/lib/libimhex/include/hex/api/content_registry.hpp b/lib/libimhex/include/hex/api/content_registry.hpp index 3f2e5616c..c0df93dd8 100644 --- a/lib/libimhex/include/hex/api/content_registry.hpp +++ b/lib/libimhex/include/hex/api/content_registry.hpp @@ -632,6 +632,7 @@ EXPORT_MODULE namespace hex { struct Entry { UnlocalizedString unlocalizedName; + const char *icon; Callback function; }; @@ -644,7 +645,7 @@ EXPORT_MODULE namespace hex { * @param unlocalizedName The unlocalized name of the tool * @param function The function that will be called to draw the tool */ - void add(const UnlocalizedString &unlocalizedName, const impl::Callback &function); + void add(const UnlocalizedString &unlocalizedName, const char *icon, const impl::Callback &function); } /* Data Inspector Registry. Allows adding of new types to the data inspector */ diff --git a/lib/libimhex/source/api/content_registry.cpp b/lib/libimhex/source/api/content_registry.cpp index c7e7b6cf2..6ad37d289 100644 --- a/lib/libimhex/source/api/content_registry.cpp +++ b/lib/libimhex/source/api/content_registry.cpp @@ -767,10 +767,10 @@ namespace hex { } - void add(const UnlocalizedString &unlocalizedName, const impl::Callback &function) { + void add(const UnlocalizedString &unlocalizedName, const char *icon, const impl::Callback &function) { log::debug("Registered new tool: {}", unlocalizedName.get()); - impl::s_tools->emplace_back(impl::Entry { unlocalizedName, function }); + impl::s_tools->emplace_back(impl::Entry { unlocalizedName, icon, function }); } } diff --git a/plugins/builtin/source/content/tools_entries.cpp b/plugins/builtin/source/content/tools_entries.cpp index 2d880ff63..24e42882d 100644 --- a/plugins/builtin/source/content/tools_entries.cpp +++ b/plugins/builtin/source/content/tools_entries.cpp @@ -5,6 +5,7 @@ #include #include +#include namespace hex::plugin::builtin { @@ -31,23 +32,23 @@ namespace hex::plugin::builtin { } void registerToolEntries() { - ContentRegistry::Tools::add("hex.builtin.tools.demangler", drawDemangler); - ContentRegistry::Tools::add("hex.builtin.tools.ascii_table", drawASCIITable); - ContentRegistry::Tools::add("hex.builtin.tools.regex_replacer", drawRegexReplacer); - ContentRegistry::Tools::add("hex.builtin.tools.color", drawColorPicker); - ContentRegistry::Tools::add("hex.builtin.tools.calc", drawMathEvaluator); - ContentRegistry::Tools::add("hex.builtin.tools.graphing", drawGraphingCalculator); - ContentRegistry::Tools::add("hex.builtin.tools.base_converter", drawBaseConverter); - ContentRegistry::Tools::add("hex.builtin.tools.byte_swapper", drawByteSwapper); - ContentRegistry::Tools::add("hex.builtin.tools.permissions", drawPermissionsCalculator); - //ContentRegistry::Tools::add("hex.builtin.tools.file_uploader", drawFileUploader); - ContentRegistry::Tools::add("hex.builtin.tools.wiki_explain", drawWikiExplainer); - ContentRegistry::Tools::add("hex.builtin.tools.file_tools", drawFileTools); - ContentRegistry::Tools::add("hex.builtin.tools.ieee754", drawIEEE754Decoder); - ContentRegistry::Tools::add("hex.builtin.tools.invariant_multiplication", drawInvariantMultiplicationDecoder); - ContentRegistry::Tools::add("hex.builtin.tools.tcp_client_server", drawTCPClientServer); - ContentRegistry::Tools::add("hex.builtin.tools.euclidean_algorithm", drawEuclidianAlgorithm); - ContentRegistry::Tools::add("hex.builtin.tools.http_requests", drawHTTPRequestMaker); + ContentRegistry::Tools::add("hex.builtin.tools.demangler", ICON_VS_CODE, drawDemangler); + ContentRegistry::Tools::add("hex.builtin.tools.ascii_table", ICON_VS_TABLE, drawASCIITable); + ContentRegistry::Tools::add("hex.builtin.tools.regex_replacer", ICON_VS_REGEX, drawRegexReplacer); + ContentRegistry::Tools::add("hex.builtin.tools.color", ICON_VS_SYMBOL_COLOR, drawColorPicker); + ContentRegistry::Tools::add("hex.builtin.tools.calc", ICON_VS_SYMBOL_OPERATOR, drawMathEvaluator); + ContentRegistry::Tools::add("hex.builtin.tools.graphing", ICON_VS_GRAPH_LINE, drawGraphingCalculator); + ContentRegistry::Tools::add("hex.builtin.tools.base_converter", ICON_VS_SYMBOL_RULER, drawBaseConverter); + ContentRegistry::Tools::add("hex.builtin.tools.byte_swapper", ICON_VS_ARROW_SWAP, drawByteSwapper); + ContentRegistry::Tools::add("hex.builtin.tools.permissions", ICON_VS_ACCOUNT, drawPermissionsCalculator); + // ContentRegistry::Tools::add("hex.builtin.tools.file_uploader", ICON_VS_CLOUD_UPLOAD, drawFileUploader); + ContentRegistry::Tools::add("hex.builtin.tools.wiki_explain", ICON_VS_GLOBE, drawWikiExplainer); + ContentRegistry::Tools::add("hex.builtin.tools.file_tools", ICON_VS_FILES, drawFileTools); + ContentRegistry::Tools::add("hex.builtin.tools.ieee754", ICON_VS_PERCENTAGE, drawIEEE754Decoder); + ContentRegistry::Tools::add("hex.builtin.tools.invariant_multiplication", ICON_VS_UNFOLD, drawInvariantMultiplicationDecoder); + ContentRegistry::Tools::add("hex.builtin.tools.tcp_client_server", ICON_VS_SERVER_ENVIRONMENT, drawTCPClientServer); + ContentRegistry::Tools::add("hex.builtin.tools.euclidean_algorithm", ICON_VS_GROUP_BY_REF_TYPE, drawEuclidianAlgorithm); + ContentRegistry::Tools::add("hex.builtin.tools.http_requests", ICON_VS_SERVER_PROCESS, drawHTTPRequestMaker); } } diff --git a/plugins/builtin/source/content/views/view_tools.cpp b/plugins/builtin/source/content/views/view_tools.cpp index 6f79bd176..1af0e894e 100644 --- a/plugins/builtin/source/content/views/view_tools.cpp +++ b/plugins/builtin/source/content/views/view_tools.cpp @@ -20,7 +20,7 @@ namespace hex::plugin::builtin { }); LayoutManager::registerStoreCallback([this](ImGuiTextBuffer *buffer) { - for (auto &[unlocalizedName, function] : ContentRegistry::Tools::impl::getEntries()) { + for (auto &[unlocalizedName, icon, function] : ContentRegistry::Tools::impl::getEntries()) { auto detached = m_detachedTools[unlocalizedName]; buffer->appendf("%s=%d\n", unlocalizedName.get().c_str(), detached); } @@ -32,13 +32,13 @@ namespace hex::plugin::builtin { // Draw all tools for (auto iter = tools.begin(); iter != tools.end(); ++iter) { - auto &[unlocalizedName, function] = *iter; + auto &[unlocalizedName, icon, function] = *iter; // If the tool has been detached from the main window, don't draw it here anymore if (m_detachedTools[unlocalizedName]) continue; // Draw the tool - if (ImGui::CollapsingHeader(Lang(unlocalizedName))) { + if (ImGui::CollapsingHeader(hex::format("{} {}", icon, Lang(unlocalizedName)).c_str())) { function(); ImGui::NewLine(); } else { @@ -69,13 +69,13 @@ namespace hex::plugin::builtin { auto &tools = ContentRegistry::Tools::impl::getEntries(); for (auto iter = tools.begin(); iter != tools.end(); ++iter) { - auto &[unlocalizedName, function] = *iter; + auto &[unlocalizedName, icon, function] = *iter; // If the tool is still attached to the main window, don't draw it here if (!m_detachedTools[unlocalizedName]) continue; // Load the window height that is dependent on the tool content - const auto windowName = View::toWindowName(unlocalizedName); + const auto windowName = hex::format("{} {}", icon, View::toWindowName(unlocalizedName)); const auto height = m_windowHeights[ImGui::FindWindowByName(windowName.c_str())]; if (height > 0) ImGui::SetNextWindowSizeConstraints(ImVec2(400_scaled, height), ImVec2(FLT_MAX, height));