1
0
mirror of synced 2024-12-11 23:46:00 +01:00
ImHex/plugins/builtin/source/content/views/view_tools.cpp

65 lines
2.3 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
ViewTools::ViewTools() : View("hex.builtin.view.tools.name") {
this->m_dragStartIterator = ContentRegistry::Tools::impl::getEntries().end();
}
void ViewTools::drawContent() {
auto &tools = ContentRegistry::Tools::impl::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();
ImGui::NewLine();
} else {
if (ImGui::IsMouseClicked(0) && ImGui::IsItemActivated() && this->m_dragStartIterator == tools.end())
this->m_dragStartIterator = iter;
if (!ImGui::IsMouseDown(0))
this->m_dragStartIterator = tools.end();
if (!ImGui::IsItemHovered() && this->m_dragStartIterator == iter) {
detached = true;
}
}
}
2020-11-15 00:46:38 +01:00
}
ImGui::End();
}
void ViewTools::drawAlwaysVisible() {
auto &tools = ContentRegistry::Tools::impl::getEntries();
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::End();
}
2020-11-15 00:46:38 +01:00
}
}