mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-04 12:08:47 +02:00
Nav: Added a CTRL+TAB window list and changed the highlight system accordingly. (#787)
This commit is contained in:
97
imgui.cpp
97
imgui.cpp
@ -305,6 +305,7 @@
|
||||
When you are not sure about a old symbol or function name, try using the Search/Find function of your IDE to look for comments or references in all imgui files.
|
||||
You can read releases logs https://github.com/ocornut/imgui/releases for more details.
|
||||
|
||||
- 2018/07/08 (1.63) - style: renamed ImGuiCol_ModalWindowDarkening to ImGuiCol_ModalWindowDimBg for consistency with other features. Kept redirection enum (will obsolete).
|
||||
- 2018/07/06 (1.63) - removed per-window ImGuiWindowFlags_ResizeFromAnySide beta flag in favor of a global io.OptResizeWindowsFromEdges to enable the feature.
|
||||
- 2018/06/06 (1.62) - renamed GetGlyphRangesChinese() to GetGlyphRangesChineseFull() to distinguish other variants and discourage using the full set.
|
||||
- 2018/06/06 (1.62) - TreeNodeEx()/TreeNodeBehavior(): the ImGuiTreeNodeFlags_CollapsingHeader helper now include the ImGuiTreeNodeFlags_NoTreePushOnOpen flag. See Changelog for details.
|
||||
@ -896,6 +897,7 @@ static bool BeginChildEx(const char* name, ImGuiID id, const ImVec2&
|
||||
|
||||
static void NavUpdate();
|
||||
static void NavUpdateWindowing();
|
||||
static void NavUpdateWindowingList();
|
||||
static void NavProcessItem(ImGuiWindow* window, const ImRect& nav_bb, const ImGuiID id);
|
||||
|
||||
static void UpdateMouseInputs();
|
||||
@ -3051,7 +3053,8 @@ static void NavUpdateWindowingHighlightWindow(int focus_change_dir)
|
||||
ImGuiWindow* window_target = FindWindowNavigable(i_current + focus_change_dir, -INT_MAX, focus_change_dir);
|
||||
if (!window_target)
|
||||
window_target = FindWindowNavigable((focus_change_dir < 0) ? (g.Windows.Size - 1) : 0, i_current, focus_change_dir);
|
||||
g.NavWindowingTarget = window_target;
|
||||
if (window_target) // Don't reset windowing target if there's a single window in the list
|
||||
g.NavWindowingTarget = window_target;
|
||||
g.NavWindowingToggleLayer = false;
|
||||
}
|
||||
|
||||
@ -3136,7 +3139,7 @@ static void ImGui::NavUpdateWindowing()
|
||||
{
|
||||
const float NAV_MOVE_SPEED = 800.0f;
|
||||
const float move_speed = ImFloor(NAV_MOVE_SPEED * g.IO.DeltaTime * ImMin(g.IO.DisplayFramebufferScale.x, g.IO.DisplayFramebufferScale.y)); // FIXME: Doesn't code variable framerate very well
|
||||
g.NavWindowingTarget->Pos += move_delta * move_speed;
|
||||
g.NavWindowingTarget->RootWindow->Pos += move_delta * move_speed;
|
||||
g.NavDisableMouseHover = true;
|
||||
MarkIniSettingsDirty(g.NavWindowingTarget);
|
||||
}
|
||||
@ -3178,6 +3181,46 @@ static void ImGui::NavUpdateWindowing()
|
||||
}
|
||||
}
|
||||
|
||||
// Window has already passed the IsWindowNavFocusable()
|
||||
static const char* GetFallbackWindowNameForWindowingList(ImGuiWindow* window)
|
||||
{
|
||||
if (window->Flags & ImGuiWindowFlags_Popup)
|
||||
return "(Popup)";
|
||||
if ((window->Flags & ImGuiWindowFlags_MenuBar) && strcmp(window->Name, "##MainMenuBar") == 0)
|
||||
return "(Main menu bar)";
|
||||
return "(Untitled)";
|
||||
}
|
||||
|
||||
// Overlay displayed when using CTRL+TAB. Called by EndFrame().
|
||||
void ImGui::NavUpdateWindowingList()
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
if (!g.NavWindowingTarget)
|
||||
{
|
||||
g.NavWindowingList = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
if (g.NavWindowingList == NULL)
|
||||
g.NavWindowingList = FindWindowByName("###NavWindowList");
|
||||
SetNextWindowSizeConstraints(ImVec2(g.IO.DisplaySize.x * 0.20f, g.IO.DisplaySize.y * 0.20f), ImVec2(FLT_MAX, FLT_MAX));
|
||||
SetNextWindowPos(g.IO.DisplaySize * 0.5f, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
|
||||
PushStyleVar(ImGuiStyleVar_WindowPadding, g.Style.WindowPadding * 2.0f);
|
||||
Begin("###NavWindowList", NULL, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_AlwaysAutoResize);
|
||||
for (int n = g.Windows.Size - 1; n >= 0; n--)
|
||||
{
|
||||
ImGuiWindow* window = g.Windows[n];
|
||||
if (!IsWindowNavFocusable(window))
|
||||
continue;
|
||||
const char* label = window->Name;
|
||||
if (label == FindRenderedTextEnd(label))
|
||||
label = GetFallbackWindowNameForWindowingList(window);
|
||||
Selectable(label, g.NavWindowingTarget == window);
|
||||
}
|
||||
End();
|
||||
PopStyleVar();
|
||||
}
|
||||
|
||||
// Scroll to keep newly navigated item fully into view
|
||||
// NB: We modify rect_rel by the amount we scrolled for, so it is immediately updated.
|
||||
static void NavScrollToBringItemIntoView(ImGuiWindow* window, const ImRect& item_rect)
|
||||
@ -3590,6 +3633,11 @@ void ImGui::UpdateMovingWindow()
|
||||
}
|
||||
}
|
||||
|
||||
static bool IsWindowActiveAndVisible(ImGuiWindow* window)
|
||||
{
|
||||
return (window->HiddenFrames == 0) && (window->Active);
|
||||
}
|
||||
|
||||
static void ImGui::UpdateMouseInputs()
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
@ -3820,10 +3868,10 @@ void ImGui::NewFrame()
|
||||
UpdateHoveredWindowAndCaptureFlags();
|
||||
|
||||
// Background darkening/whitening
|
||||
if (GetFrontMostPopupModal() != NULL)
|
||||
g.ModalWindowDarkeningRatio = ImMin(g.ModalWindowDarkeningRatio + g.IO.DeltaTime * 6.0f, 1.0f);
|
||||
if (GetFrontMostPopupModal() != NULL || g.NavWindowingTarget != NULL)
|
||||
g.DimBgRatio = ImMin(g.DimBgRatio + g.IO.DeltaTime * 6.0f, 1.0f);
|
||||
else
|
||||
g.ModalWindowDarkeningRatio = 0.0f;
|
||||
g.DimBgRatio = 0.0f;
|
||||
|
||||
g.MouseCursor = ImGuiMouseCursor_Arrow;
|
||||
g.WantCaptureMouseNextFrame = g.WantCaptureKeyboardNextFrame = g.WantTextInputNextFrame = -1;
|
||||
@ -4333,6 +4381,8 @@ void ImGui::EndFrame()
|
||||
g.PlatformImeLastPos = g.PlatformImePos;
|
||||
}
|
||||
|
||||
NavUpdateWindowingList();
|
||||
|
||||
// Hide implicit "Debug" window if it hasn't been used
|
||||
IM_ASSERT(g.CurrentWindowStack.Size == 1); // Mismatched Begin()/End() calls, did you forget to call end on g.CurrentWindow->Name?
|
||||
if (g.CurrentWindow && !g.CurrentWindow->WriteAccessed)
|
||||
@ -4421,15 +4471,18 @@ void ImGui::Render()
|
||||
// Gather windows to render
|
||||
g.IO.MetricsRenderVertices = g.IO.MetricsRenderIndices = g.IO.MetricsActiveWindows = 0;
|
||||
g.DrawDataBuilder.Clear();
|
||||
ImGuiWindow* window_to_render_front_most = (g.NavWindowingTarget && !(g.NavWindowingTarget->Flags & ImGuiWindowFlags_NoBringToFrontOnFocus)) ? g.NavWindowingTarget : NULL;
|
||||
ImGuiWindow* windows_to_render_front_most[2];
|
||||
windows_to_render_front_most[0] = (g.NavWindowingTarget && !(g.NavWindowingTarget->Flags & ImGuiWindowFlags_NoBringToFrontOnFocus)) ? g.NavWindowingTarget->RootWindow : NULL;
|
||||
windows_to_render_front_most[1] = (g.NavWindowingList);
|
||||
for (int n = 0; n != g.Windows.Size; n++)
|
||||
{
|
||||
ImGuiWindow* window = g.Windows[n];
|
||||
if (window->Active && window->HiddenFrames == 0 && (window->Flags & ImGuiWindowFlags_ChildWindow) == 0 && window != window_to_render_front_most)
|
||||
if (IsWindowActiveAndVisible(window) && (window->Flags & ImGuiWindowFlags_ChildWindow) == 0 && window != windows_to_render_front_most[0] && window != windows_to_render_front_most[1])
|
||||
AddWindowToDrawDataSelectLayer(window);
|
||||
}
|
||||
if (window_to_render_front_most && window_to_render_front_most->Active && window_to_render_front_most->HiddenFrames == 0) // NavWindowingTarget is always temporarily displayed as the front-most window
|
||||
AddWindowToDrawDataSelectLayer(window_to_render_front_most);
|
||||
for (int n = 0; n < IM_ARRAYSIZE(windows_to_render_front_most); n++)
|
||||
if (windows_to_render_front_most[n] && IsWindowActiveAndVisible(windows_to_render_front_most[n])) // NavWindowingTarget is always temporarily displayed as the front-most window
|
||||
AddWindowToDrawDataSelectLayer(windows_to_render_front_most[n]);
|
||||
g.DrawDataBuilder.FlattenIntoSingleLayer();
|
||||
|
||||
// Draw software mouse cursor if requested
|
||||
@ -6032,7 +6085,7 @@ static void ImGui::UpdateManualResize(ImGuiWindow* window, const ImVec2& size_au
|
||||
PopID();
|
||||
|
||||
// Navigation resize (keyboard/gamepad)
|
||||
if (g.NavWindowingTarget == window)
|
||||
if (g.NavWindowingTarget && g.NavWindowingTarget->RootWindow == window)
|
||||
{
|
||||
ImVec2 nav_resize_delta;
|
||||
if (g.NavInputSource == ImGuiInputSource_NavKeyboard && g.IO.KeyShift)
|
||||
@ -6391,23 +6444,29 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
||||
else
|
||||
PushClipRect(viewport_rect.Min, viewport_rect.Max, true);
|
||||
|
||||
// Draw modal window background (darkens what is behind them)
|
||||
if ((flags & ImGuiWindowFlags_Modal) != 0 && window == GetFrontMostPopupModal())
|
||||
window->DrawList->AddRectFilled(viewport_rect.Min, viewport_rect.Max, GetColorU32(ImGuiCol_ModalWindowDarkening, g.ModalWindowDarkeningRatio));
|
||||
// Draw modal window background (darkens what is behind them, all viewports)
|
||||
const bool dim_bg_for_modal = (flags & ImGuiWindowFlags_Modal) && window == GetFrontMostPopupModal() && window->HiddenFrames <= 0;
|
||||
const bool dim_bg_for_window_list = g.NavWindowingTarget && (window == g.NavWindowingTarget->RootWindow);
|
||||
if (dim_bg_for_modal || dim_bg_for_window_list)
|
||||
{
|
||||
const ImU32 dim_bg_col = GetColorU32(dim_bg_for_modal ? ImGuiCol_ModalWindowDimBg : ImGuiCol_NavWindowListDimBg, g.DimBgRatio);
|
||||
window->DrawList->AddRectFilled(viewport_rect.Min, viewport_rect.Max, dim_bg_col);
|
||||
}
|
||||
|
||||
// Draw navigation selection/windowing rectangle background
|
||||
if (g.NavWindowingTarget == window)
|
||||
if (dim_bg_for_window_list && window == g.NavWindowingTarget->RootWindow)
|
||||
{
|
||||
ImRect bb = window->Rect();
|
||||
bb.Expand(g.FontSize);
|
||||
if (!bb.Contains(viewport_rect)) // Avoid drawing if the window covers all the viewport anyway
|
||||
window->DrawList->AddRectFilled(bb.Min, bb.Max, GetColorU32(ImGuiCol_NavWindowingHighlight, g.NavWindowingHighlightAlpha * 0.25f), g.Style.WindowRounding);
|
||||
window->DrawList->AddRectFilled(bb.Min, bb.Max, GetColorU32(ImGuiCol_NavWindowListHighlight, g.NavWindowingHighlightAlpha * 0.25f), g.Style.WindowRounding);
|
||||
}
|
||||
|
||||
// Draw window + handle manual resize
|
||||
const float window_rounding = window->WindowRounding;
|
||||
const float window_border_size = window->WindowBorderSize;
|
||||
const bool title_bar_is_highlight = want_focus || (g.NavWindow && window->RootWindowForTitleBarHighlight == g.NavWindow->RootWindowForTitleBarHighlight);
|
||||
const ImGuiWindow* window_to_highlight = g.NavWindowingTarget ? g.NavWindowingTarget : g.NavWindow;
|
||||
const bool title_bar_is_highlight = want_focus || (window_to_highlight && window->RootWindowForTitleBarHighlight == window_to_highlight->RootWindowForTitleBarHighlight);
|
||||
const ImRect title_bar_rect = window->TitleBarRect();
|
||||
if (window->Collapsed)
|
||||
{
|
||||
@ -6487,7 +6546,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
||||
bb.Expand(-g.FontSize - 1.0f);
|
||||
rounding = window->WindowRounding;
|
||||
}
|
||||
window->DrawList->AddRect(bb.Min, bb.Max, GetColorU32(ImGuiCol_NavWindowingHighlight, g.NavWindowingHighlightAlpha), rounding, ~0, 3.0f);
|
||||
window->DrawList->AddRect(bb.Min, bb.Max, GetColorU32(ImGuiCol_NavWindowListHighlight, g.NavWindowingHighlightAlpha), rounding, ~0, 3.0f);
|
||||
}
|
||||
|
||||
// Store a backup of SizeFull which we will use next frame to decide if we need scrollbars.
|
||||
@ -7181,10 +7240,10 @@ const char* ImGui::GetStyleColorName(ImGuiCol idx)
|
||||
case ImGuiCol_PlotHistogram: return "PlotHistogram";
|
||||
case ImGuiCol_PlotHistogramHovered: return "PlotHistogramHovered";
|
||||
case ImGuiCol_TextSelectedBg: return "TextSelectedBg";
|
||||
case ImGuiCol_ModalWindowDarkening: return "ModalWindowDarkening";
|
||||
case ImGuiCol_DragDropTarget: return "DragDropTarget";
|
||||
case ImGuiCol_NavHighlight: return "NavHighlight";
|
||||
case ImGuiCol_NavWindowingHighlight: return "NavWindowingHighlight";
|
||||
case ImGuiCol_NavWindowListDimBg: return "NavWindowListDimBg";
|
||||
case ImGuiCol_ModalWindowDimBg: return "ModalWindowDimBg";
|
||||
}
|
||||
IM_ASSERT(0);
|
||||
return "Unknown";
|
||||
|
Reference in New Issue
Block a user