mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-06 04:58:47 +02:00
Internals: maintaining focus order inside windows + only storing root windows in WindowsFocusOrder[] array. (toward #2304)
This commit is contained in:
50
imgui.cpp
50
imgui.cpp
@ -4034,7 +4034,7 @@ void ImGui::NewFrame()
|
||||
UpdateTabFocus();
|
||||
|
||||
// Mark all windows as not visible and compact unused memory.
|
||||
IM_ASSERT(g.WindowsFocusOrder.Size == g.Windows.Size);
|
||||
IM_ASSERT(g.WindowsFocusOrder.Size <= g.Windows.Size);
|
||||
const float memory_compact_start_time = (g.GcCompactAll || g.IO.ConfigMemoryCompactTimer < 0.0f) ? FLT_MAX : (float)g.Time - g.IO.ConfigMemoryCompactTimer;
|
||||
for (int i = 0; i != g.Windows.Size; i++)
|
||||
{
|
||||
@ -5143,7 +5143,12 @@ static ImGuiWindow* CreateNewWindow(const char* name, ImGuiWindowFlags flags)
|
||||
window->AutoFitOnlyGrows = (window->AutoFitFramesX > 0) || (window->AutoFitFramesY > 0);
|
||||
}
|
||||
|
||||
g.WindowsFocusOrder.push_back(window);
|
||||
if (!(flags & ImGuiWindowFlags_ChildWindow))
|
||||
{
|
||||
g.WindowsFocusOrder.push_back(window);
|
||||
window->FocusOrder = (short)(g.WindowsFocusOrder.Size - 1);
|
||||
}
|
||||
|
||||
if (flags & ImGuiWindowFlags_NoBringToFrontOnFocus)
|
||||
g.Windows.push_front(window); // Quite slow but rare and only once
|
||||
else
|
||||
@ -6378,15 +6383,22 @@ void ImGui::End()
|
||||
void ImGui::BringWindowToFocusFront(ImGuiWindow* window)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
IM_ASSERT(window == window->RootWindow);
|
||||
|
||||
const int cur_order = window->FocusOrder;
|
||||
IM_ASSERT(g.WindowsFocusOrder[cur_order] == window);
|
||||
if (g.WindowsFocusOrder.back() == window)
|
||||
return;
|
||||
for (int i = g.WindowsFocusOrder.Size - 2; i >= 0; i--) // We can ignore the top-most window
|
||||
if (g.WindowsFocusOrder[i] == window)
|
||||
{
|
||||
memmove(&g.WindowsFocusOrder[i], &g.WindowsFocusOrder[i + 1], (size_t)(g.WindowsFocusOrder.Size - i - 1) * sizeof(ImGuiWindow*));
|
||||
g.WindowsFocusOrder[g.WindowsFocusOrder.Size - 1] = window;
|
||||
break;
|
||||
}
|
||||
|
||||
const int new_order = g.WindowsFocusOrder.Size - 1;
|
||||
for (int n = cur_order; n < new_order; n++)
|
||||
{
|
||||
g.WindowsFocusOrder[n] = g.WindowsFocusOrder[n + 1];
|
||||
g.WindowsFocusOrder[n]->FocusOrder--;
|
||||
IM_ASSERT(g.WindowsFocusOrder[n]->FocusOrder == n);
|
||||
}
|
||||
g.WindowsFocusOrder[new_order] = window;
|
||||
window->FocusOrder = (short)new_order;
|
||||
}
|
||||
|
||||
void ImGui::BringWindowToDisplayFront(ImGuiWindow* window)
|
||||
@ -6466,18 +6478,13 @@ void ImGui::FocusTopMostWindowUnderOne(ImGuiWindow* under_this_window, ImGuiWind
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
|
||||
int start_idx = g.WindowsFocusOrder.Size - 1;
|
||||
if (under_this_window != NULL)
|
||||
{
|
||||
int under_this_window_idx = FindWindowFocusIndex(under_this_window);
|
||||
if (under_this_window_idx != -1)
|
||||
start_idx = under_this_window_idx - 1;
|
||||
}
|
||||
const int start_idx = ((under_this_window != NULL) ? FindWindowFocusIndex(under_this_window) : g.WindowsFocusOrder.Size) - 1;
|
||||
for (int i = start_idx; i >= 0; i--)
|
||||
{
|
||||
// We may later decide to test for different NoXXXInputs based on the active navigation input (mouse vs nav) but that may feel more confusing to the user.
|
||||
ImGuiWindow* window = g.WindowsFocusOrder[i];
|
||||
if (window != ignore_window && window->WasActive && !(window->Flags & ImGuiWindowFlags_ChildWindow))
|
||||
IM_ASSERT(window == window->RootWindow);
|
||||
if (window != ignore_window && window->WasActive)
|
||||
if ((window->Flags & (ImGuiWindowFlags_NoMouseInputs | ImGuiWindowFlags_NoNavInputs)) != (ImGuiWindowFlags_NoMouseInputs | ImGuiWindowFlags_NoNavInputs))
|
||||
{
|
||||
ImGuiWindow* focus_window = NavRestoreLastChildNavWindow(window);
|
||||
@ -9479,13 +9486,12 @@ static void ImGui::NavEndFrame()
|
||||
}
|
||||
}
|
||||
|
||||
static int ImGui::FindWindowFocusIndex(ImGuiWindow* window) // FIXME-OPT O(N)
|
||||
static int ImGui::FindWindowFocusIndex(ImGuiWindow* window)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
for (int i = g.WindowsFocusOrder.Size - 1; i >= 0; i--)
|
||||
if (g.WindowsFocusOrder[i] == window)
|
||||
return i;
|
||||
return -1;
|
||||
int order = window->FocusOrder;
|
||||
IM_ASSERT(g.WindowsFocusOrder[order] == window);
|
||||
return order;
|
||||
}
|
||||
|
||||
static ImGuiWindow* FindWindowNavFocusable(int i_start, int i_stop, int dir) // FIXME-OPT O(N)
|
||||
|
Reference in New Issue
Block a user