@@ -1794,7 +1794,8 @@ ImGuiWindow::ImGuiWindow(const char* name)
17941794 AutoPosLastDirection = -1 ;
17951795 HiddenFrames = 0 ;
17961796 SetWindowPosAllowFlags = SetWindowSizeAllowFlags = SetWindowCollapsedAllowFlags = ImGuiSetCond_Always | ImGuiSetCond_Once | ImGuiSetCond_FirstUseEver | ImGuiSetCond_Appearing;
1797- SetWindowPosCenterWanted = false ;
1797+ SetWindowPosXAxisCenterWanted = false ;
1798+ SetWindowPosYAxisCenterWanted = false ;
17981799
17991800 LastFrameActive = -1 ;
18001801 ItemWidthDefault = 0 .0f ;
@@ -3931,10 +3932,11 @@ bool ImGui::Begin(const char* name, bool* p_open, const ImVec2& size_on_first_us
39313932 const ImVec2 backup_cursor_pos = window->DC .CursorPos ; // FIXME: not sure of the exact reason of this saving/restore anymore :( need to look into that.
39323933 if (!window_was_active || window_appearing_after_being_hidden) window->SetWindowPosAllowFlags |= ImGuiSetCond_Appearing;
39333934 window_pos_set_by_api = (window->SetWindowPosAllowFlags & g.SetNextWindowPosCond ) != 0 ;
3934- if (window_pos_set_by_api && ImLengthSqr ( g.SetNextWindowPosVal - ImVec2 ( -FLT_MAX,-FLT_MAX)) < 0 . 001f )
3935+ if (window_pos_set_by_api && (( g.SetNextWindowPosVal . x == -FLT_MAX) || (g. SetNextWindowPosVal . y == -FLT_MAX)) )
39353936 {
3936- window->SetWindowPosCenterWanted = true ; // May be processed on the next frame if this is our first frame and we are measuring size
39373937 window->SetWindowPosAllowFlags &= ~(ImGuiSetCond_Once | ImGuiSetCond_FirstUseEver | ImGuiSetCond_Appearing);
3938+ if (g.SetNextWindowPosVal .x == -FLT_MAX) window->SetWindowPosXAxisCenterWanted = true ;
3939+ if (g.SetNextWindowPosVal .y == -FLT_MAX) window->SetWindowPosYAxisCenterWanted = true ;
39383940 }
39393941 else
39403942 {
@@ -4117,12 +4119,15 @@ bool ImGui::Begin(const char* name, bool* p_open, const ImVec2& size_on_first_us
41174119 }
41184120
41194121 bool window_pos_center = false ;
4120- window_pos_center |= (window->SetWindowPosCenterWanted && window->HiddenFrames == 0 );
4122+ window_pos_center |= (( window->SetWindowPosXAxisCenterWanted | window-> SetWindowPosYAxisCenterWanted ) && window->HiddenFrames == 0 );
41214123 window_pos_center |= ((flags & ImGuiWindowFlags_Modal) && !window_pos_set_by_api && window_appearing_after_being_hidden);
41224124 if (window_pos_center)
41234125 {
41244126 // Center (any sort of window)
4125- SetWindowPos (window, ImMax (style.DisplaySafeAreaPadding , fullscreen_rect.GetCenter () - window->SizeFull * 0 .5f ), 0 );
4127+ ImVec2 centerv = fullscreen_rect.GetCenter () - window->SizeFull * 0 .5f ;
4128+ if (!window->SetWindowPosXAxisCenterWanted ) centerv.x = g.SetNextWindowPosVal .x ;
4129+ if (!window->SetWindowPosYAxisCenterWanted ) centerv.y = g.SetNextWindowPosVal .y ;
4130+ SetWindowPos (window, ImMax (style.DisplaySafeAreaPadding , centerv), 0 );
41264131 }
41274132 else if (flags & ImGuiWindowFlags_ChildMenu)
41284133 {
@@ -4919,7 +4924,8 @@ static void SetWindowPos(ImGuiWindow* window, const ImVec2& pos, ImGuiSetCond co
49194924 if (cond && (window->SetWindowPosAllowFlags & cond) == 0 )
49204925 return ;
49214926 window->SetWindowPosAllowFlags &= ~(ImGuiSetCond_Once | ImGuiSetCond_FirstUseEver | ImGuiSetCond_Appearing);
4922- window->SetWindowPosCenterWanted = false ;
4927+ window->SetWindowPosXAxisCenterWanted = false ;
4928+ window->SetWindowPosYAxisCenterWanted = false ;
49234929
49244930 // Set
49254931 const ImVec2 old_pos = window->Pos ;
0 commit comments