Skip to content

Commit

Permalink
Internals: zero-clearing ImGuiWindow / ImGuiWindowTempData for simpli…
Browse files Browse the repository at this point in the history
…city. (amend)

All the non-zero fields previously initialized in ImGuiWindowTempData() are in fact setup in Begin: FocusCounterRegular, FocusCounterTabStop, TextWrapPos, LayoutType, ParentLayoutType
  • Loading branch information
ocornut committed Nov 12, 2020
1 parent 7a135a7 commit 09caf50
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 81 deletions.
51 changes: 4 additions & 47 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2774,70 +2774,27 @@ void ImGui::RenderNavHighlight(const ImRect& bb, ImGuiID id, ImGuiNavHighlightFl
//-----------------------------------------------------------------------------

// ImGuiWindow is mostly a dumb struct. It merely has a constructor and a few helper methods
ImGuiWindow::ImGuiWindow(ImGuiContext* context, const char* name)
: DrawListInst(&context->DrawListSharedData)
ImGuiWindow::ImGuiWindow(ImGuiContext* context, const char* name) : DrawListInst(NULL)
{
memset(this, 0, sizeof(*this));
Name = ImStrdup(name);
NameBufLen = (int)strlen(name) + 1;
ID = ImHashStr(name);
IDStack.push_back(ID);
Flags = ImGuiWindowFlags_None;
Pos = ImVec2(0.0f, 0.0f);
Size = SizeFull = ImVec2(0.0f, 0.0f);
ContentSize = ContentSizeExplicit = ImVec2(0.0f, 0.0f);
WindowPadding = ImVec2(0.0f, 0.0f);
WindowRounding = 0.0f;
WindowBorderSize = 0.0f;
NameBufLen = (int)strlen(name) + 1;
MoveId = GetID("#MOVE");
ChildId = 0;
Scroll = ImVec2(0.0f, 0.0f);
ScrollTarget = ImVec2(FLT_MAX, FLT_MAX);
ScrollTargetCenterRatio = ImVec2(0.5f, 0.5f);
ScrollbarSizes = ImVec2(0.0f, 0.0f);
ScrollbarX = ScrollbarY = false;
Active = WasActive = false;
WriteAccessed = false;
Collapsed = false;
WantCollapseToggle = false;
SkipItems = false;
Appearing = false;
Hidden = false;
IsFallbackWindow = false;
HasCloseButton = false;
ResizeBorderHeld = -1;
BeginCount = 0;
BeginOrderWithinParent = -1;
BeginOrderWithinContext = -1;
PopupId = 0;
AutoFitFramesX = AutoFitFramesY = -1;
AutoFitChildAxises = 0x00;
AutoFitOnlyGrows = false;
AutoPosLastDirection = ImGuiDir_None;
HiddenFramesCanSkipItems = HiddenFramesCannotSkipItems = 0;
SetWindowPosAllowFlags = SetWindowSizeAllowFlags = SetWindowCollapsedAllowFlags = ImGuiCond_Always | ImGuiCond_Once | ImGuiCond_FirstUseEver | ImGuiCond_Appearing;
SetWindowPosVal = SetWindowPosPivot = ImVec2(FLT_MAX, FLT_MAX);

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.

LastFrameActive = -1;
LastTimeActive = -1.0f;
ItemWidthDefault = 0.0f;
FontWindowScale = 1.0f;
SettingsOffset = -1;

DrawList = &DrawListInst;
DrawList->_Data = &context->DrawListSharedData;
DrawList->_OwnerName = Name;
ParentWindow = NULL;
RootWindow = NULL;
RootWindowForTitleBarHighlight = NULL;
RootWindowForNav = NULL;

NavLastIds[0] = NavLastIds[1] = 0;
NavRectRel[0] = NavRectRel[1] = ImRect();
NavLastChildNavWindow = NULL;

MemoryCompacted = false;
MemoryDrawListIdxCapacity = MemoryDrawListVtxCapacity = 0;
}

ImGuiWindow::~ImGuiWindow()
Expand Down
34 changes: 0 additions & 34 deletions imgui_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -1557,40 +1557,6 @@ struct IMGUI_API ImGuiWindowTempData
ImVector<float> TextWrapPosStack;
ImVector<ImGuiGroupData>GroupStack;
short StackSizesBackup[6]; // Store size of various stacks for asserting

ImGuiWindowTempData()
{
CursorPos = CursorPosPrevLine = CursorStartPos = CursorMaxPos = ImVec2(0.0f, 0.0f);
CurrLineSize = PrevLineSize = ImVec2(0.0f, 0.0f);
CurrLineTextBaseOffset = PrevLineTextBaseOffset = 0.0f;
Indent = ImVec1(0.0f);
ColumnsOffset = ImVec1(0.0f);
GroupOffset = ImVec1(0.0f);

LastItemId = 0;
LastItemStatusFlags = ImGuiItemStatusFlags_None;
LastItemRect = LastItemDisplayRect = ImRect();

NavLayerActiveMask = NavLayerActiveMaskNext = 0x00;
NavLayerCurrent = ImGuiNavLayer_Main;
NavFocusScopeIdCurrent = 0;
NavHideHighlightOneFrame = false;
NavHasScroll = false;

MenuBarAppending = false;
MenuBarOffset = ImVec2(0.0f, 0.0f);
TreeDepth = 0;
TreeJumpToParentOnPopMask = 0x00;
StateStorage = NULL;
CurrentColumns = NULL;
LayoutType = ParentLayoutType = ImGuiLayoutType_Vertical;
FocusCounterRegular = FocusCounterTabStop = -1;

ItemFlags = ImGuiItemFlags_Default_;
ItemWidth = 0.0f;
TextWrapPos = -1.0f;
memset(StackSizesBackup, 0, sizeof(StackSizesBackup));
}
};

// Storage for one window
Expand Down

0 comments on commit 09caf50

Please sign in to comment.