@ -4169,7 +4169,7 @@ void ImGui::NewFrame()
UpdateTabFocus ( ) ;
UpdateTabFocus ( ) ;
// Mark all windows as not visible and compact unused memory.
// 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 ;
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 + + )
for ( int i = 0 ; i ! = g . Windows . Size ; i + + )
{
{
@ -5419,7 +5419,12 @@ static ImGuiWindow* CreateNewWindow(const char* name, ImGuiWindowFlags flags)
window - > AutoFitOnlyGrows = ( window - > AutoFitFramesX > 0 ) | | ( window - > AutoFitFramesY > 0 ) ;
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 )
if ( flags & ImGuiWindowFlags_NoBringToFrontOnFocus )
g . Windows . push_front ( window ) ; // Quite slow but rare and only once
g . Windows . push_front ( window ) ; // Quite slow but rare and only once
else
else
@ -6948,15 +6953,22 @@ void ImGui::End()
void ImGui : : BringWindowToFocusFront ( ImGuiWindow * window )
void ImGui : : BringWindowToFocusFront ( ImGuiWindow * window )
{
{
ImGuiContext & g = * GImGui ;
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 )
if ( g . WindowsFocusOrder . back ( ) = = window )
return ;
return ;
for ( int i = g . WindowsFocusOrder . Size - 2 ; i > = 0 ; i - - ) // We can ignore the top-most window
if ( g . WindowsFocusOrder [ i ] = = window )
const int new_order = g . WindowsFocusOrder . Size - 1 ;
{
for ( int n = cur_order ; n < new_order ; n + + )
memmove ( & g . WindowsFocusOrder [ i ] , & g . WindowsFocusOrder [ i + 1 ] , ( size_t ) ( g . WindowsFocusOrder . Size - i - 1 ) * sizeof ( ImGuiWindow * ) ) ;
{
g . WindowsFocusOrder [ g . WindowsFocusOrder . Size - 1 ] = window ;
g . WindowsFocusOrder [ n ] = g . WindowsFocusOrder [ n + 1 ] ;
break ;
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 )
void ImGui : : BringWindowToDisplayFront ( ImGuiWindow * window )
@ -7044,18 +7056,13 @@ void ImGui::FocusTopMostWindowUnderOne(ImGuiWindow* under_this_window, ImGuiWind
{
{
ImGuiContext & g = * GImGui ;
ImGuiContext & g = * GImGui ;
int start_idx = g . WindowsFocusOrder . Size - 1 ;
const int start_idx = ( ( under_this_window ! = NULL ) ? FindWindowFocusIndex ( under_this_window ) : 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 ;
}
for ( int i = start_idx ; i > = 0 ; i - - )
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.
// 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 ] ;
ImGuiWindow * window = g . WindowsFocusOrder [ i ] ;
if ( window ! = ignore_window & & window - > WasActive & & window - > RootWindow = = window )
IM_ASSERT ( window = = window - > RootWindow ) ;
if ( window ! = ignore_window & & window - > WasActive )
if ( ( window - > Flags & ( ImGuiWindowFlags_NoMouseInputs | ImGuiWindowFlags_NoNavInputs ) ) ! = ( ImGuiWindowFlags_NoMouseInputs | ImGuiWindowFlags_NoNavInputs ) )
if ( ( window - > Flags & ( ImGuiWindowFlags_NoMouseInputs | ImGuiWindowFlags_NoNavInputs ) ) ! = ( ImGuiWindowFlags_NoMouseInputs | ImGuiWindowFlags_NoNavInputs ) )
{
{
// FIXME-DOCK: This is failing (lagging by one frame) for docked windows.
// FIXME-DOCK: This is failing (lagging by one frame) for docked windows.
@ -10164,13 +10171,12 @@ static void ImGui::NavEndFrame()
}
}
}
}
static int ImGui : : FindWindowFocusIndex ( ImGuiWindow * window ) // FIXME-OPT O(N)
static int ImGui : : FindWindowFocusIndex ( ImGuiWindow * window )
{
{
ImGuiContext & g = * GImGui ;
ImGuiContext & g = * GImGui ;
for ( int i = g . WindowsFocusOrder . Size - 1 ; i > = 0 ; i - - )
int order = window - > FocusOrder ;
if ( g . WindowsFocusOrder [ i ] = = window )
IM_ASSERT ( g . WindowsFocusOrder [ order ] = = window ) ;
return i ;
return order ;
return - 1 ;
}
}
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)