From 0e00555703d0e9f7bb4b5b5ce57dcf19b1f3681b Mon Sep 17 00:00:00 2001 From: WerWolv Date: Thu, 18 Feb 2021 12:09:19 +0100 Subject: [PATCH] Added Footer and API for it and the welcome screen --- .../ImGui/source/imgui_imhex_extensions.cpp | 2 +- plugins/builtin/source/lang/en_US.cpp | 1 + .../include/hex/api/content_registry.hpp | 10 +++ .../include/hex/helpers/shared_data.hpp | 3 + .../libimhex/source/api/content_registry.cpp | 17 +++++ .../libimhex/source/helpers/shared_data.cpp | 3 + source/window.cpp | 74 +++++++++++++------ 7 files changed, 87 insertions(+), 23 deletions(-) diff --git a/external/ImGui/source/imgui_imhex_extensions.cpp b/external/ImGui/source/imgui_imhex_extensions.cpp index 7707dbf29..62caf5b12 100644 --- a/external/ImGui/source/imgui_imhex_extensions.cpp +++ b/external/ImGui/source/imgui_imhex_extensions.cpp @@ -107,7 +107,7 @@ namespace ImGui { ImGui::PushStyleVar(ImGuiStyleVar_ButtonTextAlign, ImVec2(0.0, 0.5)); // Render - const ImU32 col = GetColorU32((held && hovered) ? ImGuiCol_ScrollbarBg : hovered ? ImGuiCol_WindowBg : ImGuiCol_PopupBg); + const ImU32 col = GetColorU32((held && hovered) ? ImGuiCol_TableHeaderBg : hovered ? ImGuiCol_TableBorderLight : ImGuiCol_TableBorderStrong); RenderNavHighlight(bb, id); RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding); PushStyleColor(ImGuiCol_Text, GetColorU32(ImGuiCol_ButtonActive)); diff --git a/plugins/builtin/source/lang/en_US.cpp b/plugins/builtin/source/lang/en_US.cpp index e2b96d279..2eff28f4b 100644 --- a/plugins/builtin/source/lang/en_US.cpp +++ b/plugins/builtin/source/lang/en_US.cpp @@ -37,6 +37,7 @@ namespace hex::plugin::builtin { { "hex.welcome.learn.plugins.title", "Plugins API\"" }, { "hex.welcome.learn.plugins.desc", "Extend ImHex with additional features using plugins" }, { "hex.welcome.learn.plugins.link", "https://github.com/WerWolv/ImHex/wiki/Plugins-Development-Guide" }, + { "hex.welcome.header.various", "Various" }, { "hex.common.little_endian", "Little Endian" }, { "hex.common.big_endian", "Big Endian" }, diff --git a/plugins/libimhex/include/hex/api/content_registry.hpp b/plugins/libimhex/include/hex/api/content_registry.hpp index 8ca508b7e..8e657ab28 100644 --- a/plugins/libimhex/include/hex/api/content_registry.hpp +++ b/plugins/libimhex/include/hex/api/content_registry.hpp @@ -183,6 +183,16 @@ namespace hex { static std::map& getLanguages(); static std::map>& getLanguageDefinitions(); }; + + struct Interface { + using DrawCallback = std::function; + + static void addWelcomeScreenEntry(const DrawCallback &function); + static void addFooterItem(const DrawCallback &function); + + static std::vector& getWelcomeScreenEntries(); + static std::vector& getFooterItems(); + }; }; } \ No newline at end of file diff --git a/plugins/libimhex/include/hex/helpers/shared_data.hpp b/plugins/libimhex/include/hex/helpers/shared_data.hpp index ea912c5e8..98a18b6c5 100644 --- a/plugins/libimhex/include/hex/helpers/shared_data.hpp +++ b/plugins/libimhex/include/hex/helpers/shared_data.hpp @@ -68,6 +68,9 @@ namespace hex { static std::map> languageDefinitions; static std::map loadedLanguageStrings; + static std::vector welcomeScreenEntries; + static std::vector footerItems; + static imgui_addons::ImGuiFileBrowser fileBrowser; static imgui_addons::ImGuiFileBrowser::DialogMode fileBrowserDialogMode; static std::string fileBrowserTitle; diff --git a/plugins/libimhex/source/api/content_registry.cpp b/plugins/libimhex/source/api/content_registry.cpp index b80da2b4b..bc22823d3 100644 --- a/plugins/libimhex/source/api/content_registry.cpp +++ b/plugins/libimhex/source/api/content_registry.cpp @@ -225,4 +225,21 @@ namespace hex { std::map>& ContentRegistry::Language::getLanguageDefinitions() { return SharedData::languageDefinitions; } + + + void ContentRegistry::Interface::addWelcomeScreenEntry(const ContentRegistry::Interface::DrawCallback &function) { + getWelcomeScreenEntries().push_back(function); + } + + void ContentRegistry::Interface::addFooterItem(const ContentRegistry::Interface::DrawCallback &function){ + getFooterItems().push_back(function); + } + + + std::vector& ContentRegistry::Interface::getWelcomeScreenEntries() { + return SharedData::welcomeScreenEntries; + } + std::vector& ContentRegistry::Interface::getFooterItems() { + return SharedData::footerItems; + } } \ No newline at end of file diff --git a/plugins/libimhex/source/helpers/shared_data.cpp b/plugins/libimhex/source/helpers/shared_data.cpp index 01270c87d..44cf0d12b 100644 --- a/plugins/libimhex/source/helpers/shared_data.cpp +++ b/plugins/libimhex/source/helpers/shared_data.cpp @@ -22,6 +22,9 @@ namespace hex { std::map> SharedData::languageDefinitions; std::map SharedData::loadedLanguageStrings; + std::vector SharedData::welcomeScreenEntries; + std::vector SharedData::footerItems; + imgui_addons::ImGuiFileBrowser SharedData::fileBrowser; imgui_addons::ImGuiFileBrowser::DialogMode SharedData::fileBrowserDialogMode; std::string SharedData::fileBrowserTitle; diff --git a/source/window.cpp b/source/window.cpp index bc3c351fd..bda04f617 100644 --- a/source/window.cpp +++ b/source/window.cpp @@ -131,6 +131,9 @@ namespace hex { for (const auto &path : ContentRegistry::Settings::read("hex.builtin.setting.imhex", "hex.builtin.setting.imhex.recent_files")) this->m_recentFiles.push_back(path); + + ContentRegistry::Interface::addFooterItem([]{ ImGui::TextUnformatted("ImHex"); }); + ContentRegistry::Interface::addFooterItem([]{ ImGui::ProgressBar(0.69, ImVec2(200, 25)); }); } Window::~Window() { @@ -233,19 +236,33 @@ namespace hex { ImGuiWindowFlags windowFlags = ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize - | ImGuiWindowFlags_NoNavFocus | ImGuiWindowFlags_NoBringToFrontOnFocus; + | ImGuiWindowFlags_NoNavFocus | ImGuiWindowFlags_NoBringToFrontOnFocus + | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse; ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; if (ImGui::Begin("DockSpace", nullptr, windowFlags)) { ImGui::PopStyleVar(2); - ImGui::DockSpace(ImGui::GetID("MainDock"), ImVec2(0.0f, 0.0f)); + + ImGui::DockSpace(ImGui::GetID("MainDock"), ImVec2(0.0f, ImGui::GetContentRegionAvail().y - ImGui::GetTextLineHeightWithSpacing() - 1)); + + ImGui::Separator(); + for (const auto &callback : ContentRegistry::Interface::getFooterItems()) { + auto prevIdx = ImGui::GetWindowDrawList()->_VtxCurrentIdx; + callback(); + auto currIdx = ImGui::GetWindowDrawList()->_VtxCurrentIdx; + + // Only draw separator if something was actually drawn + if (prevIdx != currIdx) { + ImGui::SameLine(); + ImGui::SeparatorEx(ImGuiSeparatorFlags_Vertical); + ImGui::SameLine(); + } + } if (ImGui::BeginMenuBar()) { - auto MenuBarItems = { "hex.menu.file"_lang, "hex.menu.edit"_lang, "hex.menu.view"_lang, "hex.menu.help"_lang }; - - for (auto menu : MenuBarItems) + for (const auto& menu : { "hex.menu.file"_lang, "hex.menu.edit"_lang, "hex.menu.view"_lang, "hex.menu.help"_lang }) if (ImGui::BeginMenu(menu)) ImGui::EndMenu(); if (ImGui::BeginMenu("hex.menu.view"_lang)) { @@ -332,26 +349,27 @@ namespace hex { } void Window::drawWelcomeScreen() { - ImGui::UnderlinedText("hex.welcome.header.main"_lang, ImGui::GetStyleColorVec4(ImGuiCol_HeaderActive)); + ImGui::UnderlinedText("hex.welcome.header.main"_lang, ImGui::GetStyleColorVec4(ImGuiCol_Text)); ImGui::NewLine(); - auto availableSpace = ImGui::GetContentRegionAvail(); + const auto availableSpace = ImGui::GetContentRegionAvail(); + const auto rowHeight = ImGui::GetTextLineHeightWithSpacing() * 6; ImGui::Indent(); if (ImGui::BeginTable("Welcome Left", 1, ImGuiTableFlags_NoBordersInBody, ImVec2(availableSpace.x / 2, availableSpace.y))) { - ImGui::TableNextRow(ImGuiTableRowFlags_None, 100); + ImGui::TableNextRow(ImGuiTableRowFlags_None, rowHeight); ImGui::TableNextColumn(); - ImGui::Text("hex.welcome.header.start"_lang); + ImGui::TextUnformatted("hex.welcome.header.start"_lang); { if (ImGui::BulletHyperlink("hex.welcome.start.open_file"_lang)) EventManager::post(Events::OpenWindow, "Open File"); if (ImGui::BulletHyperlink("hex.welcome.start.open_project"_lang)) EventManager::post(Events::OpenWindow, "Open Project"); } - ImGui::TableNextRow(ImGuiTableRowFlags_None, 100); + ImGui::TableNextRow(ImGuiTableRowFlags_None, rowHeight); ImGui::TableNextColumn(); - ImGui::Text("hex.welcome.start.recent"_lang); + ImGui::TextUnformatted("hex.welcome.start.recent"_lang); { if (!this->m_recentFiles.empty()) { for (auto &path : this->m_recentFiles) { @@ -362,9 +380,9 @@ namespace hex { } } } - ImGui::TableNextRow(ImGuiTableRowFlags_None, 100); + ImGui::TableNextRow(ImGuiTableRowFlags_None, rowHeight); ImGui::TableNextColumn(); - ImGui::Text("hex.welcome.header.help"_lang); + ImGui::TextUnformatted("hex.welcome.header.help"_lang); { if (ImGui::BulletHyperlink("hex.welcome.help.repo"_lang)) hex::openWebpage("hex.welcome.help.repo.link"_lang); if (ImGui::BulletHyperlink("hex.welcome.help.gethelp"_lang)) hex::openWebpage("hex.welcome.help.gethelp.link"_lang); @@ -374,25 +392,37 @@ namespace hex { } ImGui::SameLine(); if (ImGui::BeginTable("Welcome Right", 1, ImGuiTableFlags_NoBordersInBody, ImVec2(availableSpace.x / 2, availableSpace.y))) { - ImGui::TableNextRow(ImGuiTableRowFlags_None, 100); + ImGui::TableNextRow(ImGuiTableRowFlags_None, rowHeight); ImGui::TableNextColumn(); - ImGui::Text("hex.welcome.header.customize"_lang); + ImGui::TextUnformatted("hex.welcome.header.customize"_lang); { - if (ImGui::DescriptionButton("hex.welcome.customize.settings.title"_lang, "hex.welcome.customize.settings.desc"_lang, ImVec2(ImGui::GetContentRegionAvail().x * 0.8f, 0))) + if (ImGui::DescriptionButton("hex.welcome.customize.settings.title"_lang, "hex.welcome.customize.settings.desc"_lang, ImVec2(ImGui::GetContentRegionAvail().x * 0.8F, 0))) EventManager::post(Events::OpenWindow, "hex.view.settings.title"); } - ImGui::TableNextRow(ImGuiTableRowFlags_None, 100); + ImGui::TableNextRow(ImGuiTableRowFlags_None, rowHeight); ImGui::TableNextColumn(); - ImGui::Text("hex.welcome.header.learn"_lang); + ImGui::TextUnformatted("hex.welcome.header.learn"_lang); { - if (ImGui::DescriptionButton("hex.welcome.learn.latest.title"_lang, "hex.welcome.learn.latest.desc"_lang, ImVec2(ImGui::GetContentRegionAvail().x * 0.8, 0))) + if (ImGui::DescriptionButton("hex.welcome.learn.latest.title"_lang, "hex.welcome.learn.latest.desc"_lang, ImVec2(ImGui::GetContentRegionAvail().x * 0.8F, 0))) hex::openWebpage("hex.welcome.learn.latest.link"_lang); - if (ImGui::DescriptionButton("hex.welcome.learn.pattern.title"_lang, "hex.welcome.learn.pattern.desc"_lang, ImVec2(ImGui::GetContentRegionAvail().x * 0.8, 0))) + if (ImGui::DescriptionButton("hex.welcome.learn.pattern.title"_lang, "hex.welcome.learn.pattern.desc"_lang, ImVec2(ImGui::GetContentRegionAvail().x * 0.8F, 0))) hex::openWebpage("hex.welcome.learn.pattern.link"_lang); - if (ImGui::DescriptionButton("hex.welcome.learn.plugins.title"_lang, "hex.welcome.learn.plugins.desc"_lang, ImVec2(ImGui::GetContentRegionAvail().x * 0.8, 0))) + if (ImGui::DescriptionButton("hex.welcome.learn.plugins.title"_lang, "hex.welcome.learn.plugins.desc"_lang, ImVec2(ImGui::GetContentRegionAvail().x * 0.8F, 0))) hex::openWebpage("hex.welcome.learn.plugins.link"_lang); } + auto extraWelcomeScreenEntries = ContentRegistry::Interface::getWelcomeScreenEntries(); + if (!extraWelcomeScreenEntries.empty()) { + ImGui::TableNextRow(ImGuiTableRowFlags_None, rowHeight); + ImGui::TableNextColumn(); + ImGui::TextUnformatted("hex.welcome.header.various"_lang); + { + for (const auto &callback : extraWelcomeScreenEntries) + callback(); + } + } + + ImGui::EndTable(); } } @@ -498,7 +528,7 @@ namespace hex { ImGuiStyle& style = ImGui::GetStyle(); io.ConfigFlags |= ImGuiConfigFlags_DockingEnable | ImGuiConfigFlags_ViewportsEnable | ImGuiConfigFlags_NavEnableKeyboard; - io.ConfigViewportsNoTaskBarIcon = true; + io.ConfigViewportsNoTaskBarIcon = false; io.KeyMap[ImGuiKey_Tab] = GLFW_KEY_TAB; io.KeyMap[ImGuiKey_LeftArrow] = GLFW_KEY_LEFT; io.KeyMap[ImGuiKey_RightArrow] = GLFW_KEY_RIGHT;