From 51010096bb7f1d295af439239ee9175c6926cf84 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Fri, 29 Mar 2024 15:38:03 +0100 Subject: [PATCH] feat: Added provider information to search bar hover tooltip --- plugins/builtin/source/content/ui_items.cpp | 69 ++++++----- .../source/content/window_decoration.cpp | 111 ++++++++++-------- 2 files changed, 98 insertions(+), 82 deletions(-) diff --git a/plugins/builtin/source/content/ui_items.cpp b/plugins/builtin/source/content/ui_items.cpp index d49bc0762..5ad4fc153 100644 --- a/plugins/builtin/source/content/ui_items.cpp +++ b/plugins/builtin/source/content/ui_items.cpp @@ -334,6 +334,41 @@ namespace hex::plugin::builtin { } }; + void drawProviderTooltip(const prv::Provider *provider) { + if (ImGuiExt::InfoTooltip()) { + ImGui::BeginTooltip(); + + ImGuiExt::TextFormatted("{}", provider->getName().c_str()); + + const auto &description = provider->getDataDescription(); + if (!description.empty()) { + ImGui::Separator(); + if (ImGui::GetIO().KeyShift && !description.empty()) { + + if (ImGui::BeginTable("information", 2, ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_RowBg | ImGuiTableFlags_NoKeepColumnsVisible, ImVec2(400_scaled, 0))) { + ImGui::TableSetupColumn("type"); + ImGui::TableSetupColumn("value", ImGuiTableColumnFlags_WidthStretch); + + ImGui::TableNextRow(); + + for (auto &[name, value] : description) { + ImGui::TableNextColumn(); + ImGuiExt::TextFormatted("{}", name); + ImGui::TableNextColumn(); + ImGuiExt::TextFormattedWrapped("{}", value); + } + + ImGui::EndTable(); + } + } else { + ImGuiExt::TextFormattedDisabled("hex.builtin.provider.tooltip.show_more"_lang); + } + } + + ImGui::EndTooltip(); + } + } + void addToolbarItems() { ShortcutManager::addGlobalShortcut(AllowWhileTyping + ALT + CTRLCMD + Keys::Left, "hex.builtin.shortcut.prev_provider", []{ auto currIndex = ImHexApi::Provider::getCurrentProviderIndex(); @@ -379,6 +414,7 @@ namespace hex::plugin::builtin { alwaysShowProviderTabs = value.get(false); }); + // Toolbar items ContentRegistry::Interface::addToolbarItem([] { std::set menuItems; @@ -456,38 +492,7 @@ namespace hex::plugin::builtin { lastSelectedProvider = i; } - if (ImGuiExt::InfoTooltip()) { - ImGui::BeginTooltip(); - - ImGuiExt::TextFormatted("{}", tabProvider->getName().c_str()); - - const auto &description = tabProvider->getDataDescription(); - if (!description.empty()) { - ImGui::Separator(); - if (ImGui::GetIO().KeyShift && !description.empty()) { - - if (ImGui::BeginTable("information", 2, ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_RowBg | ImGuiTableFlags_NoKeepColumnsVisible, ImVec2(400_scaled, 0))) { - ImGui::TableSetupColumn("type"); - ImGui::TableSetupColumn("value", ImGuiTableColumnFlags_WidthStretch); - - ImGui::TableNextRow(); - - for (auto &[name, value] : description) { - ImGui::TableNextColumn(); - ImGuiExt::TextFormatted("{}", name); - ImGui::TableNextColumn(); - ImGuiExt::TextFormattedWrapped("{}", value); - } - - ImGui::EndTable(); - } - } else { - ImGuiExt::TextFormattedDisabled("hex.builtin.provider.tooltip.show_more"_lang); - } - } - - ImGui::EndTooltip(); - } + drawProviderTooltip(tabProvider); ImGui::PopID(); diff --git a/plugins/builtin/source/content/window_decoration.cpp b/plugins/builtin/source/content/window_decoration.cpp index 6eb8a1f05..3461467b5 100644 --- a/plugins/builtin/source/content/window_decoration.cpp +++ b/plugins/builtin/source/content/window_decoration.cpp @@ -17,6 +17,9 @@ namespace hex::plugin::builtin { + // Function that draws the provider popup, defiend in the ui_items.cpp file + void drawProviderTooltip(const prv::Provider *provider); + namespace { std::string s_windowTitle, s_windowTitleFull; @@ -70,58 +73,58 @@ namespace hex::plugin::builtin { } void drawSidebar(ImVec2 dockSpaceSize, ImVec2 sidebarPos, float sidebarWidth) { - static i32 openWindow = -1; - u32 index = 0; - ImGui::PushID("SideBarWindows"); - for (const auto &[icon, callback, enabledCallback] : ContentRegistry::Interface::impl::getSidebarItems()) { - ImGui::SetCursorPosY(sidebarPos.y + sidebarWidth * index); + static i32 openWindow = -1; + u32 index = 0; + ImGui::PushID("SideBarWindows"); + for (const auto &[icon, callback, enabledCallback] : ContentRegistry::Interface::impl::getSidebarItems()) { + ImGui::SetCursorPosY(sidebarPos.y + sidebarWidth * index); - ImGui::PushStyleColor(ImGuiCol_Button, ImGui::GetColorU32(ImGuiCol_MenuBarBg)); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImGui::GetColorU32(ImGuiCol_ScrollbarGrabActive)); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImGui::GetColorU32(ImGuiCol_ScrollbarGrabHovered)); + ImGui::PushStyleColor(ImGuiCol_Button, ImGui::GetColorU32(ImGuiCol_MenuBarBg)); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImGui::GetColorU32(ImGuiCol_ScrollbarGrabActive)); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImGui::GetColorU32(ImGuiCol_ScrollbarGrabHovered)); - ImGui::BeginDisabled(!(ImHexApi::Provider::isValid() && enabledCallback())); - { - if (ImGui::Button(icon.c_str(), ImVec2(sidebarWidth, sidebarWidth))) { - if (static_cast(openWindow) == index) - openWindow = -1; - else - openWindow = index; - } + ImGui::BeginDisabled(!(ImHexApi::Provider::isValid() && enabledCallback())); + { + if (ImGui::Button(icon.c_str(), ImVec2(sidebarWidth, sidebarWidth))) { + if (static_cast(openWindow) == index) + openWindow = -1; + else + openWindow = index; } - ImGui::EndDisabled(); - - ImGui::PopStyleColor(3); - - auto sideBarFocused = ImGui::IsWindowFocused(); - - bool open = static_cast(openWindow) == index; - if (open) { - - ImGui::SetNextWindowPos(ImGui::GetWindowPos() + sidebarPos + ImVec2(sidebarWidth - 1_scaled, -1_scaled)); - ImGui::SetNextWindowSize(ImVec2(0, dockSpaceSize.y + 5_scaled)); - - ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 1); - ImGui::PushStyleColor(ImGuiCol_WindowShadow, 0x00000000); - if (ImGui::Begin("SideBarWindow", &open, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse)) { - if (ImGui::BeginChild("##Content", ImVec2(), ImGuiChildFlags_ResizeX)) { - callback(); - } - ImGui::EndChild(); - - if (!ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows) && !sideBarFocused) { - openWindow = -1; - } - } - ImGui::End(); - ImGui::PopStyleVar(); - ImGui::PopStyleColor(); - } - - ImGui::NewLine(); - index++; } - ImGui::PopID(); + ImGui::EndDisabled(); + + ImGui::PopStyleColor(3); + + auto sideBarFocused = ImGui::IsWindowFocused(); + + bool open = static_cast(openWindow) == index; + if (open) { + + ImGui::SetNextWindowPos(ImGui::GetWindowPos() + sidebarPos + ImVec2(sidebarWidth - 1_scaled, -1_scaled)); + ImGui::SetNextWindowSize(ImVec2(0, dockSpaceSize.y + 5_scaled)); + + ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 1); + ImGui::PushStyleColor(ImGuiCol_WindowShadow, 0x00000000); + if (ImGui::Begin("SideBarWindow", &open, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse)) { + if (ImGui::BeginChild("##Content", ImVec2(), ImGuiChildFlags_ResizeX)) { + callback(); + } + ImGui::EndChild(); + + if (!ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows) && !sideBarFocused) { + openWindow = -1; + } + } + ImGui::End(); + ImGui::PopStyleVar(); + ImGui::PopStyleColor(); + } + + ImGui::NewLine(); + index++; + } + ImGui::PopID(); } void drawTitleBar() { @@ -228,8 +231,16 @@ namespace hex::plugin::builtin { EventSearchBoxClicked::post(ImGuiMouseButton_Right); ImGui::PushTextWrapPos(300_scaled); - if (!s_windowTitleFull.empty()) - ImGui::SetItemTooltip("%s", s_windowTitleFull.c_str()); + + if (auto provider = ImHexApi::Provider::get(); provider != nullptr) { + drawProviderTooltip(ImHexApi::Provider::get()); + } else { + if (ImGuiExt::InfoTooltip()) { + ImGui::BeginTooltip(); + ImGui::TextUnformatted(s_windowTitleFull.c_str()); + ImGui::EndTooltip(); + } + } ImGui::PopTextWrapPos(); ImGui::PopStyleVar(3);