Skip to content

Commit 9b6fa29

Browse files
committed
Clicking on a widget in a child window focus the parent window (ocornut#147)
However SetWindowFocus() called on a child window prior to calling Begin() on said child won;'t work yet.
1 parent b911f96 commit 9b6fa29

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

imgui.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2774,7 +2774,7 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size, float bg
27742774
window->IDStack.resize(0);
27752775
ImGui::PushID(window);
27762776

2777-
// Move window (at the beginning of the frame to avoid input lag or sheering)
2777+
// Move window (at the beginning of the frame to avoid input lag or sheering). Only valid for root windows.
27782778
const ImGuiID move_id = window->GetID("#MOVE");
27792779
RegisterAliveId(move_id);
27802780
if (g.ActiveId == move_id)
@@ -3127,6 +3127,12 @@ void ImGui::End()
31273127
static void FocusWindow(ImGuiWindow* window)
31283128
{
31293129
ImGuiState& g = *GImGui;
3130+
3131+
// Always focus the root window
3132+
// FIXME: RootWindow is set as we do Begin() on the window, so this won't work if called SetWindowFocus(const char* name) on a child window prior to window calling Begin(). Bit of an edge.
3133+
if (window->RootWindow)
3134+
window = window->RootWindow;
3135+
31303136
g.FocusedWindow = window;
31313137

31323138
if (g.Windows.back() == window)

0 commit comments

Comments
 (0)