Skip to content

Commit

Permalink
Internals: removed GetContentRegionMaxAbs() which was only meaningful…
Browse files Browse the repository at this point in the history
…ly used in place of GetContentRegionAvail().
  • Loading branch information
ocornut committed Jul 25, 2024
1 parent 055b2e8 commit 4227402
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 25 deletions.
36 changes: 12 additions & 24 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10313,7 +10313,6 @@ IM_MSVC_RUNTIME_CHECKS_RESTORE
// - GetFrameHeight()
// - GetFrameHeightWithSpacing()
// - GetContentRegionMax()
// - GetContentRegionMaxAbs() [Internal]
// - GetContentRegionAvail(),
// - BeginGroup()
// - EndGroup()
Expand Down Expand Up @@ -10530,8 +10529,8 @@ float ImGui::CalcItemWidth()
w = window->DC.ItemWidth;
if (w < 0.0f)
{
float region_max_x = GetContentRegionMaxAbs().x;
w = ImMax(1.0f, region_max_x - window->DC.CursorPos.x + w);
float region_avail_x = GetContentRegionAvail().x;
w = ImMax(1.0f, region_avail_x + w);
}
w = IM_TRUNC(w);
return w;
Expand All @@ -10543,22 +10542,19 @@ float ImGui::CalcItemWidth()
// The 4.0f here may be changed to match CalcItemWidth() and/or BeginChild() (right now we have a mismatch which is harmless but undesirable)
ImVec2 ImGui::CalcItemSize(ImVec2 size, float default_w, float default_h)
{
ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow;

ImVec2 region_max;
ImVec2 avail;
if (size.x < 0.0f || size.y < 0.0f)
region_max = GetContentRegionMaxAbs();
avail = GetContentRegionAvail();

if (size.x == 0.0f)
size.x = default_w;
else if (size.x < 0.0f)
size.x = ImMax(4.0f, region_max.x - window->DC.CursorPos.x + size.x);
size.x = ImMax(4.0f, avail.x + size.x); // <-- size.x is negative here so we are subtracting

if (size.y == 0.0f)
size.y = default_h;
else if (size.y < 0.0f)
size.y = ImMax(4.0f, region_max.y - window->DC.CursorPos.y + size.y);
size.y = ImMax(4.0f, avail.y + size.y); // <-- size.y is negative here so we are subtracting

return size;
}
Expand Down Expand Up @@ -10587,30 +10583,22 @@ float ImGui::GetFrameHeightWithSpacing()
return g.FontSize + g.Style.FramePadding.y * 2.0f + g.Style.ItemSpacing.y;
}

// FIXME: All the Contents Region function are messy or misleading. WE WILL AIM TO OBSOLETE ALL OF THEM WITH A NEW "WORK RECT" API. Thanks for your patience!

// FIXME: This is in window space (not screen space!).
ImVec2 ImGui::GetContentRegionMax()
ImVec2 ImGui::GetContentRegionAvail()
{
ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow;
ImVec2 mx = (window->DC.CurrentColumns || g.CurrentTable) ? window->WorkRect.Max : window->ContentRegionRect.Max;
return mx - window->Pos;
return mx - window->DC.CursorPos;
}

// [Internal] Absolute coordinate. Saner. This is not exposed until we finishing refactoring work rect features.
ImVec2 ImGui::GetContentRegionMaxAbs()
// FIXME: All the Contents Region function are messy or misleading. WE WILL AIM TO OBSOLETE ALL OF THEM WITH A NEW "WORK RECT" API. Thanks for your patience!
// FIXME: This is in window space (not screen space!).
ImVec2 ImGui::GetContentRegionMax()
{
ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow;
ImVec2 mx = (window->DC.CurrentColumns || g.CurrentTable) ? window->WorkRect.Max : window->ContentRegionRect.Max;
return mx;
}

ImVec2 ImGui::GetContentRegionAvail()
{
ImGuiWindow* window = GImGui->CurrentWindow;
return GetContentRegionMaxAbs() - window->DC.CursorPos;
return mx - window->Pos;
}

#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
Expand Down
1 change: 0 additions & 1 deletion imgui_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -3217,7 +3217,6 @@ namespace ImGui
IMGUI_API ImVec2 CalcItemSize(ImVec2 size, float default_w, float default_h);
IMGUI_API float CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x);
IMGUI_API void PushMultiItemsWidths(int components, float width_full);
IMGUI_API ImVec2 GetContentRegionMaxAbs();
IMGUI_API void ShrinkWidths(ImGuiShrinkWidthItem* items, int count, float width_excess);

// Parameter stacks (shared)
Expand Down

0 comments on commit 4227402

Please sign in to comment.