Tables: fixed GetContentRegionAvail().y report not taking account of lower cell padding or of using ImGuiTableFlags_NoHostExtendY. (#6619)
Made GetContentRegionMax() fully defer to WorkRect when inside a table container.
diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt
index 0ec6be5..6ffe682 100644
--- a/docs/CHANGELOG.txt
+++ b/docs/CHANGELOG.txt
@@ -64,6 +64,10 @@
- InputText: Fixed a case where deactivation frame would write to underlying
buffer or call CallbackResize although unnecessary, in a frame where the
return value was false.
+- Tables: fixed GetContentRegionAvail().y report not taking account of lower cell
+ padding or of using ImGuiTableFlags_NoHostExtendY. Not taking it into account
+ would make the idiom of creating vertically bottom-aligned content (e.g. a child
+ window) inside a table make the parent window erroneously have a scrollbar. (#6619)
- Tables: fixed calculation of multi-instance shared decoration/scrollbar width of
scrolling tables, to avoid flickering width variation when resizing down a table
hosting a child window. (#5920, #6619)
diff --git a/imgui.cpp b/imgui.cpp
index 3e464de..1afaf9e 100644
--- a/imgui.cpp
+++ b/imgui.cpp
@@ -9774,9 +9774,7 @@
{
ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow;
- ImVec2 mx = window->ContentRegionRect.Max;
- if (window->DC.CurrentColumns || g.CurrentTable)
- mx.x = window->WorkRect.Max.x;
+ ImVec2 mx = (window->DC.CurrentColumns || g.CurrentTable) ? window->WorkRect.Max : window->ContentRegionRect.Max;
return mx - window->Pos;
}
@@ -9785,9 +9783,7 @@
{
ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow;
- ImVec2 mx = window->ContentRegionRect.Max;
- if (window->DC.CurrentColumns || g.CurrentTable)
- mx.x = window->WorkRect.Max.x;
+ ImVec2 mx = (window->DC.CurrentColumns || g.CurrentTable) ? window->WorkRect.Max : window->ContentRegionRect.Max;
return mx;
}
diff --git a/imgui_tables.cpp b/imgui_tables.cpp
index 1203254..33c9d05 100644
--- a/imgui_tables.cpp
+++ b/imgui_tables.cpp
@@ -1126,6 +1126,14 @@
table->BorderX1 = table->InnerClipRect.Min.x;// +((table->Flags & ImGuiTableFlags_BordersOuter) ? 0.0f : -1.0f);
table->BorderX2 = table->InnerClipRect.Max.x;// +((table->Flags & ImGuiTableFlags_BordersOuter) ? 0.0f : +1.0f);
+ // Setup window's WorkRect.Max.y for GetContentRegionAvail(). Other values will be updated in each TableBeginCell() call.
+ float window_content_max_y;
+ if (table->Flags & ImGuiTableFlags_NoHostExtendY)
+ window_content_max_y = table->OuterRect.Max.y;
+ else
+ window_content_max_y = ImMax(table->InnerWindow->ContentRegionRect.Max.y, (table->Flags & ImGuiTableFlags_ScrollY) ? 0.0f : table->OuterRect.Max.y);
+ table->InnerWindow->WorkRect.Max.y = ImClamp(window_content_max_y - g.Style.CellPadding.y, table->InnerWindow->WorkRect.Min.y, table->InnerWindow->WorkRect.Max.y);
+
// [Part 9] Allocate draw channels and setup background cliprect
TableSetupDrawChannels(table);
@@ -2011,6 +2019,7 @@
window->DC.CurrLineTextBaseOffset = table->RowTextBaseline;
window->DC.NavLayerCurrent = (ImGuiNavLayer)column->NavLayerCurrent;
+ // Note how WorkRect.Max.y is only set once during layout
window->WorkRect.Min.y = window->DC.CursorPos.y;
window->WorkRect.Min.x = column->WorkMinX;
window->WorkRect.Max.x = column->WorkMaxX;
@@ -3974,6 +3983,7 @@
window->DC.ColumnsOffset.x = ImMax(column_padding - window->WindowPadding.x, 0.0f);
window->DC.CursorPos.x = IM_FLOOR(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x);
window->WorkRect.Max.x = window->Pos.x + offset_1 - column_padding;
+ window->WorkRect.Max.y = window->ContentRegionRect.Max.y;
}
void ImGui::NextColumn()