1
0
mirror of synced 2024-11-30 18:34:29 +01:00
ImHex/plugins/builtin/source/content/views/view_tools.cpp

58 lines
2.1 KiB
C++
Raw Normal View History

2021-12-07 22:47:41 +01:00
#include "content/views/view_tools.hpp"
#include <imgui_internal.h>
2020-11-15 00:46:38 +01:00
#include <hex/api/content_registry.hpp>
2021-12-07 22:47:41 +01:00
namespace hex::plugin::builtin {
2020-11-15 00:46:38 +01:00
2021-12-07 22:47:41 +01:00
ViewTools::ViewTools() : View("hex.builtin.view.tools.name") { }
void ViewTools::drawContent() {
auto &tools = ContentRegistry::Tools::getEntries();
2021-12-07 22:47:41 +01:00
if (ImGui::Begin(View::toWindowName("hex.builtin.view.tools.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) {
for (auto iter = tools.begin(); iter != tools.end(); iter++) {
auto &[name, function, detached] = *iter;
if (detached) continue;
if (ImGui::CollapsingHeader(LangEntry(name))) {
function();
} else {
if (ImGui::IsMouseClicked(0) && ImGui::IsItemActivated() && this->m_dragStartIterator == tools.end())
this->m_dragStartIterator = iter;
if (!ImGui::IsItemHovered() && this->m_dragStartIterator == iter) {
detached = true;
}
if (!ImGui::IsMouseDown(0))
this->m_dragStartIterator = tools.end();
}
}
2020-11-15 00:46:38 +01:00
}
ImGui::End();
for (auto iter = tools.begin(); iter != tools.end(); iter++) {
auto &[name, function, detached] = *iter;
if (!detached) continue;
ImGui::SetNextWindowSize(scaled(ImVec2(600, 0)));
if (ImGui::Begin(View::toWindowName(name).c_str(), &detached, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize)) {
function();
if (ImGui::IsWindowAppearing() && this->m_dragStartIterator == iter) {
this->m_dragStartIterator = tools.end();
// Attach the newly created window to the cursor, so it gets dragged around
GImGui->MovingWindow = ImGui::GetCurrentWindow();
GImGui->ActiveId = GImGui->MovingWindow->MoveId;
ImGui::DockContextQueueUndockWindow(GImGui, GImGui->MovingWindow);
}
}
ImGui::End();
}
2020-11-15 00:46:38 +01:00
}
}