From c1f76be3b7b0e9d394148e27892c6777b9b8b94b Mon Sep 17 00:00:00 2001 From: WerWolv Date: Thu, 14 Dec 2023 13:50:26 +0100 Subject: [PATCH] feat: Display complete window title when hovering over search bar --- .../include/hex/api/event_manager.hpp | 2 +- main/gui/include/window.hpp | 2 +- main/gui/source/window/window.cpp | 25 +++++++++++++------ .../content/views/view_command_palette.cpp | 10 +++++--- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/lib/libimhex/include/hex/api/event_manager.hpp b/lib/libimhex/include/hex/api/event_manager.hpp index a710e4d8f..8da16bb38 100644 --- a/lib/libimhex/include/hex/api/event_manager.hpp +++ b/lib/libimhex/include/hex/api/event_manager.hpp @@ -250,7 +250,7 @@ namespace hex { EVENT_DEF(EventStoreContentRemoved, const std::fs::path&); EVENT_DEF(EventImHexClosing); EVENT_DEF(EventAchievementUnlocked, const Achievement&); - EVENT_DEF(EventSearchBoxClicked); + EVENT_DEF(EventSearchBoxClicked, u32); EVENT_DEF(EventViewOpened, View*); EVENT_DEF(EventProviderDataModified, prv::Provider *, u64, u64, const u8*); diff --git a/main/gui/include/window.hpp b/main/gui/include/window.hpp index e281fd8e6..5310dd86e 100644 --- a/main/gui/include/window.hpp +++ b/main/gui/include/window.hpp @@ -49,7 +49,7 @@ namespace hex { GLFWwindow *m_window = nullptr; - std::string m_windowTitle; + std::string m_windowTitle, m_windowTitleFull; double m_lastStartFrameTime = 0; double m_lastFrameTime = 0; diff --git a/main/gui/source/window/window.cpp b/main/gui/source/window/window.cpp index 99b06f007..1b6b4637e 100644 --- a/main/gui/source/window/window.cpp +++ b/main/gui/source/window/window.cpp @@ -111,30 +111,33 @@ namespace hex { // Handle updating the window title RequestUpdateWindowTitle::subscribe(this, [this] { + std::string prefix, postfix; std::string title = "ImHex"; if (ProjectFile::hasPath()) { // If a project is open, show the project name instead of the file name - title = "Project " + hex::limitStringLength(ProjectFile::getPath().stem().string(), 32); + prefix = "Project "; + title = ProjectFile::getPath().stem().string(); if (ImHexApi::Provider::isDirty()) - title += " (*)"; + postfix += " (*)"; } else if (ImHexApi::Provider::isValid()) { auto provider = ImHexApi::Provider::get(); if (provider != nullptr) { - title = hex::limitStringLength(provider->getName(), 32); + title = provider->getName(); if (provider->isDirty()) - title += " (*)"; + postfix += " (*)"; if (!provider->isWritable()) - title += " (Read Only)"; + postfix += " (Read Only)"; } } - this->m_windowTitle = title; + this->m_windowTitle = prefix + hex::limitStringLength(title, 32) + postfix; + this->m_windowTitleFull = prefix + title + postfix; if (this->m_window != nullptr) { if (title != "ImHex") @@ -322,9 +325,17 @@ namespace hex { ImGui::SetCursorPos(searchBoxPos); if (ImGui::Button(this->m_windowTitle.c_str(), searchBoxSize)) { - EventSearchBoxClicked::post(); + EventSearchBoxClicked::post(ImGuiMouseButton_Left); } + if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) + EventSearchBoxClicked::post(ImGuiMouseButton_Right); + + ImGui::PushTextWrapPos(300_scaled); + if (!this->m_windowTitleFull.empty()) + ImGui::SetItemTooltip(this->m_windowTitleFull.c_str()); + ImGui::PopTextWrapPos(); + ImGui::PopStyleVar(3); ImGui::PopStyleColor(3); } diff --git a/plugins/builtin/source/content/views/view_command_palette.cpp b/plugins/builtin/source/content/views/view_command_palette.cpp index b438c43f5..32dafa82b 100644 --- a/plugins/builtin/source/content/views/view_command_palette.cpp +++ b/plugins/builtin/source/content/views/view_command_palette.cpp @@ -13,10 +13,12 @@ namespace hex::plugin::builtin { this->m_justOpened = true; }); - EventSearchBoxClicked::subscribe([this] { - RequestOpenPopup::post("hex.builtin.view.command_palette.name"_lang); - this->m_commandPaletteOpen = true; - this->m_justOpened = true; + EventSearchBoxClicked::subscribe([this](ImGuiMouseButton button) { + if (button == ImGuiMouseButton_Left) { + RequestOpenPopup::post("hex.builtin.view.command_palette.name"_lang); + this->m_commandPaletteOpen = true; + this->m_justOpened = true; + } }); }