From 6d89285f59ce1a1ec246123c446c07b98ba347ae Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 27 Feb 2015 09:01:12 +0000 Subject: [PATCH] Added SetWindowFocus(), SetWindowFocus(const char*), SetNextWindowFocus() (#146) --- imgui.cpp | 26 ++++++++++++++++++++++++++ imgui.h | 4 ++++ 2 files changed, 30 insertions(+) diff --git a/imgui.cpp b/imgui.cpp index 7e2cc01f2..a72f6f249 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1005,6 +1005,7 @@ struct ImGuiState ImGuiSetCondition SetNextWindowSizeCond; bool SetNextWindowCollapsedVal; ImGuiSetCondition SetNextWindowCollapsedCond; + bool SetNextWindowFocus; // Render ImVector RenderDrawLists; @@ -1056,6 +1057,7 @@ struct ImGuiState SetNextWindowSizeCond = 0; SetNextWindowCollapsedVal = false; SetNextWindowCollapsedCond = 0; + SetNextWindowFocus = false; SliderAsInputTextId = 0; ActiveComboID = 0; @@ -2704,6 +2706,11 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size, float bg ImGui::SetWindowCollapsed(g.SetNextWindowCollapsedVal, g.SetNextWindowCollapsedCond); g.SetNextWindowCollapsedCond = 0; } + if (g.SetNextWindowFocus) + { + ImGui::SetWindowFocus(); + g.SetNextWindowFocus = false; + } // Find parent ImGuiWindow* parent_window = (flags & ImGuiWindowFlags_ChildWindow) != 0 ? g.CurrentWindowStack[g.CurrentWindowStack.size()-2] : NULL; @@ -3437,6 +3444,19 @@ void ImGui::SetWindowCollapsed(bool collapsed, ImGuiSetCondition cond) window->Collapsed = collapsed; } +void ImGui::SetWindowFocus() +{ + ImGuiWindow* window = GetCurrentWindow(); + FocusWindow(window); +} + +void ImGui::SetWindowFocus(const char* name) +{ + ImGuiWindow* window = FindWindowByName(name); + if (window) + FocusWindow(window); +} + void ImGui::SetNextWindowPos(const ImVec2& pos, ImGuiSetCondition cond) { ImGuiState& g = *GImGui; @@ -3458,6 +3478,12 @@ void ImGui::SetNextWindowCollapsed(bool collapsed, ImGuiSetCondition cond) g.SetNextWindowCollapsedCond = cond ? cond : ImGuiSetCondition_Always; } +void ImGui::SetNextWindowFocus() +{ + ImGuiState& g = *GImGui; + g.SetNextWindowFocus = true; +} + ImVec2 ImGui::GetContentRegionMax() { ImGuiWindow* window = GetCurrentWindow(); diff --git a/imgui.h b/imgui.h index e94191da6..ff95ae8ec 100644 --- a/imgui.h +++ b/imgui.h @@ -177,12 +177,16 @@ namespace ImGui IMGUI_API ImVec2 GetWindowSize(); // get current window position. IMGUI_API float GetWindowWidth(); IMGUI_API bool GetWindowCollapsed(); + IMGUI_API void SetNextWindowPos(const ImVec2& pos, ImGuiSetCondition cond = 0); // set next window position - call before Begin(). IMGUI_API void SetNextWindowSize(const ImVec2& size, ImGuiSetCondition cond = 0); // set next window size. set to ImVec2(0,0) to force an auto-fit. IMGUI_API void SetNextWindowCollapsed(bool collapsed, ImGuiSetCondition cond = 0); // set next window collapsed state. + IMGUI_API void SetNextWindowFocus(); // set next window to be focused / front-most IMGUI_API void SetWindowPos(const ImVec2& pos, ImGuiSetCondition cond = 0); // set current window position - call within Begin()/End(). may incur tearing. IMGUI_API void SetWindowSize(const ImVec2& size, ImGuiSetCondition cond = 0); // set current window size. set to ImVec2(0,0) to force an auto-fit. may incur tearing. IMGUI_API void SetWindowCollapsed(bool collapsed, ImGuiSetCondition cond = 0); // set current window collapsed state. + IMGUI_API void SetWindowFocus(); // set current window to be focused / front-most + IMGUI_API void SetWindowFocus(const char* name); // set named window to be focused / front-most IMGUI_API void SetScrollPosHere(); // adjust scrolling position to center into the current cursor position. IMGUI_API void SetKeyboardFocusHere(int offset = 0); // focus keyboard on the next widget. Use positive 'offset' to access sub components of a multiple component widget.