1
0
mirror of https://github.com/ocornut/imgui.git synced 2024-11-24 07:40:22 +01:00

Columns: Fixed Separator from creating an extraneous draw command. Fixed Selectable with SpanAllColumns flag from creating an extraneous draw command. (#125)

This commit is contained in:
omar 2019-05-09 12:10:36 +02:00
parent 42fc563fed
commit b7c2759f95
4 changed files with 38 additions and 12 deletions

View File

@ -35,6 +35,8 @@ HOW TO UPDATE?
Breaking Changes:
Other Changes:
- Columns: Fixed Separator from creating an extraneous draw command. (#125)
- Columns: Fixed Selectable with SpanAllColumns flag from creating an extraneous draw command. (#125)
-----------------------------------------------------------------------

View File

@ -8400,13 +8400,13 @@ void ImGui::NextColumn()
{
// New column (columns 1+ cancels out IndentX)
window->DC.ColumnsOffset.x = GetColumnOffset(columns->Current) - window->DC.Indent.x + g.Style.ItemSpacing.x;
window->DrawList->ChannelsSetCurrent(columns->Current);
window->DrawList->ChannelsSetCurrent(columns->Current + 1);
}
else
{
// New row/line
window->DC.ColumnsOffset.x = 0.0f;
window->DrawList->ChannelsSetCurrent(0);
window->DrawList->ChannelsSetCurrent(1);
columns->Current = 0;
columns->LineMinY = columns->LineMaxY;
}
@ -8415,7 +8415,7 @@ void ImGui::NextColumn()
window->DC.CurrentLineSize = ImVec2(0.0f, 0.0f);
window->DC.CurrentLineTextBaseOffset = 0.0f;
PushColumnClipRect();
PushColumnClipRect(columns->Current);
PushItemWidth(GetColumnWidth() * 0.65f); // FIXME-COLUMNS: Move on columns setup
}
@ -8543,6 +8543,25 @@ void ImGui::PushColumnClipRect(int column_index)
PushClipRect(column->ClipRect.Min, column->ClipRect.Max, false);
}
// Get into the columns background draw command (which is generally the same draw command as before we called BeginColumns)
void ImGui::PushColumnsBackground()
{
ImGuiWindow* window = GetCurrentWindowRead();
ImGuiColumns* columns = window->DC.CurrentColumns;
window->DrawList->ChannelsSetCurrent(0);
int cmd_size = window->DrawList->CmdBuffer.Size;
PushClipRect(columns->BackupClipRect.Min, columns->BackupClipRect.Max, false);
IM_ASSERT(cmd_size == window->DrawList->CmdBuffer.Size); // Being in channel 0 this should not have created an ImDrawCmd
}
void ImGui::PopColumnsBackground()
{
ImGuiWindow* window = GetCurrentWindowRead();
ImGuiColumns* columns = window->DC.CurrentColumns;
window->DrawList->ChannelsSetCurrent(columns->Current + 1);
PopClipRect();
}
ImGuiColumns* ImGui::FindOrCreateColumns(ImGuiWindow* window, ImGuiID id)
{
// We have few columns per window so for now we don't need bother much with turning this into a faster lookup.
@ -8593,6 +8612,7 @@ void ImGui::BeginColumns(const char* str_id, int columns_count, ImGuiColumnsFlag
columns->MaxX = ImMax(content_region_width - window->Scroll.x, columns->MinX + 1.0f);
columns->BackupCursorPosY = window->DC.CursorPos.y;
columns->BackupCursorMaxPosX = window->DC.CursorMaxPos.x;
columns->BackupClipRect = window->ClipRect;
columns->LineMinY = columns->LineMaxY = window->DC.CursorPos.y;
window->DC.ColumnsOffset.x = 0.0f;
window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x);
@ -8626,8 +8646,9 @@ void ImGui::BeginColumns(const char* str_id, int columns_count, ImGuiColumnsFlag
if (columns->Count > 1)
{
window->DrawList->ChannelsSplit(columns->Count);
PushColumnClipRect();
window->DrawList->ChannelsSplit(1 + columns->Count);
window->DrawList->ChannelsSetCurrent(1);
PushColumnClipRect(0);
}
PushItemWidth(GetColumnWidth() * 0.65f);
}

View File

@ -683,6 +683,7 @@ struct ImGuiColumns
float LineMinY, LineMaxY;
float BackupCursorPosY; // Backup of CursorPos at the time of BeginColumns()
float BackupCursorMaxPosX; // Backup of CursorMaxPos at the time of BeginColumns()
ImRect BackupClipRect;
ImVector<ImGuiColumnData> Columns;
ImGuiColumns() { Clear(); }
@ -1502,7 +1503,9 @@ namespace ImGui
// New Columns API (FIXME-WIP)
IMGUI_API void BeginColumns(const char* str_id, int count, ImGuiColumnsFlags flags = 0); // setup number of columns. use an identifier to distinguish multiple column sets. close with EndColumns().
IMGUI_API void EndColumns(); // close columns
IMGUI_API void PushColumnClipRect(int column_index = -1);
IMGUI_API void PushColumnClipRect(int column_index);
IMGUI_API void PushColumnsBackground();
IMGUI_API void PopColumnsBackground();
IMGUI_API ImGuiID GetColumnsID(const char* str_id, int count);
IMGUI_API ImGuiColumns* FindOrCreateColumns(ImGuiWindow* window, ImGuiID id);

View File

@ -1216,7 +1216,7 @@ void ImGui::Separator()
// Horizontal Separator
if (window->DC.CurrentColumns)
PopClipRect();
PushColumnsBackground();
float x1 = window->Pos.x;
float x2 = window->Pos.x + window->Size.x;
@ -1228,7 +1228,7 @@ void ImGui::Separator()
if (!ItemAdd(bb, 0))
{
if (window->DC.CurrentColumns)
PushColumnClipRect();
PopColumnsBackground();
return;
}
@ -1239,7 +1239,7 @@ void ImGui::Separator()
if (window->DC.CurrentColumns)
{
PushColumnClipRect();
PopColumnsBackground();
window->DC.CurrentColumns->LineMinY = window->DC.CursorPos.y;
}
}
@ -5311,7 +5311,7 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl
const ImGuiStyle& style = g.Style;
if ((flags & ImGuiSelectableFlags_SpanAllColumns) && window->DC.CurrentColumns) // FIXME-OPT: Avoid if vertically clipped.
PopClipRect();
PushColumnsBackground();
ImGuiID id = window->GetID(label);
ImVec2 label_size = CalcTextSize(label, NULL, true);
@ -5355,7 +5355,7 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl
if (!item_add)
{
if ((flags & ImGuiSelectableFlags_SpanAllColumns) && window->DC.CurrentColumns)
PushColumnClipRect();
PopColumnsBackground();
return false;
}
@ -5401,7 +5401,7 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl
if ((flags & ImGuiSelectableFlags_SpanAllColumns) && window->DC.CurrentColumns)
{
PushColumnClipRect();
PopColumnsBackground();
bb.Max.x -= (GetContentRegionMax().x - max_x);
}