1
0
mirror of synced 2024-11-24 15:50:16 +01:00

impr: Make sure detached windows always have an appropriate size

This commit is contained in:
WerWolv 2024-01-03 18:26:25 +01:00
parent 62093a8dd8
commit ed8934882e
2 changed files with 13 additions and 2 deletions

View File

@ -17,6 +17,8 @@ namespace hex::plugin::builtin {
private:
std::vector<ContentRegistry::Tools::impl::Entry>::iterator m_dragStartIterator;
std::map<ImGuiWindow*, float> m_windowHeights;
};
}

View File

@ -56,9 +56,15 @@ namespace hex::plugin::builtin {
// If the tool is still attached to the main window, don't draw it here
if (!detached) continue;
// Load the window height that is dependent on the tool content
const auto windowName = View::toWindowName(name);
const auto height = m_windowHeights[ImGui::FindWindowByName(windowName.c_str())];
if (height > 0)
ImGui::SetNextWindowSizeConstraints(ImVec2(400_scaled, height), ImVec2(FLT_MAX, height));
// Create a new window for the tool
if (ImGui::Begin(View::toWindowName(name).c_str(), &detached, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize)) {
// Draw the tool
if (ImGui::Begin(windowName.c_str(), &detached, ImGuiWindowFlags_NoCollapse)) {
// Draw the tool content
function();
// Handle the first frame after the tool has been detached
@ -69,6 +75,9 @@ namespace hex::plugin::builtin {
GImGui->MovingWindow = ImGui::GetCurrentWindowRead();
GImGui->ActiveId = GImGui->MovingWindow->MoveId;
}
const auto window = ImGui::GetCurrentWindowRead();
m_windowHeights[ImGui::GetCurrentWindowRead()] = ImGui::CalcWindowNextAutoFitSize(window).y;
}
ImGui::End();
}