1
0
mirror of https://github.com/ocornut/imgui.git synced 2024-11-30 18:34:34 +01:00

Internals: removed GetContentRegionMaxAbs() which was only meaningfully used in place of GetContentRegionAvail().

This commit is contained in:
ocornut 2024-07-25 16:10:18 +02:00
parent 055b2e80fb
commit 4227402b2f
2 changed files with 14 additions and 27 deletions

View File

@ -10313,7 +10313,6 @@ IM_MSVC_RUNTIME_CHECKS_RESTORE
// - GetFrameHeight() // - GetFrameHeight()
// - GetFrameHeightWithSpacing() // - GetFrameHeightWithSpacing()
// - GetContentRegionMax() // - GetContentRegionMax()
// - GetContentRegionMaxAbs() [Internal]
// - GetContentRegionAvail(), // - GetContentRegionAvail(),
// - BeginGroup() // - BeginGroup()
// - EndGroup() // - EndGroup()
@ -10530,8 +10529,8 @@ float ImGui::CalcItemWidth()
w = window->DC.ItemWidth; w = window->DC.ItemWidth;
if (w < 0.0f) if (w < 0.0f)
{ {
float region_max_x = GetContentRegionMaxAbs().x; float region_avail_x = GetContentRegionAvail().x;
w = ImMax(1.0f, region_max_x - window->DC.CursorPos.x + w); w = ImMax(1.0f, region_avail_x + w);
} }
w = IM_TRUNC(w); w = IM_TRUNC(w);
return w; return w;
@ -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) // 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) ImVec2 ImGui::CalcItemSize(ImVec2 size, float default_w, float default_h)
{ {
ImGuiContext& g = *GImGui; ImVec2 avail;
ImGuiWindow* window = g.CurrentWindow;
ImVec2 region_max;
if (size.x < 0.0f || size.y < 0.0f) if (size.x < 0.0f || size.y < 0.0f)
region_max = GetContentRegionMaxAbs(); avail = GetContentRegionAvail();
if (size.x == 0.0f) if (size.x == 0.0f)
size.x = default_w; size.x = default_w;
else if (size.x < 0.0f) 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) if (size.y == 0.0f)
size.y = default_h; size.y = default_h;
else if (size.y < 0.0f) 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; return size;
} }
@ -10587,8 +10583,15 @@ float ImGui::GetFrameHeightWithSpacing()
return g.FontSize + g.Style.FramePadding.y * 2.0f + g.Style.ItemSpacing.y; 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! 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->DC.CursorPos;
}
// 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!). // FIXME: This is in window space (not screen space!).
ImVec2 ImGui::GetContentRegionMax() ImVec2 ImGui::GetContentRegionMax()
{ {
@ -10598,21 +10601,6 @@ ImVec2 ImGui::GetContentRegionMax()
return mx - window->Pos; return mx - window->Pos;
} }
// [Internal] Absolute coordinate. Saner. This is not exposed until we finishing refactoring work rect features.
ImVec2 ImGui::GetContentRegionMaxAbs()
{
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;
}
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
// You should never need those functions. Always use GetCursorScreenPos() and GetContentRegionAvail()! // You should never need those functions. Always use GetCursorScreenPos() and GetContentRegionAvail()!
// They are bizarre local-coordinates which don't play well with scrolling. // They are bizarre local-coordinates which don't play well with scrolling.

View File

@ -3217,7 +3217,6 @@ namespace ImGui
IMGUI_API ImVec2 CalcItemSize(ImVec2 size, float default_w, float default_h); 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 float CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x);
IMGUI_API void PushMultiItemsWidths(int components, float width_full); IMGUI_API void PushMultiItemsWidths(int components, float width_full);
IMGUI_API ImVec2 GetContentRegionMaxAbs();
IMGUI_API void ShrinkWidths(ImGuiShrinkWidthItem* items, int count, float width_excess); IMGUI_API void ShrinkWidths(ImGuiShrinkWidthItem* items, int count, float width_excess);
// Parameter stacks (shared) // Parameter stacks (shared)