Using range-based for where it makes sense. (#4537)

Amend 82d177c
features/sdl_renderer3_multiviewports v1.89.9-docking
ocornut ago%!(EXTRA string=2 years)
parent a1b60fc1f5
commit 1d8e48c161
  1. 96
      imgui.cpp
  2. 2
      imgui_demo.cpp

@ -5208,9 +5208,8 @@ static void ImGui::RenderDimmedBackgrounds()
} }
// Draw dimming background on _other_ viewports than the ones our windows are in // Draw dimming background on _other_ viewports than the ones our windows are in
for (int viewport_n = 0; viewport_n < g.Viewports.Size; viewport_n++) for (ImGuiViewportP* viewport : g.Viewports)
{ {
ImGuiViewportP* viewport = g.Viewports[viewport_n];
if (viewport == viewports_already_dimmed[0] || viewport == viewports_already_dimmed[1]) if (viewport == viewports_already_dimmed[0] || viewport == viewports_already_dimmed[1])
continue; continue;
if (modal_window && viewport->Window && IsWindowAbove(viewport->Window, modal_window)) if (modal_window && viewport->Window && IsWindowAbove(viewport->Window, modal_window))
@ -9860,9 +9859,8 @@ static void ImGui::ErrorCheckNewFrameSanityChecks()
} }
// Perform simple checks on platform monitor data + compute a total bounding box for quick early outs // Perform simple checks on platform monitor data + compute a total bounding box for quick early outs
for (int monitor_n = 0; monitor_n < g.PlatformIO.Monitors.Size; monitor_n++) for (ImGuiPlatformMonitor& mon : g.PlatformIO.Monitors)
{ {
ImGuiPlatformMonitor& mon = g.PlatformIO.Monitors[monitor_n];
IM_UNUSED(mon); IM_UNUSED(mon);
IM_ASSERT(mon.MainSize.x > 0.0f && mon.MainSize.y > 0.0f && "Monitor main bounds not setup properly."); IM_ASSERT(mon.MainSize.x > 0.0f && mon.MainSize.y > 0.0f && "Monitor main bounds not setup properly.");
IM_ASSERT(ImRect(mon.MainPos, mon.MainPos + mon.MainSize).Contains(ImRect(mon.WorkPos, mon.WorkPos + mon.WorkSize)) && "Monitor work bounds not setup properly. If you don't have work area information, just copy MainPos/MainSize into them."); IM_ASSERT(ImRect(mon.MainPos, mon.MainPos + mon.MainSize).Contains(ImRect(mon.WorkPos, mon.WorkPos + mon.WorkSize)) && "Monitor work bounds not setup properly. If you don't have work area information, just copy MainPos/MainSize into them.");
@ -10909,8 +10907,8 @@ bool ImGui::IsPopupOpen(ImGuiID id, ImGuiPopupFlags popup_flags)
if (popup_flags & ImGuiPopupFlags_AnyPopupLevel) if (popup_flags & ImGuiPopupFlags_AnyPopupLevel)
{ {
// Return true if the popup is open anywhere in the popup stack // Return true if the popup is open anywhere in the popup stack
for (int n = 0; n < g.OpenPopupStack.Size; n++) for (ImGuiPopupData& popup_data : g.OpenPopupStack)
if (g.OpenPopupStack[n].PopupId == id) if (popup_data.PopupId == id)
return true; return true;
return false; return false;
} }
@ -13989,18 +13987,18 @@ ImGuiViewport* ImGui::GetMainViewport()
ImGuiViewport* ImGui::FindViewportByID(ImGuiID id) ImGuiViewport* ImGui::FindViewportByID(ImGuiID id)
{ {
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
for (int n = 0; n < g.Viewports.Size; n++) for (ImGuiViewportP* viewport : g.Viewports)
if (g.Viewports[n]->ID == id) if (viewport->ID == id)
return g.Viewports[n]; return viewport;
return NULL; return NULL;
} }
ImGuiViewport* ImGui::FindViewportByPlatformHandle(void* platform_handle) ImGuiViewport* ImGui::FindViewportByPlatformHandle(void* platform_handle)
{ {
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
for (int i = 0; i != g.Viewports.Size; i++) for (ImGuiViewportP* viewport : g.Viewports)
if (g.Viewports[i]->PlatformHandle == platform_handle) if (viewport->PlatformHandle == platform_handle)
return g.Viewports[i]; return viewport;
return NULL; return NULL;
} }
@ -14062,9 +14060,8 @@ static bool ImGui::UpdateTryMergeWindowIntoHostViewport(ImGuiWindow* window, ImG
return false; return false;
// FIXME: Can't use g.WindowsFocusOrder[] for root windows only as we care about Z order. If we maintained a DisplayOrder along with FocusOrder we could.. // FIXME: Can't use g.WindowsFocusOrder[] for root windows only as we care about Z order. If we maintained a DisplayOrder along with FocusOrder we could..
for (int n = 0; n < g.Windows.Size; n++) for (ImGuiWindow* window_behind : g.Windows)
{ {
ImGuiWindow* window_behind = g.Windows[n];
if (window_behind == window) if (window_behind == window)
break; break;
if (window_behind->WasActive && window_behind->ViewportOwned && !(window_behind->Flags & ImGuiWindowFlags_ChildWindow)) if (window_behind->WasActive && window_behind->ViewportOwned && !(window_behind->Flags & ImGuiWindowFlags_ChildWindow))
@ -14106,9 +14103,9 @@ void ImGui::TranslateWindowsInViewport(ImGuiViewportP* viewport, const ImVec2& o
const bool translate_all_windows = (g.ConfigFlagsCurrFrame & ImGuiConfigFlags_ViewportsEnable) != (g.ConfigFlagsLastFrame & ImGuiConfigFlags_ViewportsEnable); const bool translate_all_windows = (g.ConfigFlagsCurrFrame & ImGuiConfigFlags_ViewportsEnable) != (g.ConfigFlagsLastFrame & ImGuiConfigFlags_ViewportsEnable);
ImRect test_still_fit_rect(old_pos, old_pos + viewport->Size); ImRect test_still_fit_rect(old_pos, old_pos + viewport->Size);
ImVec2 delta_pos = new_pos - old_pos; ImVec2 delta_pos = new_pos - old_pos;
for (int window_n = 0; window_n < g.Windows.Size; window_n++) // FIXME-OPT for (ImGuiWindow* window : g.Windows) // FIXME-OPT
if (translate_all_windows || (g.Windows[window_n]->Viewport == viewport && test_still_fit_rect.Contains(g.Windows[window_n]->Rect()))) if (translate_all_windows || (window->Viewport == viewport && test_still_fit_rect.Contains(window->Rect())))
TranslateWindow(g.Windows[window_n], delta_pos); TranslateWindow(window, delta_pos);
} }
// Scale all windows (position, size). Use when e.g. changing DPI. (This is a lossy operation!) // Scale all windows (position, size). Use when e.g. changing DPI. (This is a lossy operation!)
@ -14121,9 +14118,9 @@ void ImGui::ScaleWindowsInViewport(ImGuiViewportP* viewport, float scale)
} }
else else
{ {
for (int i = 0; i != g.Windows.Size; i++) for (ImGuiWindow* window : g.Windows)
if (g.Windows[i]->Viewport == viewport) if (window->Viewport == viewport)
ScaleWindow(g.Windows[i], scale); ScaleWindow(window, scale);
} }
} }
@ -14134,13 +14131,10 @@ ImGuiViewportP* ImGui::FindHoveredViewportFromPlatformWindowStack(const ImVec2&
{ {
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
ImGuiViewportP* best_candidate = NULL; ImGuiViewportP* best_candidate = NULL;
for (int n = 0; n < g.Viewports.Size; n++) for (ImGuiViewportP* viewport : g.Viewports)
{
ImGuiViewportP* viewport = g.Viewports[n];
if (!(viewport->Flags & (ImGuiViewportFlags_NoInputs | ImGuiViewportFlags_IsMinimized)) && viewport->GetMainRect().Contains(mouse_platform_pos)) if (!(viewport->Flags & (ImGuiViewportFlags_NoInputs | ImGuiViewportFlags_IsMinimized)) && viewport->GetMainRect().Contains(mouse_platform_pos))
if (best_candidate == NULL || best_candidate->LastFocusedStampCount < viewport->LastFocusedStampCount) if (best_candidate == NULL || best_candidate->LastFocusedStampCount < viewport->LastFocusedStampCount)
best_candidate = viewport; best_candidate = viewport;
}
return best_candidate; return best_candidate;
} }
@ -14157,9 +14151,8 @@ static void ImGui::UpdateViewportsNewFrame()
if (viewports_enabled) if (viewports_enabled)
{ {
ImGuiViewportP* focused_viewport = NULL; ImGuiViewportP* focused_viewport = NULL;
for (int n = 0; n < g.Viewports.Size; n++) for (ImGuiViewportP* viewport : g.Viewports)
{ {
ImGuiViewportP* viewport = g.Viewports[n];
const bool platform_funcs_available = viewport->PlatformWindowCreated; const bool platform_funcs_available = viewport->PlatformWindowCreated;
if (g.PlatformIO.Platform_GetWindowMinimized && platform_funcs_available) if (g.PlatformIO.Platform_GetWindowMinimized && platform_funcs_available)
{ {
@ -14459,9 +14452,8 @@ static void ImGui::DestroyViewport(ImGuiViewportP* viewport)
{ {
// Clear references to this viewport in windows (window->ViewportId becomes the master data) // Clear references to this viewport in windows (window->ViewportId becomes the master data)
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
for (int window_n = 0; window_n < g.Windows.Size; window_n++) for (ImGuiWindow* window : g.Windows)
{ {
ImGuiWindow* window = g.Windows[window_n];
if (window->Viewport != viewport) if (window->Viewport != viewport)
continue; continue;
window->Viewport = NULL; window->Viewport = NULL;
@ -14939,8 +14931,8 @@ void ImGui::DestroyPlatformWindows()
// It is expected that the backend can handle calls to Renderer_DestroyWindow/Platform_DestroyWindow without // It is expected that the backend can handle calls to Renderer_DestroyWindow/Platform_DestroyWindow without
// crashing if it doesn't have data stored. // crashing if it doesn't have data stored.
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
for (int i = 0; i < g.Viewports.Size; i++) for (ImGuiViewportP* viewport : g.Viewports)
DestroyPlatformWindow(g.Viewports[i]); DestroyPlatformWindow(viewport);
} }
@ -15251,13 +15243,12 @@ void ImGui::DockContextNewFrameUpdateUndocking(ImGuiContext* ctx)
} }
// Process Undocking requests (we need to process them _before_ the UpdateMouseMovingWindowNewFrame call in NewFrame) // Process Undocking requests (we need to process them _before_ the UpdateMouseMovingWindowNewFrame call in NewFrame)
for (int n = 0; n < dc->Requests.Size; n++) for (ImGuiDockRequest& req : dc->Requests)
{ {
ImGuiDockRequest* req = &dc->Requests[n]; if (req.Type == ImGuiDockRequestType_Undock && req.UndockTargetWindow)
if (req->Type == ImGuiDockRequestType_Undock && req->UndockTargetWindow) DockContextProcessUndockWindow(ctx, req.UndockTargetWindow);
DockContextProcessUndockWindow(ctx, req->UndockTargetWindow); else if (req.Type == ImGuiDockRequestType_Undock && req.UndockTargetNode)
else if (req->Type == ImGuiDockRequestType_Undock && req->UndockTargetNode) DockContextProcessUndockNode(ctx, req.UndockTargetNode);
DockContextProcessUndockNode(ctx, req->UndockTargetNode);
} }
} }
@ -15282,9 +15273,9 @@ void ImGui::DockContextNewFrameUpdateDocking(ImGuiContext* ctx)
} }
// Process Docking requests // Process Docking requests
for (int n = 0; n < dc->Requests.Size; n++) for (ImGuiDockRequest& req : dc->Requests)
if (dc->Requests[n].Type == ImGuiDockRequestType_Dock) if (req.Type == ImGuiDockRequestType_Dock)
DockContextProcessDock(ctx, &dc->Requests[n]); DockContextProcessDock(ctx, &req);
dc->Requests.resize(0); dc->Requests.resize(0);
// Create windows for each automatic docking nodes // Create windows for each automatic docking nodes
@ -15488,9 +15479,8 @@ void ImGui::DockContextBuildAddWindowsToNodes(ImGuiContext* ctx, ImGuiID root_id
{ {
// Rebind all windows to nodes (they can also lazily rebind but we'll have a visible glitch during the first frame) // Rebind all windows to nodes (they can also lazily rebind but we'll have a visible glitch during the first frame)
ImGuiContext& g = *ctx; ImGuiContext& g = *ctx;
for (int n = 0; n < g.Windows.Size; n++) for (ImGuiWindow* window : g.Windows)
{ {
ImGuiWindow* window = g.Windows[n];
if (window->DockId == 0 || window->LastFrameActive < g.FrameCount - 1) if (window->DockId == 0 || window->LastFrameActive < g.FrameCount - 1)
continue; continue;
if (window->DockNode != NULL) if (window->DockNode != NULL)
@ -15549,9 +15539,9 @@ void ImGui::DockContextQueueUndockNode(ImGuiContext* ctx, ImGuiDockNode* node)
void ImGui::DockContextQueueNotifyRemovedNode(ImGuiContext* ctx, ImGuiDockNode* node) void ImGui::DockContextQueueNotifyRemovedNode(ImGuiContext* ctx, ImGuiDockNode* node)
{ {
ImGuiDockContext* dc = &ctx->DockContext; ImGuiDockContext* dc = &ctx->DockContext;
for (int n = 0; n < dc->Requests.Size; n++) for (ImGuiDockRequest& req : dc->Requests)
if (dc->Requests[n].DockTargetNode == node) if (req.DockTargetNode == node)
dc->Requests[n].Type = ImGuiDockRequestType_None; req.Type = ImGuiDockRequestType_None;
} }
void ImGui::DockContextProcessDock(ImGuiContext* ctx, ImGuiDockRequest* req) void ImGui::DockContextProcessDock(ImGuiContext* ctx, ImGuiDockRequest* req)
@ -15759,9 +15749,8 @@ void ImGui::DockContextProcessUndockNode(ImGuiContext* ctx, ImGuiDockNode* node)
node->ParentNode->AuthorityForViewport = ImGuiDataAuthority_Window; // The node that stays in place keeps the viewport, so our newly dragged out node will create a new viewport node->ParentNode->AuthorityForViewport = ImGuiDataAuthority_Window; // The node that stays in place keeps the viewport, so our newly dragged out node will create a new viewport
node->ParentNode = NULL; node->ParentNode = NULL;
} }
for (int n = 0; n < node->Windows.Size; n++) for (ImGuiWindow* window : node->Windows)
{ {
ImGuiWindow* window = node->Windows[n];
window->Flags &= ~ImGuiWindowFlags_ChildWindow; window->Flags &= ~ImGuiWindowFlags_ChildWindow;
if (window->ParentWindow) if (window->ParentWindow)
window->ParentWindow->DC.ChildWindows.find_erase(window); window->ParentWindow->DC.ChildWindows.find_erase(window);
@ -16046,10 +16035,10 @@ static void ImGui::DockNodeMoveWindows(ImGuiDockNode* dst_node, ImGuiDockNode* s
static void ImGui::DockNodeApplyPosSizeToWindows(ImGuiDockNode* node) static void ImGui::DockNodeApplyPosSizeToWindows(ImGuiDockNode* node)
{ {
for (int n = 0; n < node->Windows.Size; n++) for (ImGuiWindow* window : node->Windows)
{ {
SetWindowPos(node->Windows[n], node->Pos, ImGuiCond_Always); // We don't assign directly to Pos because it can break the calculation of SizeContents on next frame SetWindowPos(window, node->Pos, ImGuiCond_Always); // We don't assign directly to Pos because it can break the calculation of SizeContents on next frame
SetWindowSize(node->Windows[n], node->Size, ImGuiCond_Always); SetWindowSize(window, node->Size, ImGuiCond_Always);
} }
} }
@ -16108,9 +16097,9 @@ static void DockNodeFindInfo(ImGuiDockNode* node, ImGuiDockNodeTreeInfo* info)
static ImGuiWindow* ImGui::DockNodeFindWindowByID(ImGuiDockNode* node, ImGuiID id) static ImGuiWindow* ImGui::DockNodeFindWindowByID(ImGuiDockNode* node, ImGuiID id)
{ {
IM_ASSERT(id != 0); IM_ASSERT(id != 0);
for (int n = 0; n < node->Windows.Size; n++) for (ImGuiWindow* window : node->Windows)
if (node->Windows[n]->ID == id) if (window->ID == id)
return node->Windows[n]; return window;
return NULL; return NULL;
} }
@ -16375,10 +16364,9 @@ static void ImGui::DockNodeUpdate(ImGuiDockNode* node)
// Decide if the node will have a close button and a window menu button // Decide if the node will have a close button and a window menu button
node->HasWindowMenuButton = (node->Windows.Size > 0) && (node_flags & ImGuiDockNodeFlags_NoWindowMenuButton) == 0; node->HasWindowMenuButton = (node->Windows.Size > 0) && (node_flags & ImGuiDockNodeFlags_NoWindowMenuButton) == 0;
node->HasCloseButton = false; node->HasCloseButton = false;
for (int window_n = 0; window_n < node->Windows.Size; window_n++) for (ImGuiWindow* window : node->Windows)
{ {
// FIXME-DOCK: Setting DockIsActive here means that for single active window in a leaf node, DockIsActive will be cleared until the next Begin() call. // FIXME-DOCK: Setting DockIsActive here means that for single active window in a leaf node, DockIsActive will be cleared until the next Begin() call.
ImGuiWindow* window = node->Windows[window_n];
node->HasCloseButton |= window->HasCloseButton; node->HasCloseButton |= window->HasCloseButton;
window->DockIsActive = (node->Windows.Size > 1); window->DockIsActive = (node->Windows.Size > 1);
} }

@ -4907,7 +4907,7 @@ static void ShowDemoWindowTables()
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::Text("CellPadding.y = %.2f", style.CellPadding.y); ImGui::Text("CellPadding.y = %.2f", style.CellPadding.y);
if ((row % 3) == 2) if ((row % 3) == 2)
ImGui::PopStyleVar();; ImGui::PopStyleVar();
} }
ImGui::EndTable(); ImGui::EndTable();
} }

Loading…
Cancel
Save