mirror of
https://github.com/ocornut/imgui.git
synced 2024-11-24 15:50:25 +01:00
Nav: Fix navigation inside child windows. Removed GetChildID() and storin/g the info within the window. (#1291)
This commit is contained in:
parent
ce7f3d4831
commit
bea06117bb
19
imgui.cpp
19
imgui.cpp
@ -1807,6 +1807,7 @@ ImGuiWindow::ImGuiWindow(const char* name)
|
||||
SizeContents = SizeContentsExplicit = ImVec2(0.0f, 0.0f);
|
||||
WindowPadding = ImVec2(0.0f, 0.0f);
|
||||
MoveId = GetID("#MOVE");
|
||||
ChildId = 0;
|
||||
Scroll = ImVec2(0.0f, 0.0f);
|
||||
ScrollTarget = ImVec2(FLT_MAX, FLT_MAX);
|
||||
ScrollTargetCenterRatio = ImVec2(0.5f, 0.5f);
|
||||
@ -1877,13 +1878,6 @@ ImGuiID ImGuiWindow::GetIDNoKeepAlive(const char* str, const char* str_end)
|
||||
return ImHash(str, str_end ? (int)(str_end - str) : 0, seed);
|
||||
}
|
||||
|
||||
ImGuiID ImGuiWindow::GetChildID(ImGuiWindow* child_window)
|
||||
{
|
||||
IM_ASSERT(child_window && child_window->ParentWindow == this);
|
||||
ImGuiID seed = IDStack[0];
|
||||
return ImHash(&child_window->ID, sizeof(child_window->ID), seed);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Internal API exposed in imgui_internal.h
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -2670,7 +2664,8 @@ static void NavUpdate()
|
||||
ImGuiWindow* child_window = g.NavWindow;
|
||||
ImGuiWindow* parent_window = g.NavWindow->ParentWindow;
|
||||
ImGui::FocusWindow(parent_window);
|
||||
SetNavId(parent_window->GetChildID(child_window));
|
||||
IM_ASSERT(child_window->ChildId != 0);
|
||||
SetNavId(child_window->ChildId);
|
||||
g.NavIdIsAlive = false;
|
||||
if (g.NavDisableMouseHover)
|
||||
g.NavMousePosDirty = true;
|
||||
@ -4392,12 +4387,12 @@ static bool BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, b
|
||||
|
||||
bool ret = ImGui::Begin(title, NULL, size, -1.0f, flags);
|
||||
ImGuiWindow* child_window = ImGui::GetCurrentWindow();
|
||||
child_window->ChildId = id;
|
||||
child_window->AutoFitChildAxises = auto_fit_axises;
|
||||
if (!(parent_window->Flags & ImGuiWindowFlags_ShowBorders))
|
||||
child_window->Flags &= ~ImGuiWindowFlags_ShowBorders;
|
||||
|
||||
// Process navigation-in immediately so NavInit can run on first frame
|
||||
//const ImGuiID id = parent_window->GetChildID(child_window);
|
||||
if (/*!(flags & ImGuiWindowFlags_NavFlattened) &&*/ (child_window->DC.NavLayerActiveFlags != 0 || child_window->DC.NavHasScroll) && GImGui->NavActivateId == id)
|
||||
{
|
||||
ImGui::FocusWindow(child_window);
|
||||
@ -4440,13 +4435,12 @@ void ImGui::EndChild()
|
||||
ImGui::End();
|
||||
|
||||
ImGuiWindow* parent_window = GetCurrentWindow();
|
||||
ImGuiID id = parent_window->GetChildID(window);
|
||||
ImRect bb(parent_window->DC.CursorPos, parent_window->DC.CursorPos + sz);
|
||||
ItemSize(sz);
|
||||
if (/*!(window->Flags & ImGuiWindowFlags_NavFlattened) &&*/ (window->DC.NavLayerActiveFlags != 0 || window->DC.NavHasScroll))
|
||||
{
|
||||
ItemAdd(bb, &id);
|
||||
RenderNavHighlight(bb, id);
|
||||
ItemAdd(bb, &window->ChildId);
|
||||
RenderNavHighlight(bb, window->ChildId);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -11465,6 +11459,7 @@ void ImGui::ShowMetricsWindow(bool* p_open)
|
||||
ImGui::Text("NavWindow: '%s', NavId: 0x%08X, NavLayer: %d", g.NavWindow ? g.NavWindow->Name : "NULL", g.NavId, g.NavLayer);
|
||||
ImGui::Text("NavRefRectRel: (%.1f,%.1f)(%.1f,%.1f)", g.NavRefRectRel.Min.x, g.NavRefRectRel.Min.y, g.NavRefRectRel.Max.x, g.NavRefRectRel.Max.y);
|
||||
ImGui::Text("NavUsable: %d, NavActive: %d", g.IO.NavUsable, g.IO.NavActive);
|
||||
ImGui::Text("NavActivateId: 0x%08X, NavInputId: 0x%08X", g.NavActivateId, g.NavInputId);
|
||||
ImGui::Text("NavDisableHighlight: %d, NavDisableMouseHover: %d", g.NavDisableHighlight, g.NavDisableMouseHover);
|
||||
ImGui::TreePop();
|
||||
}
|
||||
|
@ -735,6 +735,7 @@ struct IMGUI_API ImGuiWindow
|
||||
ImRect ContentsRegionRect; // Maximum visible content position in window coordinates. ~~ (SizeContentsExplicit ? SizeContentsExplicit : Size - ScrollbarSizes) - CursorStartPos, per axis
|
||||
ImVec2 WindowPadding; // Window padding at the time of begin. We need to lock it, in particular manipulation of the ShowBorder would have an effect
|
||||
ImGuiID MoveId; // == window->GetID("#MOVE")
|
||||
ImGuiID ChildId; // Id of corresponding item in parent window (for child windows)
|
||||
ImVec2 Scroll;
|
||||
ImVec2 ScrollTarget; // target scroll position. stored as cursor position with scrolling canceled out, so the highest point is always 0.0f. (FLT_MAX for no change)
|
||||
ImVec2 ScrollTargetCenterRatio; // 0.0f = scroll so that target position is at top, 0.5f = scroll so that target position is centered
|
||||
@ -792,7 +793,6 @@ public:
|
||||
ImGuiID GetID(const char* str, const char* str_end = NULL);
|
||||
ImGuiID GetID(const void* ptr);
|
||||
ImGuiID GetIDNoKeepAlive(const char* str, const char* str_end = NULL);
|
||||
ImGuiID GetChildID(ImGuiWindow* window);
|
||||
|
||||
ImRect Rect() const { return ImRect(Pos.x, Pos.y, Pos.x+Size.x, Pos.y+Size.y); }
|
||||
float CalcFontSize() const { return GImGui->FontBaseSize * FontWindowScale; }
|
||||
|
Loading…
Reference in New Issue
Block a user