Columns: Refactor: Moved ColumnsSet[] to window out of DC as they are persistent data for most + fix for pre C++11 compilers. (#125, #1499)

This commit is contained in:
omar 2017-12-13 19:21:21 +01:00
parent b016215c80
commit 4ae5c7e227
2 changed files with 15 additions and 15 deletions

View File

@ -10935,12 +10935,12 @@ void ImGui::PushColumnClipRect(int column_index)
static ImGuiColumnsSet* FindOrAddColumnsSet(ImGuiWindow* window, ImGuiID id) static ImGuiColumnsSet* FindOrAddColumnsSet(ImGuiWindow* window, ImGuiID id)
{ {
for (int n = 0; n < window->DC.ColumnsSets.Size; n++) for (int n = 0; n < window->ColumnsStorage.Size; n++)
if (window->DC.ColumnsSets[n].ID == id) if (window->ColumnsStorage[n].ID == id)
return &window->DC.ColumnsSets[n]; return &window->ColumnsStorage[n];
window->DC.ColumnsSets.push_back(ImGuiColumnsSet()); window->ColumnsStorage.push_back(ImGuiColumnsSet());
ImGuiColumnsSet* columns = &window->DC.ColumnsSets.back(); ImGuiColumnsSet* columns = &window->ColumnsStorage.back();
columns->ID = id; columns->ID = id;
return columns; return columns;
} }

View File

@ -201,7 +201,7 @@ enum ImGuiColumnsFlags_
ImGuiColumnsFlags_NoResize = 1 << 1, // Disable resizing columns when clicking on the dividers ImGuiColumnsFlags_NoResize = 1 << 1, // Disable resizing columns when clicking on the dividers
ImGuiColumnsFlags_NoPreserveWidths = 1 << 2, // Disable column width preservation when adjusting columns ImGuiColumnsFlags_NoPreserveWidths = 1 << 2, // Disable column width preservation when adjusting columns
ImGuiColumnsFlags_NoForceWithinWindow = 1 << 3, // Disable forcing columns to fit within window ImGuiColumnsFlags_NoForceWithinWindow = 1 << 3, // Disable forcing columns to fit within window
ImGuiColumnsFlags_GrowParentContentsSize= 1 << 4, // (WIP) Restore pre-1.51 behavior of extending the parent window contents size but _without affecting the columns width at all_. Will eventually remove. ImGuiColumnsFlags_GrowParentContentsSize= 1 << 4 // (WIP) Restore pre-1.51 behavior of extending the parent window contents size but _without affecting the columns width at all_. Will eventually remove.
}; };
enum ImGuiSelectableFlagsPrivate_ enum ImGuiSelectableFlagsPrivate_
@ -403,19 +403,19 @@ struct ImGuiMouseCursorData
// Storage for current popup stack // Storage for current popup stack
struct ImGuiPopupRef struct ImGuiPopupRef
{ {
ImGuiID PopupId; // Set on OpenPopup() ImGuiID PopupId; // Set on OpenPopup()
ImGuiWindow* Window; // Resolved on BeginPopup() - may stay unresolved if user never calls OpenPopup() ImGuiWindow* Window; // Resolved on BeginPopup() - may stay unresolved if user never calls OpenPopup()
ImGuiWindow* ParentWindow; // Set on OpenPopup() ImGuiWindow* ParentWindow; // Set on OpenPopup()
ImGuiID ParentMenuSet; // Set on OpenPopup() ImGuiID ParentMenuSet; // Set on OpenPopup()
ImVec2 MousePosOnOpen; // Copy of mouse position at the time of opening popup ImVec2 MousePosOnOpen; // Copy of mouse position at the time of opening popup
ImGuiPopupRef(ImGuiID id, ImGuiWindow* parent_window, ImGuiID parent_menu_set, const ImVec2& mouse_pos) { PopupId = id; Window = NULL; ParentWindow = parent_window; ParentMenuSet = parent_menu_set; MousePosOnOpen = mouse_pos; } ImGuiPopupRef(ImGuiID id, ImGuiWindow* parent_window, ImGuiID parent_menu_set, const ImVec2& mouse_pos) { PopupId = id; Window = NULL; ParentWindow = parent_window; ParentMenuSet = parent_menu_set; MousePosOnOpen = mouse_pos; }
}; };
struct ImGuiColumnData struct ImGuiColumnData
{ {
float OffsetNorm; // Column start offset, normalized 0.0 (far left) -> 1.0 (far right) float OffsetNorm; // Column start offset, normalized 0.0 (far left) -> 1.0 (far right)
ImRect ClipRect; ImRect ClipRect;
ImGuiColumnData() { OffsetNorm = 0.0f; } ImGuiColumnData() { OffsetNorm = 0.0f; }
}; };
@ -701,8 +701,7 @@ struct IMGUI_API ImGuiDrawContext
float IndentX; // Indentation / start position from left of window (increased by TreePush/TreePop, etc.) float IndentX; // Indentation / start position from left of window (increased by TreePush/TreePop, etc.)
float GroupOffsetX; float GroupOffsetX;
float ColumnsOffsetX; // Offset to the current column (if ColumnsCurrent > 0). FIXME: This and the above should be a stack to allow use cases like Tree->Column->Tree. Need revamp columns API. float ColumnsOffsetX; // Offset to the current column (if ColumnsCurrent > 0). FIXME: This and the above should be a stack to allow use cases like Tree->Column->Tree. Need revamp columns API.
ImGuiColumnsSet* ColumnsSet; ImGuiColumnsSet* ColumnsSet; // Current columns set
ImVector<ImGuiColumnsSet> ColumnsSets;
ImGuiDrawContext() ImGuiDrawContext()
{ {
@ -784,6 +783,7 @@ struct IMGUI_API ImGuiWindow
float ItemWidthDefault; float ItemWidthDefault;
ImGuiSimpleColumns MenuColumns; // Simplified columns storage for menu items ImGuiSimpleColumns MenuColumns; // Simplified columns storage for menu items
ImGuiStorage StateStorage; ImGuiStorage StateStorage;
ImVector<ImGuiColumnsSet> ColumnsStorage;
float FontWindowScale; // Scale multiplier per-window float FontWindowScale; // Scale multiplier per-window
ImDrawList* DrawList; ImDrawList* DrawList;
ImGuiWindow* ParentWindow; // If we are a child _or_ popup window, this is pointing to our parent. Otherwise NULL. ImGuiWindow* ParentWindow; // If we are a child _or_ popup window, this is pointing to our parent. Otherwise NULL.