Nav: tweaks so docking can use same code. NavRestoreLayer restore nav id but Menu key typicallys clears it for menu layer (+ less relying on _ChildWindow flag).

This commit is contained in:
ocornut 2021-03-09 16:07:08 +01:00
parent 4bb5a36f90
commit 1c9cc7c117

View File

@ -3701,7 +3701,7 @@ void ImGui::UpdateMouseWheel()
const float new_font_scale = ImClamp(window->FontWindowScale + g.IO.MouseWheel * 0.10f, 0.50f, 2.50f); const float new_font_scale = ImClamp(window->FontWindowScale + g.IO.MouseWheel * 0.10f, 0.50f, 2.50f);
const float scale = new_font_scale / window->FontWindowScale; const float scale = new_font_scale / window->FontWindowScale;
window->FontWindowScale = new_font_scale; window->FontWindowScale = new_font_scale;
if (!(window->Flags & ImGuiWindowFlags_ChildWindow)) if (window == window->RootWindow)
{ {
const ImVec2 offset = window->Size * (1.0f - scale) * (g.IO.MousePos - window->Pos) / window->Size; const ImVec2 offset = window->Size * (1.0f - scale) * (g.IO.MousePos - window->Pos) / window->Size;
SetWindowPos(window, window->Pos + offset, 0); SetWindowPos(window, window->Pos + offset, 0);
@ -8795,7 +8795,7 @@ void ImGui::NavMoveRequestTryWrapping(ImGuiWindow* window, ImGuiNavMoveFlags mov
static void ImGui::NavSaveLastChildNavWindowIntoParent(ImGuiWindow* nav_window) static void ImGui::NavSaveLastChildNavWindowIntoParent(ImGuiWindow* nav_window)
{ {
ImGuiWindow* parent = nav_window; ImGuiWindow* parent = nav_window;
while (parent && (parent->Flags & ImGuiWindowFlags_ChildWindow) != 0 && (parent->Flags & (ImGuiWindowFlags_Popup | ImGuiWindowFlags_ChildMenu)) == 0) while (parent && parent->RootWindow != parent && (parent->Flags & (ImGuiWindowFlags_Popup | ImGuiWindowFlags_ChildMenu)) == 0)
parent = parent->ParentWindow; parent = parent->ParentWindow;
if (parent && parent != nav_window) if (parent && parent != nav_window)
parent->NavLastChildNavWindow = nav_window; parent->NavLastChildNavWindow = nav_window;
@ -8817,8 +8817,8 @@ static void NavRestoreLayer(ImGuiNavLayer layer)
if (layer == 0) if (layer == 0)
g.NavWindow = ImGui::NavRestoreLastChildNavWindow(g.NavWindow); g.NavWindow = ImGui::NavRestoreLastChildNavWindow(g.NavWindow);
ImGuiWindow* window = g.NavWindow; ImGuiWindow* window = g.NavWindow;
if (layer == 0 && window->NavLastIds[0] != 0) if (window->NavLastIds[layer] != 0)
ImGui::SetNavIDWithRectRel(window->NavLastIds[0], layer, 0, window->NavRectRel[0]); ImGui::SetNavIDWithRectRel(window->NavLastIds[layer], layer, 0, g.NavWindow->NavRectRel[layer]);
else else
ImGui::NavInitWindow(window, true); ImGui::NavInitWindow(window, true);
} }
@ -9022,7 +9022,7 @@ static void ImGui::NavUpdate()
if (!IsActiveIdUsingNavInput(ImGuiNavInput_Cancel)) if (!IsActiveIdUsingNavInput(ImGuiNavInput_Cancel))
ClearActiveID(); ClearActiveID();
} }
else if (g.NavWindow && (g.NavWindow->Flags & ImGuiWindowFlags_ChildWindow) && !(g.NavWindow->Flags & ImGuiWindowFlags_Popup) && g.NavWindow->ParentWindow) else if (g.NavWindow && g.NavWindow != g.NavWindow->RootWindow && !(g.NavWindow->Flags & ImGuiWindowFlags_Popup) && g.NavWindow->ParentWindow)
{ {
// Exit child window // Exit child window
ImGuiWindow* child_window = g.NavWindow; ImGuiWindow* child_window = g.NavWindow;
@ -9175,7 +9175,7 @@ static void ImGui::NavUpdate()
} }
// For scoring we use a single segment on the left side our current item bounding box (not touching the edge to avoid box overlap with zero-spaced items) // For scoring we use a single segment on the left side our current item bounding box (not touching the edge to avoid box overlap with zero-spaced items)
ImRect nav_rect_rel = g.NavWindow ? g.NavWindow->NavRectRel[g.NavLayer] : ImRect(0, 0, 0, 0); ImRect nav_rect_rel = g.NavWindow && !g.NavWindow->NavRectRel[g.NavLayer].IsInverted() ? g.NavWindow->NavRectRel[g.NavLayer] : ImRect(0, 0, 0, 0);
g.NavScoringRect = g.NavWindow ? ImRect(g.NavWindow->Pos + nav_rect_rel.Min, g.NavWindow->Pos + nav_rect_rel.Max) : ImRect(0, 0, 0, 0); g.NavScoringRect = g.NavWindow ? ImRect(g.NavWindow->Pos + nav_rect_rel.Min, g.NavWindow->Pos + nav_rect_rel.Max) : ImRect(0, 0, 0, 0);
g.NavScoringRect.TranslateY(nav_scoring_rect_offset_y); g.NavScoringRect.TranslateY(nav_scoring_rect_offset_y);
g.NavScoringRect.Min.x = ImMin(g.NavScoringRect.Min.x + 1.0f, g.NavScoringRect.Max.x); g.NavScoringRect.Min.x = ImMin(g.NavScoringRect.Min.x + 1.0f, g.NavScoringRect.Max.x);
@ -9579,8 +9579,10 @@ static void ImGui::NavUpdateWindowing()
g.NavDisableHighlight = false; g.NavDisableHighlight = false;
g.NavDisableMouseHover = true; g.NavDisableMouseHover = true;
// When entering a regular menu bar with the Alt key, we always reinitialize the navigation ID. // Reinitialize navigation when entering menu bar with the Alt key.
const ImGuiNavLayer new_nav_layer = (g.NavWindow->DC.NavLayerActiveMask & (1 << ImGuiNavLayer_Menu)) ? (ImGuiNavLayer)((int)g.NavLayer ^ 1) : ImGuiNavLayer_Main; const ImGuiNavLayer new_nav_layer = (g.NavWindow->DC.NavLayerActiveMask & (1 << ImGuiNavLayer_Menu)) ? (ImGuiNavLayer)((int)g.NavLayer ^ 1) : ImGuiNavLayer_Main;
if (new_nav_layer == ImGuiNavLayer_Menu)
g.NavWindow->NavLastIds[new_nav_layer] = 0;
NavRestoreLayer(new_nav_layer); NavRestoreLayer(new_nav_layer);
} }
} }