Nav: Fixed handling of ImGuiNavInput_KeyMenu so it doesn't set g.NavWindowingTarget at all, reducing size effects + handling menu layer toggle on Alt Release (#787)

This commit is contained in:
omar 2017-10-23 11:26:52 +02:00
parent 6f0aa766e1
commit be12f8c55d

View File

@ -2664,11 +2664,13 @@ static ImVec2 GetNavInputAmount2d(int stick_no, ImGuiNavReadMode mode, float slo
return delta; return delta;
} }
// Window management mode (change focus, move/resize window, jump back and forth to menu layer) // Window management mode (change focus, move/resize window, toggle menu layer)
static void ImGui::NavUpdateWindowing() static void ImGui::NavUpdateWindowing()
{ {
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
if (!g.NavWindowingTarget && (IsNavInputPressed(ImGuiNavInput_PadMenu, ImGuiNavReadMode_Pressed) || IsNavInputPressed(ImGuiNavInput_KeyMenu, ImGuiNavReadMode_Pressed))) bool toggle_layer = false;
if (!g.NavWindowingTarget && IsNavInputPressed(ImGuiNavInput_PadMenu, ImGuiNavReadMode_Pressed))
{ {
ImGuiWindow* window = g.NavWindow; ImGuiWindow* window = g.NavWindow;
if (!window) if (!window)
@ -2713,7 +2715,7 @@ static void ImGui::NavUpdateWindowing()
} }
} }
if (!IsNavInputDown(ImGuiNavInput_PadMenu) && !IsNavInputDown(ImGuiNavInput_KeyMenu)) if (!IsNavInputDown(ImGuiNavInput_PadMenu))
{ {
// Apply actual focus only when releasing the NavMenu button (until then the window was merely rendered front-most) // Apply actual focus only when releasing the NavMenu button (until then the window was merely rendered front-most)
if (g.NavWindowingTarget && !g.NavWindowingToggleLayer && (!g.NavWindow || g.NavWindowingTarget != g.NavWindow->RootNonPopupWindow)) if (g.NavWindowingTarget && !g.NavWindowingToggleLayer && (!g.NavWindow || g.NavWindowingTarget != g.NavWindow->RootNonPopupWindow))
@ -2727,20 +2729,27 @@ static void ImGui::NavUpdateWindowing()
// Single press toggles NavLayer // Single press toggles NavLayer
if (g.NavWindowingToggleLayer && g.NavWindow) if (g.NavWindowingToggleLayer && g.NavWindow)
{ toggle_layer = true;
if ((g.NavWindow->DC.NavLayerActiveMask & (1 << 1)) == 0 && (g.NavWindow->RootWindow->DC.NavLayerActiveMask & (1 << 1)) != 0)
FocusWindow(g.NavWindow->RootWindow);
g.NavLayer = (g.NavWindow->DC.NavLayerActiveMask & (1 << 1)) ? (g.NavLayer ^ 1) : 0;
g.NavDisableHighlight = false;
g.NavDisableMouseHover = true;
if (g.NavLayer == 0 && g.NavWindow->NavLastIds[0] != 0)
SetNavIDAndMoveMouse(g.NavWindow->NavLastIds[0], g.NavLayer, ImRect());
else
NavInitWindow(g.NavWindow, true);
}
g.NavWindowingTarget = NULL; g.NavWindowingTarget = NULL;
} }
} }
// Keyboard: Press and release ALT to toggle menu
if ((g.ActiveId == 0 || g.ActiveIdAllowOverlap) && IsNavInputPressed(ImGuiNavInput_KeyMenu, ImGuiNavReadMode_Released))
toggle_layer = true;
if (toggle_layer && g.NavWindow)
{
if ((g.NavWindow->DC.NavLayerActiveMask & (1 << 1)) == 0 && (g.NavWindow->RootWindow->DC.NavLayerActiveMask & (1 << 1)) != 0)
FocusWindow(g.NavWindow->RootWindow);
g.NavLayer = (g.NavWindow->DC.NavLayerActiveMask & (1 << 1)) ? (g.NavLayer ^ 1) : 0;
g.NavDisableHighlight = false;
g.NavDisableMouseHover = true;
if (g.NavLayer == 0 && g.NavWindow->NavLastIds[0] != 0)
SetNavIDAndMoveMouse(g.NavWindow->NavLastIds[0], g.NavLayer, ImRect());
else
NavInitWindow(g.NavWindow, true);
}
} }
// NB: We modify rect_rel by the amount we scrolled for, so it is immediately updated. // NB: We modify rect_rel by the amount we scrolled for, so it is immediately updated.