@@ -685,7 +685,7 @@ static void BeginLayout(ImGuiID id, ImGuiLayoutType type, ImVec2 siz
685
685
static void EndLayout (ImGuiLayoutType type);
686
686
static void PushLayout (ImGuiLayout* layout);
687
687
static void PopLayout (ImGuiLayout* layout);
688
- static void ReflowLayouts ( );
688
+ static void ProcessLayouts (ImGuiWindow* window );
689
689
static void CalculateLayoutAvailableSpace (ImGuiLayout* layout);
690
690
static void PropagateLayoutSpace (ImGuiLayout* layout, const ImVec2& extents);
691
691
static void DistributeAvailableLayoutSpace (ImGuiLayout* layout);
@@ -1792,6 +1792,13 @@ ImGuiWindow::ImGuiWindow(const char* name)
1792
1792
1793
1793
ImGuiWindow::~ImGuiWindow ()
1794
1794
{
1795
+ for (int i = 0 ; i < DC.Layouts .Data .Size ; ++i)
1796
+ {
1797
+ ImGuiLayout* layout = (ImGuiLayout*)DC.Layouts .Data [i].val_p ;
1798
+ layout->~ImGuiLayout ();
1799
+ ImGui::MemFree (layout);
1800
+ }
1801
+
1795
1802
DrawList->~ImDrawList ();
1796
1803
ImGui::MemFree (DrawList);
1797
1804
DrawList = NULL ;
@@ -1878,7 +1885,7 @@ void ImGui::ItemSize(const ImVec2& size, float text_offset_y)
1878
1885
const float text_base_offset = ImMax (window->DC .CurrentLineTextBaseOffset , text_offset_y);
1879
1886
window->DC .CursorPosPrevLine = ImVec2 (window->DC .CursorPos .x + size.x , window->DC .CursorPos .y );
1880
1887
1881
- if (!g .CurrentLayout || g .CurrentLayout ->Type == ImGuiLayoutType_Vertical)
1888
+ if (!window-> DC .CurrentLayout || window-> DC .CurrentLayout ->Type == ImGuiLayoutType_Vertical)
1882
1889
{
1883
1890
// Move cursor to next line, x to left, y down.
1884
1891
window->DC .CursorPos = ImVec2 (
@@ -2370,12 +2377,6 @@ void ImGui::Shutdown()
2370
2377
2371
2378
SaveSettings ();
2372
2379
2373
- for (int i = 0 ; i < g.Layouts .Size ; ++i)
2374
- {
2375
- g.Layouts [i]->~ImGuiLayout ();
2376
- ImGui::MemFree (g.Layouts [i]);
2377
- }
2378
-
2379
2380
for (int i = 0 ; i < g.Windows .Size ; i++)
2380
2381
{
2381
2382
g.Windows [i]->~ImGuiWindow ();
@@ -2644,8 +2645,6 @@ void ImGui::EndFrame()
2644
2645
IM_ASSERT (g.Initialized ); // Forgot to call ImGui::NewFrame()
2645
2646
IM_ASSERT (g.FrameCountEnded != g.FrameCount ); // ImGui::EndFrame() called multiple times, or forgot to call ImGui::NewFrame() again
2646
2647
2647
- ReflowLayouts ();
2648
-
2649
2648
// Render tooltip
2650
2649
if (g.Tooltip [0 ])
2651
2650
{
@@ -3724,14 +3723,14 @@ static void CheckStacksSize(ImGuiWindow* window, bool write)
3724
3723
{ int current = g.StyleModifiers .Size ; if (write) *p_backup = current; else IM_ASSERT (*p_backup == current && " PushStyleVar/PopStyleVar Mismatch!" ); p_backup++; } // User forgot PopStyleVar()
3725
3724
{ int current = g.FontStack .Size ; if (write) *p_backup = current; else IM_ASSERT (*p_backup == current && " PushFont/PopFont Mismatch!" ); p_backup++; } // User forgot PopFont()
3726
3725
{ // User forgot EndVertical() or EndHorizontal()
3727
- int current = g .LayoutStack .Size ;
3726
+ int current = window-> DC .LayoutStack .Size ;
3728
3727
if (write)
3729
3728
{
3730
3729
*p_backup = current;
3731
3730
}
3732
- else if (!g .LayoutStack .empty () && g .LayoutStack .back ())
3731
+ else if (!window-> DC .LayoutStack .empty () && window-> DC .LayoutStack .back ())
3733
3732
{
3734
- if (current == 0 || g .LayoutStack .back ()->Type == ImGuiLayoutType_Horizontal)
3733
+ if (current == 0 || window-> DC .LayoutStack .back ()->Type == ImGuiLayoutType_Horizontal)
3735
3734
IM_ASSERT (*p_backup == current && " BeginHorizontal/EndHorizontal Mismatch!" );
3736
3735
else
3737
3736
IM_ASSERT (*p_backup == current && " BeginVertical/EndVertical Mismatch!" );
@@ -4448,6 +4447,8 @@ void ImGui::End()
4448
4447
Columns (1 , " #CloseColumns" );
4449
4448
PopClipRect (); // inner window clip rectangle
4450
4449
4450
+ ProcessLayouts (window);
4451
+
4451
4452
// Stop logging
4452
4453
if (!(window->Flags & ImGuiWindowFlags_ChildWindow)) // FIXME: add more options for scope of logging
4453
4454
LogFinish ();
@@ -9310,39 +9311,33 @@ static ImGuiLayout* FindLayout(ImGuiID id, ImGuiLayoutType type)
9310
9311
{
9311
9312
IM_ASSERT (type == ImGuiLayoutType_Horizontal || type == ImGuiLayoutType_Vertical);
9312
9313
9313
- ImGuiContext& g = *GImGui;
9314
+ ImGuiWindow* window = ImGui::GetCurrentWindow ();
9315
+ ImGuiLayout* layout = (ImGuiLayout*)window->DC .Layouts .GetVoidPtr (id);
9316
+ if (!layout)
9317
+ return NULL ;
9314
9318
9315
- for ( int i = 0 ; i != g. Layouts . Size ; i++ )
9319
+ if (layout-> Type != type )
9316
9320
{
9317
- ImGuiLayout* layout = g.Layouts [i];
9318
- if (layout->Id == id)
9319
- {
9320
- if (layout->Type != type)
9321
- {
9322
- layout->Type = type;
9323
- layout->Dirty = ImGuiLayoutDirtyFlags_Uninitialized;
9324
- layout->Bounds = ImVec2 (0 .0f , 0 .0f );
9325
- layout->Items .clear ();
9326
- }
9327
-
9328
- return layout;
9329
- }
9321
+ layout->Type = type;
9322
+ layout->Dirty = ImGuiLayoutDirtyFlags_Uninitialized;
9323
+ layout->Bounds = ImVec2 (0 .0f , 0 .0f );
9324
+ layout->Items .clear ();
9330
9325
}
9331
9326
9332
- return NULL ;
9327
+ return layout ;
9333
9328
}
9334
9329
9335
9330
static ImGuiLayout* CreateNewLayout (ImGuiID id, ImGuiLayoutType type, ImVec2 size)
9336
9331
{
9337
9332
IM_ASSERT (type == ImGuiLayoutType_Horizontal || type == ImGuiLayoutType_Vertical);
9338
9333
9339
- ImGuiContext& g = *GImGui ;
9334
+ ImGuiWindow* window = ImGui::GetCurrentWindow () ;
9340
9335
9341
9336
ImGuiLayout* layout = (ImGuiLayout*)ImGui::MemAlloc (sizeof (ImGuiLayout));
9342
9337
IM_PLACEMENT_NEW (layout) ImGuiLayout (id, type);
9343
9338
layout->Size = size;
9344
9339
9345
- g .Layouts .push_back ( layout);
9340
+ window-> DC .Layouts .SetVoidPtr (id, layout);
9346
9341
9347
9342
return layout;
9348
9343
}
@@ -9383,11 +9378,11 @@ static void BeginLayout(ImGuiID id, ImGuiLayoutType type, ImVec2 size, float ali
9383
9378
9384
9379
static void EndLayout (ImGuiLayoutType type)
9385
9380
{
9386
- ImGuiContext& g = *GImGui ;
9387
- IM_ASSERT (g .CurrentLayout );
9388
- IM_ASSERT (g .CurrentLayout ->Type == type);
9381
+ ImGuiWindow* window = ImGui::GetCurrentWindow () ;
9382
+ IM_ASSERT (window-> DC .CurrentLayout );
9383
+ IM_ASSERT (window-> DC .CurrentLayout ->Type == type);
9389
9384
9390
- ImGuiLayout* layout = g .CurrentLayout ;
9385
+ ImGuiLayout* layout = window-> DC .CurrentLayout ;
9391
9386
9392
9387
EndLayoutItem (layout, true );
9393
9388
@@ -9494,16 +9489,16 @@ static ImVec2 CalculateMinimumLayoutSize(ImGuiLayout* layout)
9494
9489
9495
9490
static void PushLayout (ImGuiLayout* layout)
9496
9491
{
9497
- ImGuiContext& g = *GImGui ;
9492
+ ImGuiWindow* window = ImGui::GetCurrentWindow () ;
9498
9493
9499
9494
if (layout)
9500
9495
{
9501
- layout->Parent = g .CurrentLayout ;
9502
- if (g .CurrentLayout )
9496
+ layout->Parent = window-> DC .CurrentLayout ;
9497
+ if (window-> DC .CurrentLayout )
9503
9498
{
9504
- layout->NextSibling = g .CurrentLayout ->FirstChild ;
9499
+ layout->NextSibling = window-> DC .CurrentLayout ->FirstChild ;
9505
9500
layout->FirstChild = NULL ;
9506
- g .CurrentLayout ->FirstChild = layout;
9501
+ window-> DC .CurrentLayout ->FirstChild = layout;
9507
9502
}
9508
9503
else
9509
9504
{
@@ -9512,23 +9507,23 @@ static void PushLayout(ImGuiLayout* layout)
9512
9507
}
9513
9508
}
9514
9509
9515
- g .LayoutStack .push_back (layout);
9516
- g .CurrentLayout = layout;
9510
+ window-> DC .LayoutStack .push_back (layout);
9511
+ window-> DC .CurrentLayout = layout;
9517
9512
}
9518
9513
9519
9514
static void PopLayout (ImGuiLayout* layout)
9520
9515
{
9521
- ImGuiContext& g = *GImGui ;
9516
+ ImGuiWindow* window = ImGui::GetCurrentWindow () ;
9522
9517
9523
- IM_ASSERT (!g .LayoutStack .empty ());
9524
- IM_ASSERT (g .LayoutStack .back () == layout);
9518
+ IM_ASSERT (!window-> DC .LayoutStack .empty ());
9519
+ IM_ASSERT (window-> DC .LayoutStack .back () == layout);
9525
9520
9526
- g .LayoutStack .pop_back ();
9521
+ window-> DC .LayoutStack .pop_back ();
9527
9522
9528
- if (!g .LayoutStack .empty ())
9529
- g .CurrentLayout = g .LayoutStack .back ();
9523
+ if (!window-> DC .LayoutStack .empty ())
9524
+ window-> DC .CurrentLayout = window-> DC .LayoutStack .back ();
9530
9525
else
9531
- g .CurrentLayout = NULL ;
9526
+ window-> DC .CurrentLayout = NULL ;
9532
9527
}
9533
9528
9534
9529
static void PropagateLayoutSpace (ImGuiLayout* layout, const ImVec2& extents)
@@ -9642,13 +9637,11 @@ static void DistributeAvailableLayoutSpace(ImGuiLayout* layout)
9642
9637
layout->Dirty = ImGuiLayoutDirtyFlags_None;
9643
9638
}
9644
9639
9645
- static void ReflowLayouts ( )
9640
+ static void ProcessLayouts (ImGuiWindow* window )
9646
9641
{
9647
- ImGuiContext& g = *GImGui;
9648
-
9649
- for (int i = 0 ; i < g.Layouts .size (); ++i)
9642
+ for (int i = 0 ; i < window->DC .Layouts .Data .size (); ++i)
9650
9643
{
9651
- ImGuiLayout* layout = g .Layouts [i];
9644
+ ImGuiLayout* layout = (ImGuiLayout*)window-> DC .Layouts . Data [i]. val_p ;
9652
9645
if (!layout->Parent && layout->Dirty )
9653
9646
{
9654
9647
CalculateLayoutAvailableSpace (layout);
@@ -9891,23 +9884,22 @@ void ImGui::EndVertical()
9891
9884
// spacing >= 0 : enforce spacing amount
9892
9885
void ImGui::Spring (float weight/* = 1.0f*/ , float spacing/* = -1.0f*/ )
9893
9886
{
9894
- ImGuiContext& g = *GImGui ;
9895
- IM_ASSERT (g .CurrentLayout );
9887
+ ImGuiWindow* window = GetCurrentWindow () ;
9888
+ IM_ASSERT (window-> DC .CurrentLayout );
9896
9889
9897
- AddLayoutSpring (g .CurrentLayout , weight, spacing);
9890
+ AddLayoutSpring (window-> DC .CurrentLayout , weight, spacing);
9898
9891
}
9899
9892
9900
9893
void ImGui::SuspendLayout ()
9901
9894
{
9902
- ImGuiContext& g = *GImGui;
9903
9895
PushLayout (NULL );
9904
9896
}
9905
9897
9906
9898
void ImGui::ResumeLayout ()
9907
9899
{
9908
- ImGuiContext& g = *GImGui ;
9909
- IM_ASSERT (!g .CurrentLayout );
9910
- IM_ASSERT (!g .LayoutStack .empty ());
9900
+ ImGuiWindow* window = GetCurrentWindow () ;
9901
+ IM_ASSERT (!window-> DC .CurrentLayout );
9902
+ IM_ASSERT (!window-> DC .LayoutStack .empty ());
9911
9903
PopLayout (NULL );
9912
9904
}
9913
9905
0 commit comments