Skip to content

Commit b83a1f3

Browse files
committed
BeginPopupModal() doesn't set the ImGuiWindowFlags_NoSavedSettings flag anymore, and will not always be auto-centered. (ocornut#915, ocornut#3091)
1 parent 6838920 commit b83a1f3

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

docs/CHANGELOG.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ Other Changes:
5858
would attempt to focus it and close other popups. (#2880)
5959
- Popups: Fix BeginPopupContextVoid() when clicking over the area made unavailable by a modal. (#1636)
6060
- Popups: Clarified some of the comments and function prototypes.
61+
- Modals: BeginPopupModal() doesn't set the ImGuiWindowFlags_NoSavedSettings flag anymore, and will
62+
not always be auto-centered. Note that modals are more similar to regular windows than they are to
63+
popups, so api and behavior may evolve further toward embracing this. (#915, #3091)
64+
Enforce centering using e.g. SetNextWindowPos(io.DisplaySize * 0.5f, ImGuiCond_Appearing, ImVec2(0.5f,0.5f)).
6165
- Metrics: Added a "Settings" section with some details about persistent ini settings.
6266
- Nav, Menus: Fix vertical wrap-around in menus or popups created with multiple appending calls to
6367
BeginMenu()/EndMenu() or BeginPopup/EndPopup(). (#3223, #1207) [@rokups]

imgui.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5748,7 +5748,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
57485748
if (window_just_activated_by_user)
57495749
{
57505750
window->AutoPosLastDirection = ImGuiDir_None;
5751-
if ((flags & ImGuiWindowFlags_Popup) != 0 && !window_pos_set_by_api)
5751+
if ((flags & ImGuiWindowFlags_Popup) != 0 && !(flags & ImGuiWindowFlags_Modal) && !window_pos_set_by_api) // FIXME: BeginPopup() could use SetNextWindowPos()
57525752
window->Pos = g.BeginPopupStack.back().OpenPopupPos;
57535753
}
57545754

@@ -7807,6 +7807,7 @@ void ImGui::CloseCurrentPopup()
78077807
window->DC.NavHideHighlightOneFrame = true;
78087808
}
78097809

7810+
// Attention! BeginPopup() adds default flags which BeginPopupEx()!
78107811
bool ImGui::BeginPopupEx(ImGuiID id, ImGuiWindowFlags flags)
78117812
{
78127813
ImGuiContext& g = *GImGui;
@@ -7855,12 +7856,13 @@ bool ImGui::BeginPopupModal(const char* name, bool* p_open, ImGuiWindowFlags fla
78557856
return false;
78567857
}
78577858

7858-
// Center modal windows by default
7859+
// Center modal windows by default for increased visibility
7860+
// (this won't really last as settings will kick in, and is mostly for backward compatibility. user may do the same themselves)
78597861
// FIXME: Should test for (PosCond & window->SetWindowPosAllowFlags) with the upcoming window.
78607862
if ((g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasPos) == 0)
7861-
SetNextWindowPos(g.IO.DisplaySize * 0.5f, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
7863+
SetNextWindowPos(g.IO.DisplaySize * 0.5f, ImGuiCond_FirstUseEver, ImVec2(0.5f, 0.5f));
78627864

7863-
flags |= ImGuiWindowFlags_Popup | ImGuiWindowFlags_Modal | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoSavedSettings;
7865+
flags |= ImGuiWindowFlags_Popup | ImGuiWindowFlags_Modal | ImGuiWindowFlags_NoCollapse;
78647866
const bool is_open = Begin(name, p_open, flags);
78657867
if (!is_open || (p_open && !*p_open)) // NB: is_open can be 'false' when the popup is completely clipped (e.g. zero size display)
78667868
{

imgui_demo.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2865,6 +2865,10 @@ static void ShowDemoWindowPopups()
28652865
if (ImGui::Button("Delete.."))
28662866
ImGui::OpenPopup("Delete?");
28672867

2868+
// Always center this window when appearing
2869+
ImVec2 center(ImGui::GetIO().DisplaySize.x * 0.5f, ImGui::GetIO().DisplaySize.y * 0.5f);
2870+
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
2871+
28682872
if (ImGui::BeginPopupModal("Delete?", NULL, ImGuiWindowFlags_AlwaysAutoResize))
28692873
{
28702874
ImGui::Text("All those beautiful files will be deleted.\nThis operation cannot be undone!\n\n");

0 commit comments

Comments
 (0)