Columns: Column width data is no longer lost while dragging toward the right side. (#1499, #125)
diff --git a/imgui.cpp b/imgui.cpp
index 91b7777..cf21d0e 100644
--- a/imgui.cpp
+++ b/imgui.cpp
@@ -10879,6 +10879,19 @@
return x_offset;
}
+static float GetColumnWidthEx(ImGuiColumnsSet* columns, int column_index, bool before_resize = false)
+{
+ if (column_index < 0)
+ column_index = columns->Current;
+
+ float offset_norm;
+ if (before_resize)
+ offset_norm = columns->Columns[column_index + 1].OffsetNormBeforeResize - columns->Columns[column_index].OffsetNormBeforeResize;
+ else
+ offset_norm = columns->Columns[column_index + 1].OffsetNorm - columns->Columns[column_index].OffsetNorm;
+ return OffsetNormToPixels(columns, offset_norm);
+}
+
float ImGui::GetColumnWidth(int column_index)
{
ImGuiWindow* window = GetCurrentWindowRead();
@@ -10902,7 +10915,7 @@
IM_ASSERT(column_index < columns->Columns.Size);
const bool preserve_width = !(columns->Flags & ImGuiColumnsFlags_NoPreserveWidths) && (column_index < columns->Count-1);
- const float width = preserve_width ? GetColumnWidth(column_index) : 0.0f;
+ const float width = preserve_width ? GetColumnWidthEx(columns, column_index, columns->IsBeingResized) : 0.0f;
if (!(columns->Flags & ImGuiColumnsFlags_NoForceWithinWindow))
offset = ImMin(offset, columns->MaxX - g.Style.ColumnsMinSpacing * (columns->Count - column_index));
@@ -11033,7 +11046,7 @@
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
- columns->IsBeingResized = false;
+ bool is_being_resized = false;
if (!(columns->Flags & ImGuiColumnsFlags_NoBorder) && !window->SkipItems)
{
const float y1 = columns->StartPosY;
@@ -11070,11 +11083,15 @@
// Apply dragging after drawing the column lines, so our rendered lines are in sync with how items were displayed during the frame.
if (dragging_column != -1)
{
+ if (!columns->IsBeingResized)
+ for (int n = 0; n < columns->Count + 1; n++)
+ columns->Columns[n].OffsetNormBeforeResize = columns->Columns[n].OffsetNorm;
+ columns->IsBeingResized = is_being_resized = true;
float x = GetDraggedColumnOffset(columns, dragging_column);
SetColumnOffset(dragging_column, x);
- columns->IsBeingResized = true;
}
}
+ columns->IsBeingResized = is_being_resized;
window->DC.ColumnsSet = NULL;
window->DC.ColumnsOffsetX = 0.0f;
diff --git a/imgui_internal.h b/imgui_internal.h
index ca1086b..f0d598b 100644
--- a/imgui_internal.h
+++ b/imgui_internal.h
@@ -414,10 +414,11 @@
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)
+ float OffsetNormBeforeResize;
ImRect ClipRect;
- ImGuiColumnData() { OffsetNorm = 0.0f; }
+ ImGuiColumnData() { OffsetNorm = OffsetNormBeforeResize = 0.0f; }
};
struct ImGuiColumnsSet