From 073eee8fab06f2eb45ba9524115187633e8be340 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sat, 30 Jan 2021 23:02:03 +0100 Subject: [PATCH] Further improved UI/UX of welcome screen --- .../ImGui/source/imgui_imhex_extensions.cpp | 4 +-- .../include/hex/data_processor/attribute.hpp | 2 +- source/views/view_hexeditor.cpp | 6 ++++ source/views/view_pattern.cpp | 3 -- source/window.cpp | 32 +++++++++++++++++-- 5 files changed, 38 insertions(+), 9 deletions(-) diff --git a/external/ImGui/source/imgui_imhex_extensions.cpp b/external/ImGui/source/imgui_imhex_extensions.cpp index 968889ff9..7707dbf29 100644 --- a/external/ImGui/source/imgui_imhex_extensions.cpp +++ b/external/ImGui/source/imgui_imhex_extensions.cpp @@ -54,7 +54,7 @@ namespace ImGui { const ImVec2 label_size = CalcTextSize(label, NULL, true); ImVec2 pos = window->DC.CursorPos; - ImVec2 size = CalcItemSize(size_arg, label_size.x, label_size.y); + ImVec2 size = CalcItemSize(size_arg, label_size.x, label_size.y) + ImVec2(g.FontSize + style.FramePadding.x * 2, 0.0f); const ImRect bb(pos, pos + size); if (!ItemAdd(bb, id)) @@ -70,7 +70,7 @@ namespace ImGui { PushStyleColor(ImGuiCol_Text, ImU32(col)); RenderBullet(window->DrawList, bb.Min + ImVec2(style.FramePadding.x + g.FontSize * 0.5f, g.FontSize * 0.5f), col); RenderText(bb.Min + ImVec2(g.FontSize + style.FramePadding.x * 2, 0.0f), label, nullptr, false); - GetWindowDrawList()->AddLine(bb.Min + ImVec2(style.FramePadding.x, size.y), pos + size + ImVec2(g.FontSize * 2, 0), ImU32(col)); + GetWindowDrawList()->AddLine(bb.Min + ImVec2(style.FramePadding.x, size.y), pos + size, ImU32(col)); ImGui::NewLine(); PopStyleColor(); diff --git a/plugins/libimhex/include/hex/data_processor/attribute.hpp b/plugins/libimhex/include/hex/data_processor/attribute.hpp index 2359b2d7e..52c85ec51 100644 --- a/plugins/libimhex/include/hex/data_processor/attribute.hpp +++ b/plugins/libimhex/include/hex/data_processor/attribute.hpp @@ -31,7 +31,7 @@ namespace hex::dp { [[nodiscard]] std::string_view getName() const { return this->m_name; } void addConnectedAttribute(u32 linkId, Attribute *to) { this->m_connectedAttributes.insert({ linkId, to }); } - void removeConnectedAttribute(u32 linkId) { printf("%d\n", this->m_connectedAttributes.erase(linkId)); } + void removeConnectedAttribute(u32 linkId) { this->m_connectedAttributes.erase(linkId); } [[nodiscard]] std::map& getConnectedAttributes() { return this->m_connectedAttributes; } [[nodiscard]] Node* getParentNode() { return this->m_parentNode; } diff --git a/source/views/view_hexeditor.cpp b/source/views/view_hexeditor.cpp index d17eabccc..4f0b7d36b 100644 --- a/source/views/view_hexeditor.cpp +++ b/source/views/view_hexeditor.cpp @@ -147,6 +147,12 @@ namespace hex { this->openFile(path); this->getWindowOpenState() = true; }); + } else if (std::any_cast(name) == std::string("Open Project")) { + View::openFileBrowser("Open Project", imgui_addons::ImGuiFileBrowser::DialogMode::OPEN, ".hexproj", [this](auto path) { + ProjectFile::load(path); + View::postEvent(Events::ProjectFileLoad); + this->getWindowOpenState() = true; + }); } }); } diff --git a/source/views/view_pattern.cpp b/source/views/view_pattern.cpp index acc2aa5a8..553c82776 100644 --- a/source/views/view_pattern.cpp +++ b/source/views/view_pattern.cpp @@ -188,15 +188,12 @@ namespace hex { switch (theme) { default: case 0: /* Dark theme */ - ImGui::StyleColorsDark(); this->m_textEditor.SetPalette(TextEditor::GetDarkPalette()); break; case 1: /* Light theme */ - ImGui::StyleColorsLight(); this->m_textEditor.SetPalette(TextEditor::GetLightPalette()); break; case 2: /* Classic theme */ - ImGui::StyleColorsClassic(); this->m_textEditor.SetPalette(TextEditor::GetRetroBluePalette()); break; } diff --git a/source/window.cpp b/source/window.cpp index 0b61a711f..9458b7ad5 100644 --- a/source/window.cpp +++ b/source/window.cpp @@ -66,11 +66,33 @@ namespace hex { } #endif - ContentRegistry::Settings::load(); - View::postEvent(Events::SettingsChanged); - this->initGLFW(); this->initImGui(); + + ImGui::GetStyle().Colors[ImGuiCol_DockingEmptyBg] = ImGui::GetStyle().Colors[ImGuiCol_WindowBg]; + EventManager::subscribe(Events::SettingsChanged, this, [](auto) -> std::any { + int theme = ContentRegistry::Settings::getSettingsData()["Interface"]["Color theme"]; + + switch (theme) { + default: + case 0: /* Dark theme */ + ImGui::StyleColorsDark(); + break; + case 1: /* Light theme */ + ImGui::StyleColorsLight(); + break; + case 2: /* Classic theme */ + ImGui::StyleColorsClassic(); + break; + } + + ImGui::GetStyle().Colors[ImGuiCol_DockingEmptyBg] = ImGui::GetStyle().Colors[ImGuiCol_WindowBg]; + + return { }; + }); + + ContentRegistry::Settings::load(); + View::postEvent(Events::SettingsChanged); } Window::~Window() { @@ -83,6 +105,8 @@ namespace hex { ContentRegistry::Views::getEntries().clear(); this->deinitPlugins(); + + EventManager::unsubscribe(Events::SettingsChanged, this); } void Window::loop() { @@ -272,6 +296,8 @@ namespace hex { { if (ImGui::BulletHyperlink("Open File")) EventManager::post(Events::OpenWindow, "Open File"); + if (ImGui::BulletHyperlink("Open Project")) + EventManager::post(Events::OpenWindow, "Open Project"); } ImGui::TableNextRow(ImGuiTableRowFlags_None, 100); ImGui::TableNextColumn();