Skip to content

Commit 13258f5

Browse files
committed
Internals: zero-clearing ImGuiWindow / ImGuiWindowTempData for simplicity. (amend)
All the non-zero fields previously initialized in ImGuiWindowTempData() are in fact setup in Begin: FocusCounterRegular, FocusCounterTabStop, TextWrapPos, LayoutType, ParentLayoutType
1 parent 7a135a7 commit 13258f5

File tree

2 files changed

+6
-82
lines changed

2 files changed

+6
-82
lines changed

imgui.cpp

Lines changed: 4 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2774,70 +2774,27 @@ void ImGui::RenderNavHighlight(const ImRect& bb, ImGuiID id, ImGuiNavHighlightFl
27742774
//-----------------------------------------------------------------------------
27752775

27762776
// ImGuiWindow is mostly a dumb struct. It merely has a constructor and a few helper methods
2777-
ImGuiWindow::ImGuiWindow(ImGuiContext* context, const char* name)
2778-
: DrawListInst(&context->DrawListSharedData)
2777+
ImGuiWindow::ImGuiWindow(ImGuiContext* context, const char* name) : DrawListInst(NULL)
27792778
{
2779+
memset(this, 0, sizeof(*this));
27802780
Name = ImStrdup(name);
2781+
NameBufLen = (int)strlen(name) + 1;
27812782
ID = ImHashStr(name);
27822783
IDStack.push_back(ID);
2783-
Flags = ImGuiWindowFlags_None;
2784-
Pos = ImVec2(0.0f, 0.0f);
2785-
Size = SizeFull = ImVec2(0.0f, 0.0f);
2786-
ContentSize = ContentSizeExplicit = ImVec2(0.0f, 0.0f);
2787-
WindowPadding = ImVec2(0.0f, 0.0f);
2788-
WindowRounding = 0.0f;
2789-
WindowBorderSize = 0.0f;
2790-
NameBufLen = (int)strlen(name) + 1;
27912784
MoveId = GetID("#MOVE");
2792-
ChildId = 0;
2793-
Scroll = ImVec2(0.0f, 0.0f);
27942785
ScrollTarget = ImVec2(FLT_MAX, FLT_MAX);
27952786
ScrollTargetCenterRatio = ImVec2(0.5f, 0.5f);
2796-
ScrollbarSizes = ImVec2(0.0f, 0.0f);
2797-
ScrollbarX = ScrollbarY = false;
2798-
Active = WasActive = false;
2799-
WriteAccessed = false;
2800-
Collapsed = false;
2801-
WantCollapseToggle = false;
2802-
SkipItems = false;
2803-
Appearing = false;
2804-
Hidden = false;
2805-
IsFallbackWindow = false;
2806-
HasCloseButton = false;
2807-
ResizeBorderHeld = -1;
2808-
BeginCount = 0;
2809-
BeginOrderWithinParent = -1;
2810-
BeginOrderWithinContext = -1;
2811-
PopupId = 0;
28122787
AutoFitFramesX = AutoFitFramesY = -1;
2813-
AutoFitChildAxises = 0x00;
2814-
AutoFitOnlyGrows = false;
28152788
AutoPosLastDirection = ImGuiDir_None;
2816-
HiddenFramesCanSkipItems = HiddenFramesCannotSkipItems = 0;
28172789
SetWindowPosAllowFlags = SetWindowSizeAllowFlags = SetWindowCollapsedAllowFlags = ImGuiCond_Always | ImGuiCond_Once | ImGuiCond_FirstUseEver | ImGuiCond_Appearing;
28182790
SetWindowPosVal = SetWindowPosPivot = ImVec2(FLT_MAX, FLT_MAX);
2819-
2820-
InnerRect = ImRect(0.0f, 0.0f, 0.0f, 0.0f); // Clear so the InnerRect.GetSize() code in Begin() doesn't lead to overflow even if the result isn't used.
2821-
28222791
LastFrameActive = -1;
28232792
LastTimeActive = -1.0f;
2824-
ItemWidthDefault = 0.0f;
28252793
FontWindowScale = 1.0f;
28262794
SettingsOffset = -1;
2827-
28282795
DrawList = &DrawListInst;
2796+
DrawList->_Data = &context->DrawListSharedData;
28292797
DrawList->_OwnerName = Name;
2830-
ParentWindow = NULL;
2831-
RootWindow = NULL;
2832-
RootWindowForTitleBarHighlight = NULL;
2833-
RootWindowForNav = NULL;
2834-
2835-
NavLastIds[0] = NavLastIds[1] = 0;
2836-
NavRectRel[0] = NavRectRel[1] = ImRect();
2837-
NavLastChildNavWindow = NULL;
2838-
2839-
MemoryCompacted = false;
2840-
MemoryDrawListIdxCapacity = MemoryDrawListVtxCapacity = 0;
28412798
}
28422799

28432800
ImGuiWindow::~ImGuiWindow()

imgui_internal.h

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,7 +1503,8 @@ struct ImGuiContext
15031503
//-----------------------------------------------------------------------------
15041504

15051505
// Transient per-window data, reset at the beginning of the frame. This used to be called ImGuiDrawContext, hence the DC variable name in ImGuiWindow.
1506-
// FIXME: That's theory, in practice the delimitation between ImGuiWindow and ImGuiWindowTempData is quite tenuous and could be reconsidered.
1506+
// (That's theory, in practice the delimitation between ImGuiWindow and ImGuiWindowTempData is quite tenuous and could be reconsidered..)
1507+
// (This doesn't need a constructor because we zero-clear it as part of ImGuiWindow and all frame-temporary data are setup on Begin)
15071508
struct IMGUI_API ImGuiWindowTempData
15081509
{
15091510
// Layout
@@ -1557,40 +1558,6 @@ struct IMGUI_API ImGuiWindowTempData
15571558
ImVector<float> TextWrapPosStack;
15581559
ImVector<ImGuiGroupData>GroupStack;
15591560
short StackSizesBackup[6]; // Store size of various stacks for asserting
1560-
1561-
ImGuiWindowTempData()
1562-
{
1563-
CursorPos = CursorPosPrevLine = CursorStartPos = CursorMaxPos = ImVec2(0.0f, 0.0f);
1564-
CurrLineSize = PrevLineSize = ImVec2(0.0f, 0.0f);
1565-
CurrLineTextBaseOffset = PrevLineTextBaseOffset = 0.0f;
1566-
Indent = ImVec1(0.0f);
1567-
ColumnsOffset = ImVec1(0.0f);
1568-
GroupOffset = ImVec1(0.0f);
1569-
1570-
LastItemId = 0;
1571-
LastItemStatusFlags = ImGuiItemStatusFlags_None;
1572-
LastItemRect = LastItemDisplayRect = ImRect();
1573-
1574-
NavLayerActiveMask = NavLayerActiveMaskNext = 0x00;
1575-
NavLayerCurrent = ImGuiNavLayer_Main;
1576-
NavFocusScopeIdCurrent = 0;
1577-
NavHideHighlightOneFrame = false;
1578-
NavHasScroll = false;
1579-
1580-
MenuBarAppending = false;
1581-
MenuBarOffset = ImVec2(0.0f, 0.0f);
1582-
TreeDepth = 0;
1583-
TreeJumpToParentOnPopMask = 0x00;
1584-
StateStorage = NULL;
1585-
CurrentColumns = NULL;
1586-
LayoutType = ParentLayoutType = ImGuiLayoutType_Vertical;
1587-
FocusCounterRegular = FocusCounterTabStop = -1;
1588-
1589-
ItemFlags = ImGuiItemFlags_Default_;
1590-
ItemWidth = 0.0f;
1591-
TextWrapPos = -1.0f;
1592-
memset(StackSizesBackup, 0, sizeof(StackSizesBackup));
1593-
}
15941561
};
15951562

15961563
// Storage for one window

0 commit comments

Comments
 (0)