1
0
mirror of https://github.com/ocornut/imgui.git synced 2025-02-02 20:47:23 +01:00

Refactor: moved FindBlockingModal() in its section.

This commit is contained in:
ocornut 2025-01-08 12:43:56 +01:00
parent e6a7c7689f
commit bbbdc70f26

View File

@ -3542,7 +3542,6 @@ const char* ImGui::GetStyleColorName(ImGuiCol idx)
return "Unknown"; return "Unknown";
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// [SECTION] RENDER HELPERS // [SECTION] RENDER HELPERS
// Some of those (internal) functions are currently quite a legacy mess - their signature and behavior will change, // Some of those (internal) functions are currently quite a legacy mess - their signature and behavior will change,
@ -4252,7 +4251,6 @@ void ImGui::CallContextHooks(ImGuiContext* ctx, ImGuiContextHookType hook_type)
hook.Callback(&g, &hook); hook.Callback(&g, &hook);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// [SECTION] MAIN CODE (most of the code! lots of stuff, needs tidying up!) // [SECTION] MAIN CODE (most of the code! lots of stuff, needs tidying up!)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -6957,42 +6955,6 @@ static void SetWindowActiveForSkipRefresh(ImGuiWindow* window)
} }
} }
// When a modal popup is open, newly created windows that want focus (i.e. are not popups and do not specify ImGuiWindowFlags_NoFocusOnAppearing)
// should be positioned behind that modal window, unless the window was created inside the modal begin-stack.
// In case of multiple stacked modals newly created window honors begin stack order and does not go below its own modal parent.
// - WindowA // FindBlockingModal() returns Modal1
// - WindowB // .. returns Modal1
// - Modal1 // .. returns Modal2
// - WindowC // .. returns Modal2
// - WindowD // .. returns Modal2
// - Modal2 // .. returns Modal2
// - WindowE // .. returns NULL
// Notes:
// - FindBlockingModal(NULL) == NULL is generally equivalent to GetTopMostPopupModal() == NULL.
// Only difference is here we check for ->Active/WasActive but it may be unnecessary.
ImGuiWindow* ImGui::FindBlockingModal(ImGuiWindow* window)
{
ImGuiContext& g = *GImGui;
if (g.OpenPopupStack.Size <= 0)
return NULL;
// Find a modal that has common parent with specified window. Specified window should be positioned behind that modal.
for (ImGuiPopupData& popup_data : g.OpenPopupStack)
{
ImGuiWindow* popup_window = popup_data.Window;
if (popup_window == NULL || !(popup_window->Flags & ImGuiWindowFlags_Modal))
continue;
if (!popup_window->Active && !popup_window->WasActive) // Check WasActive, because this code may run before popup renders on current frame, also check Active to handle newly created windows.
continue;
if (window == NULL) // FindBlockingModal(NULL) test for if FocusWindow(NULL) is naturally possible via a mouse click.
return popup_window;
if (IsWindowWithinBeginStackOf(window, popup_window)) // Window may be over modal
continue;
return popup_window; // Place window right below first block modal
}
return NULL;
}
// Push a new Dear ImGui window to add widgets to. // Push a new Dear ImGui window to add widgets to.
// - A default window called "Debug" is automatically stacked at the beginning of every frame so you can use widgets without explicitly calling a Begin/End pair. // - A default window called "Debug" is automatically stacked at the beginning of every frame so you can use widgets without explicitly calling a Begin/End pair.
// - Begin/End can be called multiple times during the frame with the same window name to append content. // - Begin/End can be called multiple times during the frame with the same window name to append content.
@ -8276,14 +8238,6 @@ bool ImGui::IsWindowFocused(ImGuiFocusedFlags flags)
return (ref_window == cur_window); return (ref_window == cur_window);
} }
// Can we focus this window with CTRL+TAB (or PadMenu + PadFocusPrev/PadFocusNext)
// Note that NoNavFocus makes the window not reachable with CTRL+TAB but it can still be focused with mouse or programmatically.
// If you want a window to never be focused, you may use the e.g. NoInputs flag.
bool ImGui::IsWindowNavFocusable(ImGuiWindow* window)
{
return window->WasActive && window == window->RootWindow && !(window->Flags & ImGuiWindowFlags_NoNavFocus);
}
float ImGui::GetWindowWidth() float ImGui::GetWindowWidth()
{ {
ImGuiWindow* window = GImGui->CurrentWindow; ImGuiWindow* window = GImGui->CurrentWindow;
@ -10308,7 +10262,6 @@ bool ImGui::Shortcut(ImGuiKeyChord key_chord, ImGuiInputFlags flags, ImGuiID own
return true; return true;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// [SECTION] ERROR CHECKING, STATE RECOVERY // [SECTION] ERROR CHECKING, STATE RECOVERY
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -11655,6 +11608,43 @@ ImGuiWindow* ImGui::GetTopMostAndVisiblePopupModal()
return NULL; return NULL;
} }
// When a modal popup is open, newly created windows that want focus (i.e. are not popups and do not specify ImGuiWindowFlags_NoFocusOnAppearing)
// should be positioned behind that modal window, unless the window was created inside the modal begin-stack.
// In case of multiple stacked modals newly created window honors begin stack order and does not go below its own modal parent.
// - WindowA // FindBlockingModal() returns Modal1
// - WindowB // .. returns Modal1
// - Modal1 // .. returns Modal2
// - WindowC // .. returns Modal2
// - WindowD // .. returns Modal2
// - Modal2 // .. returns Modal2
// - WindowE // .. returns NULL
// Notes:
// - FindBlockingModal(NULL) == NULL is generally equivalent to GetTopMostPopupModal() == NULL.
// Only difference is here we check for ->Active/WasActive but it may be unnecessary.
ImGuiWindow* ImGui::FindBlockingModal(ImGuiWindow* window)
{
ImGuiContext& g = *GImGui;
if (g.OpenPopupStack.Size <= 0)
return NULL;
// Find a modal that has common parent with specified window. Specified window should be positioned behind that modal.
for (ImGuiPopupData& popup_data : g.OpenPopupStack)
{
ImGuiWindow* popup_window = popup_data.Window;
if (popup_window == NULL || !(popup_window->Flags & ImGuiWindowFlags_Modal))
continue;
if (!popup_window->Active && !popup_window->WasActive) // Check WasActive, because this code may run before popup renders on current frame, also check Active to handle newly created windows.
continue;
if (window == NULL) // FindBlockingModal(NULL) test for if FocusWindow(NULL) is naturally possible via a mouse click.
return popup_window;
if (IsWindowWithinBeginStackOf(window, popup_window)) // Window may be over modal
continue;
return popup_window; // Place window right below first block modal
}
return NULL;
}
void ImGui::OpenPopup(const char* str_id, ImGuiPopupFlags popup_flags) void ImGui::OpenPopup(const char* str_id, ImGuiPopupFlags popup_flags)
{ {
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
@ -13524,6 +13514,14 @@ static int ImGui::FindWindowFocusIndex(ImGuiWindow* window)
return order; return order;
} }
// Can we focus this window with CTRL+TAB (or PadMenu + PadFocusPrev/PadFocusNext)
// Note that NoNavFocus makes the window not reachable with CTRL+TAB but it can still be focused with mouse or programmatically.
// If you want a window to never be focused, you may use the e.g. NoInputs flag.
bool ImGui::IsWindowNavFocusable(ImGuiWindow* window)
{
return window->WasActive && window == window->RootWindow && !(window->Flags & ImGuiWindowFlags_NoNavFocus);
}
static ImGuiWindow* FindWindowNavFocusable(int i_start, int i_stop, int dir) // FIXME-OPT O(N) static ImGuiWindow* FindWindowNavFocusable(int i_start, int i_stop, int dir) // FIXME-OPT O(N)
{ {
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
@ -13801,7 +13799,6 @@ void ImGui::NavUpdateWindowingOverlay()
PopStyleVar(); PopStyleVar();
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// [SECTION] DRAG AND DROP // [SECTION] DRAG AND DROP
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -14410,7 +14407,6 @@ void ImGui::LogButtons()
LogToClipboard(); LogToClipboard();
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// [SECTION] SETTINGS // [SECTION] SETTINGS
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -14770,7 +14766,6 @@ static void WindowSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandl
} }
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// [SECTION] LOCALIZATION // [SECTION] LOCALIZATION
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -14782,7 +14777,6 @@ void ImGui::LocalizeRegisterEntries(const ImGuiLocEntry* entries, int count)
g.LocalizationTable[entries[n].Key] = entries[n].Text; g.LocalizationTable[entries[n].Key] = entries[n].Text;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// [SECTION] VIEWPORTS, PLATFORM WINDOWS // [SECTION] VIEWPORTS, PLATFORM WINDOWS
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------