mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-02 13:37:42 -05:00
refactor: Streamline entire view system
This commit is contained in:
@@ -5,49 +5,45 @@
|
||||
|
||||
namespace hex::plugin::builtin {
|
||||
|
||||
ViewTools::ViewTools() : View("hex.builtin.view.tools.name") {
|
||||
ViewTools::ViewTools() : View::Window("hex.builtin.view.tools.name") {
|
||||
this->m_dragStartIterator = ContentRegistry::Tools::impl::getEntries().end();
|
||||
}
|
||||
|
||||
void ViewTools::drawContent() {
|
||||
auto &tools = ContentRegistry::Tools::impl::getEntries();
|
||||
|
||||
if (ImGui::Begin(View::toWindowName("hex.builtin.view.tools.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) {
|
||||
// Draw all tools
|
||||
for (auto iter = tools.begin(); iter != tools.end(); ++iter) {
|
||||
auto &[name, function, detached] = *iter;
|
||||
|
||||
// Draw all tools
|
||||
for (auto iter = tools.begin(); iter != tools.end(); ++iter) {
|
||||
auto &[name, function, detached] = *iter;
|
||||
// If the tool has been detached from the main window, don't draw it here anymore
|
||||
if (detached) continue;
|
||||
|
||||
// If the tool has been detached from the main window, don't draw it here anymore
|
||||
if (detached) continue;
|
||||
// Draw the tool
|
||||
if (ImGui::CollapsingHeader(LangEntry(name))) {
|
||||
function();
|
||||
ImGui::NewLine();
|
||||
} else {
|
||||
// Handle dragging the tool out of the main window
|
||||
|
||||
// Draw the tool
|
||||
if (ImGui::CollapsingHeader(LangEntry(name))) {
|
||||
function();
|
||||
ImGui::NewLine();
|
||||
} else {
|
||||
// Handle dragging the tool out of the main window
|
||||
// If the user clicks on the header, start dragging the tool remember the iterator
|
||||
if (ImGui::IsMouseClicked(0) && ImGui::IsItemActivated() && this->m_dragStartIterator == tools.end())
|
||||
this->m_dragStartIterator = iter;
|
||||
|
||||
// If the user clicks on the header, start dragging the tool remember the iterator
|
||||
if (ImGui::IsMouseClicked(0) && ImGui::IsItemActivated() && this->m_dragStartIterator == tools.end())
|
||||
this->m_dragStartIterator = iter;
|
||||
|
||||
// If the user released the mouse button, stop dragging the tool
|
||||
if (!ImGui::IsMouseDown(0))
|
||||
this->m_dragStartIterator = tools.end();
|
||||
|
||||
// Detach the tool if the user dragged it out of the main window
|
||||
if (!ImGui::IsItemHovered() && this->m_dragStartIterator == iter) {
|
||||
detached = true;
|
||||
}
|
||||
// If the user released the mouse button, stop dragging the tool
|
||||
if (!ImGui::IsMouseDown(0))
|
||||
this->m_dragStartIterator = tools.end();
|
||||
|
||||
// Detach the tool if the user dragged it out of the main window
|
||||
if (!ImGui::IsItemHovered() && this->m_dragStartIterator == iter) {
|
||||
detached = true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void ViewTools::drawAlwaysVisible() {
|
||||
void ViewTools::drawAlwaysVisibleContent() {
|
||||
// Make sure the tool windows never get drawn over the welcome screen
|
||||
if (!ImHexApi::Provider::isValid())
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user