Columns: Refactor: Renamed all members. (#125, #1499)

This commit is contained in:
omar 2017-12-13 18:42:06 +01:00
parent 78320aa633
commit 3a31a75e3b
2 changed files with 80 additions and 82 deletions

124
imgui.cpp
View File

@ -1743,7 +1743,7 @@ static void SetCursorPosYAndSetupDummyPrevLine(float pos_y, float line_height)
window->DC.CursorPosPrevLine.y = window->DC.CursorPos.y - line_height; // Setting those fields so that SetScrollHere() can properly function after the end of our clipper usage.
window->DC.PrevLineHeight = (line_height - GImGui->Style.ItemSpacing.y); // If we end up needing more accurate data (to e.g. use SameLine) we may as well make the clipper have a fourth step to let user process and display the last item in their list.
if (window->DC.ColumnsSet)
window->DC.ColumnsSet->ColumnsCellMinY = window->DC.CursorPos.y; // Setting this so that cell Y position are set properly
window->DC.ColumnsSet->CellMinY = window->DC.CursorPos.y; // Setting this so that cell Y position are set properly
}
// Use case A: Begin() called from constructor with items_height<0, then called again from Sync() in StepNo 1
@ -5731,7 +5731,7 @@ ImVec2 ImGui::GetContentRegionMax()
ImGuiWindow* window = GetCurrentWindowRead();
ImVec2 mx = window->ContentsRegionRect.Max;
if (window->DC.ColumnsSet)
mx.x = GetColumnOffset(window->DC.ColumnsSet->ColumnsCurrent + 1) - window->WindowPadding.x;
mx.x = GetColumnOffset(window->DC.ColumnsSet->Current + 1) - window->WindowPadding.x;
return mx;
}
@ -10571,7 +10571,7 @@ void ImGui::Separator()
if (window->DC.ColumnsSet)
{
PushColumnClipRect();
window->DC.ColumnsSet->ColumnsCellMinY = window->DC.CursorPos.y;
window->DC.ColumnsSet->CellMinY = window->DC.CursorPos.y;
}
}
@ -10792,22 +10792,22 @@ void ImGui::NextColumn()
PopClipRect();
ImGuiColumnsSet* columns = window->DC.ColumnsSet;
columns->ColumnsCellMaxY = ImMax(columns->ColumnsCellMaxY, window->DC.CursorPos.y);
if (++columns->ColumnsCurrent < columns->ColumnsCount)
columns->CellMaxY = ImMax(columns->CellMaxY, window->DC.CursorPos.y);
if (++columns->Current < columns->Count)
{
// Columns 1+ cancel out IndentX
window->DC.ColumnsOffsetX = GetColumnOffset(columns->ColumnsCurrent) - window->DC.IndentX + g.Style.ItemSpacing.x;
window->DrawList->ChannelsSetCurrent(columns->ColumnsCurrent);
window->DC.ColumnsOffsetX = GetColumnOffset(columns->Current) - window->DC.IndentX + g.Style.ItemSpacing.x;
window->DrawList->ChannelsSetCurrent(columns->Current);
}
else
{
window->DC.ColumnsOffsetX = 0.0f;
columns->ColumnsCurrent = 0;
columns->ColumnsCellMinY = columns->ColumnsCellMaxY;
columns->Current = 0;
columns->CellMinY = columns->CellMaxY;
window->DrawList->ChannelsSetCurrent(0);
}
window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.IndentX + window->DC.ColumnsOffsetX);
window->DC.CursorPos.y = columns->ColumnsCellMinY;
window->DC.CursorPos.y = columns->CellMinY;
window->DC.CurrentLineHeight = 0.0f;
window->DC.CurrentLineTextBaseOffset = 0.0f;
@ -10818,23 +10818,23 @@ void ImGui::NextColumn()
int ImGui::GetColumnIndex()
{
ImGuiWindow* window = GetCurrentWindowRead();
return window->DC.ColumnsSet ? window->DC.ColumnsSet->ColumnsCurrent : 0;
return window->DC.ColumnsSet ? window->DC.ColumnsSet->Current : 0;
}
int ImGui::GetColumnsCount()
{
ImGuiWindow* window = GetCurrentWindowRead();
return window->DC.ColumnsSet ? window->DC.ColumnsSet->ColumnsCount : 1;
return window->DC.ColumnsSet ? window->DC.ColumnsSet->Count : 1;
}
static float OffsetNormToPixels(const ImGuiColumnsSet* columns, float offset_norm)
{
return offset_norm * (columns->ColumnsMaxX - columns->ColumnsMinX);
return offset_norm * (columns->MaxX - columns->MinX);
}
static float PixelsToOffsetNorm(const ImGuiColumnsSet* columns, float offset)
{
return (offset - columns->ColumnsMinX) / (columns->ColumnsMaxX - columns->ColumnsMinX);
return (offset - columns->MinX) / (columns->MaxX - columns->MinX);
}
static float GetDraggedColumnOffset(ImGuiColumnsSet* columns, int column_index)
@ -10844,11 +10844,11 @@ static float GetDraggedColumnOffset(ImGuiColumnsSet* columns, int column_index)
ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow;
IM_ASSERT(column_index > 0); // We cannot drag column 0. If you get this assert you may have a conflict between the ID of your columns and another widgets.
IM_ASSERT(g.ActiveId == columns->ColumnsSetId + ImGuiID(column_index));
IM_ASSERT(g.ActiveId == columns->ID + ImGuiID(column_index));
float x = g.IO.MousePos.x - g.ActiveIdClickOffset.x - window->Pos.x;
x = ImMax(x, ImGui::GetColumnOffset(column_index-1) + g.Style.ColumnsMinSpacing);
if ((columns->ColumnsFlags & ImGuiColumnsFlags_NoPreserveWidths))
if ((columns->Flags & ImGuiColumnsFlags_NoPreserveWidths))
x = ImMin(x, ImGui::GetColumnOffset(column_index+1) - g.Style.ColumnsMinSpacing);
return x;
@ -10861,7 +10861,7 @@ float ImGui::GetColumnOffset(int column_index)
IM_ASSERT(columns != NULL);
if (column_index < 0)
column_index = columns->ColumnsCurrent;
column_index = columns->Current;
/*
if (g.ActiveId)
@ -10873,9 +10873,9 @@ float ImGui::GetColumnOffset(int column_index)
}
*/
IM_ASSERT(column_index < columns->ColumnsData.Size);
const float t = columns->ColumnsData[column_index].OffsetNorm;
const float x_offset = ImLerp(columns->ColumnsMinX, columns->ColumnsMaxX, t);
IM_ASSERT(column_index < columns->Columns.Size);
const float t = columns->Columns[column_index].OffsetNorm;
const float x_offset = ImLerp(columns->MinX, columns->MaxX, t);
return x_offset;
}
@ -10887,20 +10887,20 @@ void ImGui::SetColumnOffset(int column_index, float offset)
IM_ASSERT(columns != NULL);
if (column_index < 0)
column_index = columns->ColumnsCurrent;
column_index = columns->Current;
IM_ASSERT(column_index < columns->ColumnsData.Size);
IM_ASSERT(column_index < columns->Columns.Size);
const bool preserve_width = !(columns->ColumnsFlags & ImGuiColumnsFlags_NoPreserveWidths) && (column_index < columns->ColumnsCount-1);
const bool preserve_width = !(columns->Flags & ImGuiColumnsFlags_NoPreserveWidths) && (column_index < columns->Count-1);
const float width = preserve_width ? GetColumnWidth(column_index) : 0.0f;
if (!(columns->ColumnsFlags & ImGuiColumnsFlags_NoForceWithinWindow))
offset = ImMin(offset, columns->ColumnsMaxX - g.Style.ColumnsMinSpacing * (columns->ColumnsCount - column_index));
if (!(columns->Flags & ImGuiColumnsFlags_NoForceWithinWindow))
offset = ImMin(offset, columns->MaxX - g.Style.ColumnsMinSpacing * (columns->Count - column_index));
const float offset_norm = PixelsToOffsetNorm(columns, offset);
const ImGuiID column_id = columns->ColumnsSetId + ImGuiID(column_index);
const ImGuiID column_id = columns->ID + ImGuiID(column_index);
window->DC.StateStorage->SetFloat(column_id, offset_norm);
columns->ColumnsData[column_index].OffsetNorm = offset_norm;
columns->Columns[column_index].OffsetNorm = offset_norm;
if (preserve_width)
SetColumnOffset(column_index + 1, offset + ImMax(g.Style.ColumnsMinSpacing, width));
@ -10913,8 +10913,8 @@ float ImGui::GetColumnWidth(int column_index)
IM_ASSERT(columns != NULL);
if (column_index < 0)
column_index = columns->ColumnsCurrent;
return OffsetNormToPixels(columns, columns->ColumnsData[column_index+1].OffsetNorm - columns->ColumnsData[column_index].OffsetNorm);
column_index = columns->Current;
return OffsetNormToPixels(columns, columns->Columns[column_index+1].OffsetNorm - columns->Columns[column_index].OffsetNorm);
}
void ImGui::SetColumnWidth(int column_index, float width)
@ -10924,7 +10924,7 @@ void ImGui::SetColumnWidth(int column_index, float width)
IM_ASSERT(columns != NULL);
if (column_index < 0)
column_index = columns->ColumnsCurrent;
column_index = columns->Current;
SetColumnOffset(column_index+1, GetColumnOffset(column_index) + width);
}
@ -10933,20 +10933,20 @@ void ImGui::PushColumnClipRect(int column_index)
ImGuiWindow* window = GetCurrentWindowRead();
ImGuiColumnsSet* columns = window->DC.ColumnsSet;
if (column_index < 0)
column_index = columns->ColumnsCurrent;
column_index = columns->Current;
PushClipRect(columns->ColumnsData[column_index].ClipRect.Min, columns->ColumnsData[column_index].ClipRect.Max, false);
PushClipRect(columns->Columns[column_index].ClipRect.Min, columns->Columns[column_index].ClipRect.Max, false);
}
static ImGuiColumnsSet* FindOrAddColumnsSet(ImGuiWindow* window, ImGuiID id)
{
for (int n = 0; n < window->DC.ColumnsSets.Size; n++)
if (window->DC.ColumnsSets[n].ColumnsSetId == id)
if (window->DC.ColumnsSets[n].ID == id)
return &window->DC.ColumnsSets[n];
window->DC.ColumnsSets.push_back(ImGuiColumnsSet());
ImGuiColumnsSet* columns = &window->DC.ColumnsSets.back();
columns->ColumnsSetId = id;
columns->ID = id;
return columns;
}
@ -10965,35 +10965,35 @@ void ImGui::BeginColumns(const char* str_id, int columns_count, ImGuiColumnsFlag
PopID();
ImGuiColumnsSet* columns = FindOrAddColumnsSet(window, id);
IM_ASSERT(columns->ColumnsSetId == id);
IM_ASSERT(columns->ID == id);
window->DC.ColumnsSet = columns;
// Set state for first column
columns->ColumnsCurrent = 0;
columns->ColumnsCount = columns_count;
columns->ColumnsFlags = flags;
columns->Current = 0;
columns->Count = columns_count;
columns->Flags = flags;
const float content_region_width = (window->SizeContentsExplicit.x != 0.0f) ? (window->SizeContentsExplicit.x) : (window->Size.x -window->ScrollbarSizes.x);
columns->ColumnsMinX = window->DC.IndentX - g.Style.ItemSpacing.x; // Lock our horizontal range
columns->MinX = window->DC.IndentX - g.Style.ItemSpacing.x; // Lock our horizontal range
//column->ColumnsMaxX = content_region_width - window->Scroll.x -((window->Flags & ImGuiWindowFlags_NoScrollbar) ? 0 : g.Style.ScrollbarSize);// - window->WindowPadding().x;
columns->ColumnsMaxX = content_region_width - window->Scroll.x;
columns->ColumnsStartPosY = window->DC.CursorPos.y;
columns->ColumnsStartMaxPosX = window->DC.CursorMaxPos.x;
columns->ColumnsCellMinY = columns->ColumnsCellMaxY = window->DC.CursorPos.y;
columns->MaxX = content_region_width - window->Scroll.x;
columns->StartPosY = window->DC.CursorPos.y;
columns->StartMaxPosX = window->DC.CursorMaxPos.x;
columns->CellMinY = columns->CellMaxY = window->DC.CursorPos.y;
window->DC.ColumnsOffsetX = 0.0f;
window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.IndentX + window->DC.ColumnsOffsetX);
// Cache column offsets
columns->ColumnsData.resize(columns_count + 1);
columns->Columns.resize(columns_count + 1);
for (int column_index = 0; column_index < columns_count + 1; column_index++)
{
const ImGuiID column_id = columns->ColumnsSetId + ImGuiID(column_index);
const ImGuiID column_id = columns->ID + ImGuiID(column_index);
KeepAliveID(column_id);
const float default_t = column_index / (float)columns_count;
float t = window->DC.StateStorage->GetFloat(column_id, default_t);
if (!(columns->ColumnsFlags & ImGuiColumnsFlags_NoForceWithinWindow))
t = ImMin(t, PixelsToOffsetNorm(columns, columns->ColumnsMaxX - g.Style.ColumnsMinSpacing * (columns->ColumnsCount - column_index)));
columns->ColumnsData[column_index].OffsetNorm = t;
if (!(columns->Flags & ImGuiColumnsFlags_NoForceWithinWindow))
t = ImMin(t, PixelsToOffsetNorm(columns, columns->MaxX - g.Style.ColumnsMinSpacing * (columns->Count - column_index)));
columns->Columns[column_index].OffsetNorm = t;
}
// Cache clipping rectangles
@ -11001,11 +11001,11 @@ void ImGui::BeginColumns(const char* str_id, int columns_count, ImGuiColumnsFlag
{
float clip_x1 = ImFloor(0.5f + window->Pos.x + GetColumnOffset(column_index) - 1.0f);
float clip_x2 = ImFloor(0.5f + window->Pos.x + GetColumnOffset(column_index + 1) - 1.0f);
columns->ColumnsData[column_index].ClipRect = ImRect(clip_x1, -FLT_MAX, clip_x2, +FLT_MAX);
columns->ColumnsData[column_index].ClipRect.ClipWith(window->ClipRect);
columns->Columns[column_index].ClipRect = ImRect(clip_x1, -FLT_MAX, clip_x2, +FLT_MAX);
columns->Columns[column_index].ClipRect.ClipWith(window->ClipRect);
}
window->DrawList->ChannelsSplit(columns->ColumnsCount);
window->DrawList->ChannelsSplit(columns->Count);
PushColumnClipRect();
PushItemWidth(GetColumnWidth() * 0.65f);
}
@ -11021,28 +11021,28 @@ void ImGui::EndColumns()
PopClipRect();
window->DrawList->ChannelsMerge();
columns->ColumnsCellMaxY = ImMax(columns->ColumnsCellMaxY, window->DC.CursorPos.y);
window->DC.CursorPos.y = columns->ColumnsCellMaxY;
if (!(columns->ColumnsFlags & ImGuiColumnsFlags_GrowParentContentsSize))
window->DC.CursorMaxPos.x = ImMax(columns->ColumnsStartMaxPosX, columns->ColumnsMaxX); // Restore cursor max pos, as columns don't grow parent
columns->CellMaxY = ImMax(columns->CellMaxY, window->DC.CursorPos.y);
window->DC.CursorPos.y = columns->CellMaxY;
if (!(columns->Flags & ImGuiColumnsFlags_GrowParentContentsSize))
window->DC.CursorMaxPos.x = ImMax(columns->StartMaxPosX, columns->MaxX); // Restore cursor max pos, as columns don't grow parent
// Draw columns borders and handle resize
if (!(columns->ColumnsFlags & ImGuiColumnsFlags_NoBorder) && !window->SkipItems)
if (!(columns->Flags & ImGuiColumnsFlags_NoBorder) && !window->SkipItems)
{
const float y1 = columns->ColumnsStartPosY;
const float y1 = columns->StartPosY;
const float y2 = window->DC.CursorPos.y;
int dragging_column = -1;
for (int i = 1; i < columns->ColumnsCount; i++)
for (int i = 1; i < columns->Count; i++)
{
float x = window->Pos.x + GetColumnOffset(i);
const ImGuiID column_id = columns->ColumnsSetId + ImGuiID(i);
const ImGuiID column_id = columns->ID + ImGuiID(i);
const float column_hw = 4.0f; // Half-width for interaction
const ImRect column_rect(ImVec2(x - column_hw, y1), ImVec2(x + column_hw, y2));
if (IsClippedEx(column_rect, column_id, false))
continue;
bool hovered = false, held = false;
if (!(columns->ColumnsFlags & ImGuiColumnsFlags_NoResize))
if (!(columns->Flags & ImGuiColumnsFlags_NoResize))
{
ButtonBehavior(column_rect, column_id, &hovered, &held);
if (hovered || held)
@ -11068,7 +11068,7 @@ void ImGui::EndColumns()
}
}
columns->ColumnsData.resize(0);
columns->Columns.resize(0);
window->DC.ColumnsSet = NULL;
window->DC.ColumnsOffsetX = 0.0f;
window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.IndentX + window->DC.ColumnsOffsetX);
@ -11080,7 +11080,7 @@ void ImGui::Columns(int columns_count, const char* id, bool border)
ImGuiWindow* window = GetCurrentWindow();
IM_ASSERT(columns_count >= 1);
if (window->DC.ColumnsSet != NULL && window->DC.ColumnsSet->ColumnsCount != columns_count)
if (window->DC.ColumnsSet != NULL && window->DC.ColumnsSet->Count != columns_count)
EndColumns();
ImGuiColumnsFlags flags = (border ? 0 : ImGuiColumnsFlags_NoBorder);

View File

@ -421,30 +421,28 @@ struct ImGuiColumnData
struct ImGuiColumnsSet
{
int ColumnsCurrent;
int ColumnsCount;
float ColumnsMinX;
float ColumnsMaxX;
float ColumnsStartPosY;
float ColumnsStartMaxPosX; // Backup of CursorMaxPos
float ColumnsCellMinY;
float ColumnsCellMaxY;
ImGuiColumnsFlags ColumnsFlags;
ImGuiID ColumnsSetId;
ImVector<ImGuiColumnData> ColumnsData;
ImGuiID ID;
ImGuiColumnsFlags Flags;
int Current;
int Count;
float MinX, MaxX;
float StartPosY;
float StartMaxPosX; // Backup of CursorMaxPos
float CellMinY, CellMaxY;
ImVector<ImGuiColumnData> Columns;
ImGuiColumnsSet() { Clear(); }
void Clear()
{
ColumnsCurrent = 0;
ColumnsCount = 1;
ColumnsMinX = ColumnsMaxX = 0.0f;
ColumnsStartPosY = 0.0f;
ColumnsStartMaxPosX = 0.0f;
ColumnsCellMinY = ColumnsCellMaxY = 0.0f;
ColumnsFlags = 0;
ColumnsSetId = 0;
ColumnsData.clear();
ID = 0;
Flags = 0;
Current = 0;
Count = 1;
MinX = MaxX = 0.0f;
StartPosY = 0.0f;
StartMaxPosX = 0.0f;
CellMinY = CellMaxY = 0.0f;
Columns.clear();
}
};