Skip to content

Commit aad86b8

Browse files
committed
Obsoleted GetWindowContentRegionMin() and GetWindowContentRegionMax().
You should never need those functions. You can do everything with GetCursorScreenPos() and GetContentRegionAvail().
1 parent 55f54fa commit aad86b8

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

docs/CHANGELOG.txt

+6
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ Breaking changes:
4646
- new: io.PlatformSetImeDataFn(ImGuiContext* ctx, ImGuiViewport* viewport, ImGuiPlatformImeData* data);
4747
It is expected that for a vast majority of users this is automatically set by core
4848
library and/or platform backend so it won't have any effect.
49+
- Obsoleted GetWindowContentRegionMin() and GetWindowContentRegionMax().
50+
You should never need those functions. Always use GetCursorScreenPos() and GetContentRegionAvail().
51+
Also consider that if you are using GetWindowPos() and GetCursorPos() you may also be making things
52+
unnecessarily complicated. You can do everything with GetCursorScreenPos() and GetContentRegionAvail()!!
53+
- GetWindowContentRegionMax().x - GetCursorPos().x --> GetContentRegionAvail().x
54+
- GetWindowContentRegionMax().x + GetWindowPos().x --> GetCursorScreenPos().x + GetContentRegionAvail().x
4955
- Item flag changes:
5056
- Obsoleted PushButtonRepeat()/PopButtonRepeat() in favor of using new PushItemFlag()/PopItemFlag()
5157
with ImGuiItemFlags_ButtonRepeat. Kept inline redirecting functions (will obsolete).

imgui.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,11 @@ CODE
430430
When you are not sure about an old symbol or function name, try using the Search/Find function of your IDE to look for comments or references in all imgui files.
431431
You can read releases logs https://github.com/ocornut/imgui/releases for more details.
432432

433+
- 2024/07/25 (1.91.0) - obsoleted GetWindowContentRegionMin() and GetWindowContentRegionMax(). You should never need those functions. Always use GetCursorScreenPos() and GetContentRegionAvail().
434+
- instead of: GetWindowContentRegionMax().x - GetCursorPos().x
435+
- you can use: GetContentRegionAvail().x
436+
- instead of: GetWindowContentRegionMax().x + GetWindowPos().x
437+
- you can use: GetCursorScreenPos().x + GetContentRegionAvail().x (from left edge of window)
433438
- 2024/07/15 (1.91.0) - renamed ImGuiSelectableFlags_DontClosePopups to ImGuiSelectableFlags_NoAutoClosePopups. (#1379, #1468, #2200, #4936, #5216, #7302, #7573)
434439
(internals: also renamed ImGuiItemFlags_SelectableDontClosePopup into ImGuiItemFlags_AutoClosePopups with inverted behaviors)
435440
- 2024/07/15 (1.91.0) - obsoleted PushButtonRepeat()/PopButtonRepeat() in favor of using new PushItemFlag(ImGuiItemFlags_ButtonRepeat, ...)/PopItemFlag().
@@ -10609,7 +10614,9 @@ ImVec2 ImGui::GetContentRegionAvail()
1060910614
return GetContentRegionMaxAbs() - window->DC.CursorPos;
1061010615
}
1061110616

10612-
// In window space (not screen space!)
10617+
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
10618+
// You should never need those functions. Always use GetCursorScreenPos() and GetContentRegionAvail()!
10619+
// They are bizarre local-coordinates which don't play well with scrolling.
1061310620
ImVec2 ImGui::GetWindowContentRegionMin()
1061410621
{
1061510622
ImGuiWindow* window = GImGui->CurrentWindow;
@@ -10621,6 +10628,7 @@ ImVec2 ImGui::GetWindowContentRegionMax()
1062110628
ImGuiWindow* window = GImGui->CurrentWindow;
1062210629
return window->ContentRegionRect.Max - window->Pos;
1062310630
}
10631+
#endif
1062410632

1062510633
// Lock horizontal starting position + capture group bounding box into one "item" (so you can use IsItemHovered() or layout primitives such as SameLine() on whole group, etc.)
1062610634
// Groups are currently a mishmash of functionalities which should perhaps be clarified and separated.

imgui.h

+7-6
Original file line numberDiff line numberDiff line change
@@ -392,10 +392,10 @@ namespace ImGui
392392
IMGUI_API bool IsWindowFocused(ImGuiFocusedFlags flags=0); // is current window focused? or its root/child, depending on flags. see flags for options.
393393
IMGUI_API bool IsWindowHovered(ImGuiHoveredFlags flags=0); // is current window hovered and hoverable (e.g. not blocked by a popup/modal)? See ImGuiHoveredFlags_ for options. IMPORTANT: If you are trying to check whether your mouse should be dispatched to Dear ImGui or to your underlying app, you should not use this function! Use the 'io.WantCaptureMouse' boolean for that! Refer to FAQ entry "How can I tell whether to dispatch mouse/keyboard to Dear ImGui or my application?" for details.
394394
IMGUI_API ImDrawList* GetWindowDrawList(); // get draw list associated to the current window, to append your own drawing primitives
395-
IMGUI_API ImVec2 GetWindowPos(); // get current window position in screen space (note: it is unlikely you need to use this. Consider using current layout pos instead, GetCursorScreenPos())
396-
IMGUI_API ImVec2 GetWindowSize(); // get current window size (note: it is unlikely you need to use this. Consider using GetCursorScreenPos() and e.g. GetContentRegionAvail() instead)
397-
IMGUI_API float GetWindowWidth(); // get current window width (shortcut for GetWindowSize().x)
398-
IMGUI_API float GetWindowHeight(); // get current window height (shortcut for GetWindowSize().y)
395+
IMGUI_API ImVec2 GetWindowPos(); // get current window position in screen space (IT IS UNLIKELY YOU EVER NEED TO USE THIS. Consider always using GetCursorScreenPos() and GetContentRegionAvail() instead)
396+
IMGUI_API ImVec2 GetWindowSize(); // get current window size (IT IS UNLIKELY YOU EVER NEED TO USE THIS. Consider always using GetCursorScreenPos() and GetContentRegionAvail() instead)
397+
IMGUI_API float GetWindowWidth(); // get current window width (IT IS UNLIKELY YOU EVER NEED TO USE THIS). Shortcut for GetWindowSize().x.
398+
IMGUI_API float GetWindowHeight(); // get current window height (IT IS UNLIKELY YOU EVER NEED TO USE THIS). Shortcut for GetWindowSize().y.
399399

400400
// Window manipulation
401401
// - Prefer using SetNextXXX functions (before Begin) rather that SetXXX functions (after Begin).
@@ -422,8 +422,6 @@ namespace ImGui
422422
// - Those functions are bound to be redesigned (they are confusing, incomplete and the Min/Max return values are in local window coordinates which increases confusion)
423423
IMGUI_API ImVec2 GetContentRegionAvail(); // == GetContentRegionMax() - GetCursorPos()
424424
IMGUI_API ImVec2 GetContentRegionMax(); // current content boundaries (typically window boundaries including scrolling, or current column boundaries), in windows coordinates
425-
IMGUI_API ImVec2 GetWindowContentRegionMin(); // content boundaries min for the full window (roughly (0,0)-Scroll), in window coordinates
426-
IMGUI_API ImVec2 GetWindowContentRegionMax(); // content boundaries max for the full window (roughly (0,0)+Size-Scroll) where Size can be overridden with SetNextWindowContentSize(), in window coordinates
427425

428426
// Windows Scrolling
429427
// - Any change of Scroll will be applied at the beginning of next frame in the first call to Begin().
@@ -473,6 +471,7 @@ namespace ImGui
473471
// - By "cursor" we mean the current output position.
474472
// - The typical widget behavior is to output themselves at the current cursor position, then move the cursor one line down.
475473
// - You can call SameLine() between widgets to undo the last carriage return and output at the right of the preceding widget.
474+
// - YOU CAN DO 99% OF WHAT YOU NEED WITH ONLY GetCursorScreenPos() and GetContentRegionAvail().
476475
// - Attention! We currently have inconsistencies between window-local and absolute positions we will aim to fix with future API:
477476
// - Absolute coordinate: GetCursorScreenPos(), SetCursorScreenPos(), all ImDrawList:: functions. -> this is the preferred way forward.
478477
// - Window-local coordinates: SameLine(), GetCursorPos(), SetCursorPos(), GetCursorStartPos(), GetContentRegionMax(), GetWindowContentRegion*(), PushTextWrapPos()
@@ -3504,6 +3503,8 @@ namespace ImGui
35043503
static inline void PopButtonRepeat() { PopItemFlag(); }
35053504
static inline void PushTabStop(bool tab_stop) { PushItemFlag(ImGuiItemFlags_NoTabStop, !tab_stop); }
35063505
static inline void PopTabStop() { PopItemFlag(); }
3506+
IMGUI_API ImVec2 GetWindowContentRegionMin(); // Content boundaries min for the window (roughly (0,0)-Scroll), in window-local coordinates. You should never need this. Always use GetCursorScreenPos() and GetContentRegionAvail()!
3507+
IMGUI_API ImVec2 GetWindowContentRegionMax(); // Content boundaries max for the window (roughly (0,0)+Size-Scroll), in window-local coordinates. You should never need this. Always use GetCursorScreenPos() and GetContentRegionAvail()!
35073508
// OBSOLETED in 1.90.0 (from September 2023)
35083509
static inline bool BeginChildFrame(ImGuiID id, const ImVec2& size, ImGuiWindowFlags window_flags = 0) { return BeginChild(id, size, ImGuiChildFlags_FrameStyle, window_flags); }
35093510
static inline void EndChildFrame() { EndChild(); }

imgui_demo.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3918,7 +3918,7 @@ static void ShowDemoWindowLayout()
39183918
ImGui::Text("Manual wrapping:");
39193919
ImGuiStyle& style = ImGui::GetStyle();
39203920
int buttons_count = 20;
3921-
float window_visible_x2 = ImGui::GetWindowPos().x + ImGui::GetWindowContentRegionMax().x;
3921+
float window_visible_x2 = ImGui::GetCursorScreenPos().x + ImGui::GetContentRegionAvail().x;
39223922
for (int n = 0; n < buttons_count; n++)
39233923
{
39243924
ImGui::PushID(n);

0 commit comments

Comments
 (0)