mirror of https://github.com/WerWolv/ImHex.git
fix: Popup positioning being wrong
This commit is contained in:
parent
09f1b56964
commit
af4dd9f5b0
|
@ -529,10 +529,14 @@ namespace hex {
|
||||||
{
|
{
|
||||||
std::scoped_lock lock(impl::PopupBase::getMutex());
|
std::scoped_lock lock(impl::PopupBase::getMutex());
|
||||||
if (auto &popups = impl::PopupBase::getOpenPopups(); !popups.empty()) {
|
if (auto &popups = impl::PopupBase::getOpenPopups(); !popups.empty()) {
|
||||||
|
static bool popupDisplaying = false;
|
||||||
|
static bool sizeSet = false;
|
||||||
|
static ImVec2 popupSize;
|
||||||
|
|
||||||
auto &currPopup = popups.back();
|
auto &currPopup = popups.back();
|
||||||
const auto &name = LangEntry(currPopup->getUnlocalizedName());
|
const auto &name = LangEntry(currPopup->getUnlocalizedName());
|
||||||
|
|
||||||
if (!ImGui::IsPopupOpen(ImGuiID(0), ImGuiPopupFlags_AnyPopupId))
|
if (!ImGui::IsPopupOpen(ImGuiID(0), ImGuiPopupFlags_AnyPopupId) && !popupDisplaying)
|
||||||
ImGui::OpenPopup(name);
|
ImGui::OpenPopup(name);
|
||||||
|
|
||||||
bool open = true;
|
bool open = true;
|
||||||
|
@ -541,28 +545,42 @@ namespace hex {
|
||||||
const auto closeButton = currPopup->hasCloseButton() ? &open : nullptr;
|
const auto closeButton = currPopup->hasCloseButton() ? &open : nullptr;
|
||||||
const auto flags = currPopup->getFlags();
|
const auto flags = currPopup->getFlags();
|
||||||
|
|
||||||
const auto windowSize = ImHexApi::System::getMainWindowSize();
|
auto emptyWindowSize = ImGui::GetStyle().FramePadding * 4;
|
||||||
|
if (!sizeSet && popupSize.x > emptyWindowSize.x && popupSize.y > emptyWindowSize.y && popupSize.y < ImGui::GetMainViewport()->Size.y) {
|
||||||
|
ImGui::SetNextWindowSize(popupSize, ImGuiCond_FirstUseEver);
|
||||||
|
ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(), ImGuiCond_FirstUseEver, ImVec2(0.5F, 0.5F));
|
||||||
|
sizeSet = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (currPopup->isModal()) {
|
if (currPopup->isModal()) {
|
||||||
if (ImGui::BeginPopupModal(name, closeButton, flags)) {
|
if (ImGui::BeginPopupModal(name, closeButton, flags)) {
|
||||||
ImGui::SetWindowPos((windowSize - ImGui::GetWindowSize()) / 2, ImGuiCond_Appearing);
|
|
||||||
|
|
||||||
currPopup->drawContent();
|
currPopup->drawContent();
|
||||||
|
popupDisplaying = true;
|
||||||
|
popupSize = ImGui::GetWindowSize();
|
||||||
|
|
||||||
ImGui::EndPopup();
|
ImGui::EndPopup();
|
||||||
|
} else {
|
||||||
|
popupDisplaying = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (ImGui::BeginPopup(name, flags)) {
|
if (ImGui::BeginPopup(name, flags)) {
|
||||||
ImGui::SetWindowPos((windowSize - ImGui::GetWindowSize()) / 2, ImGuiCond_Appearing);
|
|
||||||
|
|
||||||
currPopup->drawContent();
|
currPopup->drawContent();
|
||||||
|
popupDisplaying = true;
|
||||||
|
popupSize = ImGui::GetWindowSize();
|
||||||
|
|
||||||
ImGui::EndPopup();
|
ImGui::EndPopup();
|
||||||
|
} else {
|
||||||
|
popupDisplaying = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!open)
|
if (!open || !popupDisplaying) {
|
||||||
|
sizeSet = false;
|
||||||
|
popupDisplaying = false;
|
||||||
popups.pop_back();
|
popups.pop_back();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue