mirror of
https://github.com/Drezil/imgui.git
synced 2024-12-19 14:36:34 +00:00
Nav: Tweaked CTRL+TAB to hide visual noise on fast switch + fading out screen dimming and highlight to make the experience less harsh
This commit is contained in:
parent
f22024cb19
commit
1b646a4440
42
imgui.cpp
42
imgui.cpp
@ -862,6 +862,10 @@ static const ImS64 IM_S64_MAX = 9223372036854775807ll;
|
|||||||
static const ImU64 IM_U64_MIN = 0;
|
static const ImU64 IM_U64_MIN = 0;
|
||||||
static const ImU64 IM_U64_MAX = 0xFFFFFFFFFFFFFFFFull;
|
static const ImU64 IM_U64_MAX = 0xFFFFFFFFFFFFFFFFull;
|
||||||
|
|
||||||
|
// When using CTRL+TAB (or Gamepad Square+L/R) we delay the visual a little in order to reduce visual noise doing a fast switch.
|
||||||
|
static const float NAV_WINDOWING_HIGHLIGHT_DELAY = 0.20f; // Time before the highlight and screen dimming starts fading in
|
||||||
|
static const float NAV_WINDOWING_LIST_APPEAR_DELAY = 0.15f; // Time before the window list starts to appear
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
// Forward Declarations
|
// Forward Declarations
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
@ -3108,7 +3112,7 @@ static void NavUpdateWindowingHighlightWindow(int focus_change_dir)
|
|||||||
if (!window_target)
|
if (!window_target)
|
||||||
window_target = FindWindowNavigable((focus_change_dir < 0) ? (g.Windows.Size - 1) : 0, i_current, focus_change_dir);
|
window_target = FindWindowNavigable((focus_change_dir < 0) ? (g.Windows.Size - 1) : 0, i_current, focus_change_dir);
|
||||||
if (window_target) // Don't reset windowing target if there's a single window in the list
|
if (window_target) // Don't reset windowing target if there's a single window in the list
|
||||||
g.NavWindowingTarget = window_target;
|
g.NavWindowingTarget = g.NavWindowingTargetAnim = window_target;
|
||||||
g.NavWindowingToggleLayer = false;
|
g.NavWindowingToggleLayer = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3126,23 +3130,32 @@ static void ImGui::NavUpdateWindowing()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fade out
|
||||||
|
if (g.NavWindowingTargetAnim && g.NavWindowingTarget == NULL)
|
||||||
|
{
|
||||||
|
g.NavWindowingHighlightAlpha = ImMax(g.NavWindowingHighlightAlpha - g.IO.DeltaTime * 10.0f, 0.0f);
|
||||||
|
if (g.DimBgRatio <= 0.0f && g.NavWindowingHighlightAlpha <= 0.0f)
|
||||||
|
g.NavWindowingTargetAnim = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start CTRL-TAB or Square+L/R window selection
|
||||||
bool start_windowing_with_gamepad = !g.NavWindowingTarget && IsNavInputPressed(ImGuiNavInput_Menu, ImGuiInputReadMode_Pressed);
|
bool start_windowing_with_gamepad = !g.NavWindowingTarget && IsNavInputPressed(ImGuiNavInput_Menu, ImGuiInputReadMode_Pressed);
|
||||||
bool start_windowing_with_keyboard = !g.NavWindowingTarget && g.IO.KeyCtrl && IsKeyPressedMap(ImGuiKey_Tab) && (g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard);
|
bool start_windowing_with_keyboard = !g.NavWindowingTarget && g.IO.KeyCtrl && IsKeyPressedMap(ImGuiKey_Tab) && (g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard);
|
||||||
if (start_windowing_with_gamepad || start_windowing_with_keyboard)
|
if (start_windowing_with_gamepad || start_windowing_with_keyboard)
|
||||||
if (ImGuiWindow* window = g.NavWindow ? g.NavWindow : FindWindowNavigable(g.Windows.Size - 1, -INT_MAX, -1))
|
if (ImGuiWindow* window = g.NavWindow ? g.NavWindow : FindWindowNavigable(g.Windows.Size - 1, -INT_MAX, -1))
|
||||||
{
|
{
|
||||||
g.NavWindowingTarget = window;
|
g.NavWindowingTarget = g.NavWindowingTargetAnim = window;
|
||||||
g.NavWindowingHighlightTimer = g.NavWindowingHighlightAlpha = 0.0f;
|
g.NavWindowingTimer = g.NavWindowingHighlightAlpha = 0.0f;
|
||||||
g.NavWindowingToggleLayer = start_windowing_with_keyboard ? false : true;
|
g.NavWindowingToggleLayer = start_windowing_with_keyboard ? false : true;
|
||||||
g.NavInputSource = start_windowing_with_keyboard ? ImGuiInputSource_NavKeyboard : ImGuiInputSource_NavGamepad;
|
g.NavInputSource = start_windowing_with_keyboard ? ImGuiInputSource_NavKeyboard : ImGuiInputSource_NavGamepad;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gamepad update
|
// Gamepad update
|
||||||
g.NavWindowingHighlightTimer += g.IO.DeltaTime;
|
g.NavWindowingTimer += g.IO.DeltaTime;
|
||||||
if (g.NavWindowingTarget && g.NavInputSource == ImGuiInputSource_NavGamepad)
|
if (g.NavWindowingTarget && g.NavInputSource == ImGuiInputSource_NavGamepad)
|
||||||
{
|
{
|
||||||
// Highlight only appears after a brief time holding the button, so that a fast tap on PadMenu (to toggle NavLayer) doesn't add visual noise
|
// Highlight only appears after a brief time holding the button, so that a fast tap on PadMenu (to toggle NavLayer) doesn't add visual noise
|
||||||
g.NavWindowingHighlightAlpha = ImMax(g.NavWindowingHighlightAlpha, ImSaturate((g.NavWindowingHighlightTimer - 0.20f) / 0.05f));
|
g.NavWindowingHighlightAlpha = ImMax(g.NavWindowingHighlightAlpha, ImSaturate((g.NavWindowingTimer - NAV_WINDOWING_HIGHLIGHT_DELAY) / 0.05f));
|
||||||
|
|
||||||
// Select window to focus
|
// Select window to focus
|
||||||
const int focus_change_dir = (int)IsNavInputPressed(ImGuiNavInput_FocusPrev, ImGuiInputReadMode_RepeatSlow) - (int)IsNavInputPressed(ImGuiNavInput_FocusNext, ImGuiInputReadMode_RepeatSlow);
|
const int focus_change_dir = (int)IsNavInputPressed(ImGuiNavInput_FocusPrev, ImGuiInputReadMode_RepeatSlow) - (int)IsNavInputPressed(ImGuiNavInput_FocusNext, ImGuiInputReadMode_RepeatSlow);
|
||||||
@ -3168,7 +3181,7 @@ static void ImGui::NavUpdateWindowing()
|
|||||||
if (g.NavWindowingTarget && g.NavInputSource == ImGuiInputSource_NavKeyboard)
|
if (g.NavWindowingTarget && g.NavInputSource == ImGuiInputSource_NavKeyboard)
|
||||||
{
|
{
|
||||||
// Visuals only appears after a brief time after pressing TAB the first time, so that a fast CTRL+TAB doesn't add visual noise
|
// Visuals only appears after a brief time after pressing TAB the first time, so that a fast CTRL+TAB doesn't add visual noise
|
||||||
g.NavWindowingHighlightAlpha = ImMax(g.NavWindowingHighlightAlpha, ImSaturate((g.NavWindowingHighlightTimer - 0.15f) / 0.04f)); // 1.0f
|
g.NavWindowingHighlightAlpha = ImMax(g.NavWindowingHighlightAlpha, ImSaturate((g.NavWindowingTimer - NAV_WINDOWING_HIGHLIGHT_DELAY) / 0.05f)); // 1.0f
|
||||||
if (IsKeyPressedMap(ImGuiKey_Tab, true))
|
if (IsKeyPressedMap(ImGuiKey_Tab, true))
|
||||||
NavUpdateWindowingHighlightWindow(g.IO.KeyShift ? +1 : -1);
|
NavUpdateWindowingHighlightWindow(g.IO.KeyShift ? +1 : -1);
|
||||||
if (!g.IO.KeyCtrl)
|
if (!g.IO.KeyCtrl)
|
||||||
@ -3253,6 +3266,9 @@ void ImGui::NavUpdateWindowingList()
|
|||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
IM_ASSERT(g.NavWindowingTarget != NULL);
|
IM_ASSERT(g.NavWindowingTarget != NULL);
|
||||||
|
|
||||||
|
if (g.NavWindowingTimer < NAV_WINDOWING_LIST_APPEAR_DELAY)
|
||||||
|
return;
|
||||||
|
|
||||||
if (g.NavWindowingList == NULL)
|
if (g.NavWindowingList == NULL)
|
||||||
g.NavWindowingList = FindWindowByName("###NavWindowingList");
|
g.NavWindowingList = FindWindowByName("###NavWindowingList");
|
||||||
ImGuiViewportP* viewport = /*g.NavWindow ? g.NavWindow->Viewport :*/ (ImGuiViewportP*)GetMainViewport();
|
ImGuiViewportP* viewport = /*g.NavWindow ? g.NavWindow->Viewport :*/ (ImGuiViewportP*)GetMainViewport();
|
||||||
@ -4414,10 +4430,10 @@ void ImGui::NewFrame()
|
|||||||
UpdateMouseMovingWindow();
|
UpdateMouseMovingWindow();
|
||||||
|
|
||||||
// Background darkening/whitening
|
// Background darkening/whitening
|
||||||
if (GetFrontMostPopupModal() != NULL || g.NavWindowingTarget != NULL)
|
if (GetFrontMostPopupModal() != NULL || (g.NavWindowingTarget != NULL && g.NavWindowingHighlightAlpha > 0.0f))
|
||||||
g.DimBgRatio = ImMin(g.DimBgRatio + g.IO.DeltaTime * 6.0f, 1.0f);
|
g.DimBgRatio = ImMin(g.DimBgRatio + g.IO.DeltaTime * 6.0f, 1.0f);
|
||||||
else
|
else
|
||||||
g.DimBgRatio = 0.0f;
|
g.DimBgRatio = ImMax(g.DimBgRatio - g.IO.DeltaTime * 10.0f, 0.0f);
|
||||||
|
|
||||||
g.MouseCursor = ImGuiMouseCursor_Arrow;
|
g.MouseCursor = ImGuiMouseCursor_Arrow;
|
||||||
g.WantCaptureMouseNextFrame = g.WantCaptureKeyboardNextFrame = g.WantTextInputNextFrame = -1;
|
g.WantCaptureMouseNextFrame = g.WantCaptureKeyboardNextFrame = g.WantTextInputNextFrame = -1;
|
||||||
@ -4940,7 +4956,7 @@ void ImGui::EndFrame()
|
|||||||
// Draw modal whitening background on _other_ viewports than the one the modal is one
|
// Draw modal whitening background on _other_ viewports than the one the modal is one
|
||||||
ImGuiWindow* modal_window = GetFrontMostPopupModal();
|
ImGuiWindow* modal_window = GetFrontMostPopupModal();
|
||||||
const bool dim_bg_for_modal = (modal_window != NULL);
|
const bool dim_bg_for_modal = (modal_window != NULL);
|
||||||
const bool dim_bg_for_window_list = (g.NavWindowingTarget != NULL);
|
const bool dim_bg_for_window_list = (g.NavWindowingTargetAnim != NULL);
|
||||||
if (dim_bg_for_modal || dim_bg_for_window_list)
|
if (dim_bg_for_modal || dim_bg_for_window_list)
|
||||||
for (int viewport_n = 0; viewport_n < g.Viewports.Size; viewport_n++)
|
for (int viewport_n = 0; viewport_n < g.Viewports.Size; viewport_n++)
|
||||||
{
|
{
|
||||||
@ -4949,7 +4965,7 @@ void ImGui::EndFrame()
|
|||||||
continue;
|
continue;
|
||||||
if (g.NavWindowingList && viewport == g.NavWindowingList->Viewport)
|
if (g.NavWindowingList && viewport == g.NavWindowingList->Viewport)
|
||||||
continue;
|
continue;
|
||||||
if (g.NavWindowingTarget && viewport == g.NavWindowingTarget->Viewport)
|
if (g.NavWindowingTargetAnim && viewport == g.NavWindowingTargetAnim->Viewport)
|
||||||
continue;
|
continue;
|
||||||
ImDrawList* draw_list = GetOverlayDrawList(viewport);
|
ImDrawList* draw_list = GetOverlayDrawList(viewport);
|
||||||
const ImU32 dim_bg_col = GetColorU32(dim_bg_for_modal ? ImGuiCol_ModalWindowDimBg : ImGuiCol_NavWindowingDimBg, g.DimBgRatio);
|
const ImU32 dim_bg_col = GetColorU32(dim_bg_for_modal ? ImGuiCol_ModalWindowDimBg : ImGuiCol_NavWindowingDimBg, g.DimBgRatio);
|
||||||
@ -7444,7 +7460,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
|||||||
|
|
||||||
// Draw modal or window list full viewport dimming background (for other viewports we'll render them in EndFrame)
|
// Draw modal or window list full viewport dimming background (for other viewports we'll render them in EndFrame)
|
||||||
const bool dim_bg_for_modal = (flags & ImGuiWindowFlags_Modal) && window == GetFrontMostPopupModal() && window->HiddenFrames <= 0;
|
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) || (g.NavWindowingList && (window == g.NavWindowingList) && g.NavWindowingList->Viewport != g.NavWindowingTarget->Viewport));
|
const bool dim_bg_for_window_list = g.NavWindowingTargetAnim && ((window == g.NavWindowingTargetAnim->RootWindow) || (g.NavWindowingList && (window == g.NavWindowingList) && g.NavWindowingList->Viewport != g.NavWindowingTargetAnim->Viewport));
|
||||||
if (dim_bg_for_modal || dim_bg_for_window_list)
|
if (dim_bg_for_modal || dim_bg_for_window_list)
|
||||||
{
|
{
|
||||||
const ImU32 dim_bg_col = GetColorU32(dim_bg_for_modal ? ImGuiCol_ModalWindowDimBg : ImGuiCol_NavWindowingDimBg, g.DimBgRatio);
|
const ImU32 dim_bg_col = GetColorU32(dim_bg_for_modal ? ImGuiCol_ModalWindowDimBg : ImGuiCol_NavWindowingDimBg, g.DimBgRatio);
|
||||||
@ -7452,7 +7468,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Draw navigation selection/windowing rectangle background
|
// Draw navigation selection/windowing rectangle background
|
||||||
if (dim_bg_for_window_list && window == g.NavWindowingTarget->RootWindow)
|
if (dim_bg_for_window_list && window == g.NavWindowingTargetAnim)
|
||||||
{
|
{
|
||||||
ImRect bb = window->Rect();
|
ImRect bb = window->Rect();
|
||||||
bb.Expand(g.FontSize);
|
bb.Expand(g.FontSize);
|
||||||
@ -7536,7 +7552,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Draw navigation selection/windowing rectangle border
|
// Draw navigation selection/windowing rectangle border
|
||||||
if (g.NavWindowingTarget == window)
|
if (g.NavWindowingTargetAnim == window)
|
||||||
{
|
{
|
||||||
float rounding = ImMax(window->WindowRounding, g.Style.WindowRounding);
|
float rounding = ImMax(window->WindowRounding, g.Style.WindowRounding);
|
||||||
ImRect bb = window->Rect();
|
ImRect bb = window->Rect();
|
||||||
|
@ -719,8 +719,9 @@ struct ImGuiContext
|
|||||||
ImRect NavScoringRectScreen; // Rectangle used for scoring, in screen space. Based of window->DC.NavRefRectRel[], modified for directional navigation scoring.
|
ImRect NavScoringRectScreen; // Rectangle used for scoring, in screen space. Based of window->DC.NavRefRectRel[], modified for directional navigation scoring.
|
||||||
int NavScoringCount; // Metrics for debugging
|
int NavScoringCount; // Metrics for debugging
|
||||||
ImGuiWindow* NavWindowingTarget; // When selecting a window (holding Menu+FocusPrev/Next, or equivalent of CTRL-TAB) this window is temporarily displayed front-most.
|
ImGuiWindow* NavWindowingTarget; // When selecting a window (holding Menu+FocusPrev/Next, or equivalent of CTRL-TAB) this window is temporarily displayed front-most.
|
||||||
|
ImGuiWindow* NavWindowingTargetAnim; // Record of last valid NavWindowingTarget until DimBgRatio and NavWindowingHighlightAlpha becomes 0.0f
|
||||||
ImGuiWindow* NavWindowingList;
|
ImGuiWindow* NavWindowingList;
|
||||||
float NavWindowingHighlightTimer;
|
float NavWindowingTimer;
|
||||||
float NavWindowingHighlightAlpha;
|
float NavWindowingHighlightAlpha;
|
||||||
bool NavWindowingToggleLayer;
|
bool NavWindowingToggleLayer;
|
||||||
int NavLayer; // Layer we are navigating on. For now the system is hard-coded for 0=main contents and 1=menu/title bar, may expose layers later.
|
int NavLayer; // Layer we are navigating on. For now the system is hard-coded for 0=main contents and 1=menu/title bar, may expose layers later.
|
||||||
@ -853,8 +854,8 @@ struct ImGuiContext
|
|||||||
NavInputSource = ImGuiInputSource_None;
|
NavInputSource = ImGuiInputSource_None;
|
||||||
NavScoringRectScreen = ImRect();
|
NavScoringRectScreen = ImRect();
|
||||||
NavScoringCount = 0;
|
NavScoringCount = 0;
|
||||||
NavWindowingTarget = NavWindowingList = NULL;
|
NavWindowingTarget = NavWindowingTargetAnim = NavWindowingList = NULL;
|
||||||
NavWindowingHighlightTimer = NavWindowingHighlightAlpha = 0.0f;
|
NavWindowingTimer = NavWindowingHighlightAlpha = 0.0f;
|
||||||
NavWindowingToggleLayer = false;
|
NavWindowingToggleLayer = false;
|
||||||
NavLayer = 0;
|
NavLayer = 0;
|
||||||
NavIdTabCounter = INT_MAX;
|
NavIdTabCounter = INT_MAX;
|
||||||
|
Loading…
Reference in New Issue
Block a user