Fixed GetWindowContentRegionMax() being off by ScrollSize amount when SizeExplicit is set + caching ContentsRegionRect.
Relates to horizontal scrollbar, explicit contents size
diff --git a/imgui.cpp b/imgui.cpp
index 7f89e9b..3c310dd 100644
--- a/imgui.cpp
+++ b/imgui.cpp
@@ -4201,6 +4201,12 @@
}
}
+ // Update ContentsRegionMax. All the variable it depends on are set above in this function.
+ window->ContentsRegionRect.Min.x = -window->Scroll.x + window->WindowPadding.x;
+ window->ContentsRegionRect.Min.x = -window->Scroll.y + window->TitleBarHeight() + window->MenuBarHeight() + window->WindowPadding.y;
+ window->ContentsRegionRect.Max.x = (window->SizeContentsExplicit.x != 0.0f ? window->SizeContentsExplicit.x : window->Size.x - window->ScrollbarSizes.x) - window->Scroll.x - window->WindowPadding.x;
+ window->ContentsRegionRect.Max.y = (window->SizeContentsExplicit.y != 0.0f ? window->SizeContentsExplicit.y : window->Size.y - window->ScrollbarSizes.y) - window->Scroll.y - window->WindowPadding.y;
+
// Setup drawing context
window->DC.IndentX = 0.0f + window->WindowPadding.x - window->Scroll.x;
window->DC.ColumnsOffsetX = 0.0f;
@@ -4970,12 +4976,10 @@
}
// In window space (not screen space!)
-// FIXME-OPT: Could cache and maintain it (pretty much only change on columns change)
ImVec2 ImGui::GetContentRegionMax()
{
ImGuiWindow* window = GetCurrentWindowRead();
- ImVec2 content_region_size = ImVec2(window->SizeContentsExplicit.x != 0.0f ? window->SizeContentsExplicit.x : window->Size.x - window->ScrollbarSizes.x, window->SizeContentsExplicit.y != 0.0f ? window->SizeContentsExplicit.y : window->Size.y - window->ScrollbarSizes.y);
- ImVec2 mx = content_region_size - window->Scroll - window->WindowPadding;
+ ImVec2 mx = window->ContentsRegionRect.Max;
if (window->DC.ColumnsCount != 1)
mx.x = ImGui::GetColumnOffset(window->DC.ColumnsCurrent + 1) - window->WindowPadding.x;
return mx;
@@ -4996,20 +5000,19 @@
ImVec2 ImGui::GetWindowContentRegionMin()
{
ImGuiWindow* window = GetCurrentWindowRead();
- return ImVec2(-window->Scroll.x, -window->Scroll.y + window->TitleBarHeight() + window->MenuBarHeight()) + window->WindowPadding;
+ return window->ContentsRegionRect.Min;
}
ImVec2 ImGui::GetWindowContentRegionMax()
{
ImGuiWindow* window = GetCurrentWindowRead();
- ImVec2 content_region_size = ImVec2(window->SizeContentsExplicit.x != 0.0f ? window->SizeContentsExplicit.x : window->Size.x, window->SizeContentsExplicit.y != 0.0f ? window->SizeContentsExplicit.y : window->Size.y);
- ImVec2 m = content_region_size - window->Scroll - window->WindowPadding - window->ScrollbarSizes;
- return m;
+ return window->ContentsRegionRect.Max;
}
float ImGui::GetWindowContentRegionWidth()
{
- return GetWindowContentRegionMax().x - GetWindowContentRegionMin().x;
+ ImGuiWindow* window = GetCurrentWindowRead();
+ return window->ContentsRegionRect.Max.x - window->ContentsRegionRect.Min.x;
}
float ImGui::GetTextLineHeight()
diff --git a/imgui_internal.h b/imgui_internal.h
index c787dbd..c67eab9 100644
--- a/imgui_internal.h
+++ b/imgui_internal.h
@@ -607,6 +607,7 @@
ImVec2 SizeFull; // Size when non collapsed
ImVec2 SizeContents; // Size of contents (== extents reach of the drawing cursor) from previous frame
ImVec2 SizeContentsExplicit; // Size of contents explicitly set by the user via SetNextWindowContentSize()
+ ImRect ContentsRegionRect; // Maximum visible content position in window coordinates. ~~ (SizeContentsExplicit ? SizeContentsExplicit : Size - ScrollbarSizes) - CursorStartPos, per axis
ImVec2 WindowPadding; // Window padding at the time of begin. We need to lock it, in particular manipulation of the ShowBorder would have an effect
ImGuiID MoveID; // == window->GetID("#MOVE")
ImVec2 Scroll;