From ebe363c9510d5b73a722e4dafb460ce8ce06b999 Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 27 Feb 2015 09:07:25 +0000 Subject: [PATCH] Added SetWindowPos(), SetWindowSize(), SetWindowCollaposed() given a wnidow name. --- imgui.cpp | 47 ++++++++++++++++++++++++++++++++++++++++------- imgui.h | 3 +++ 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index a72f6f24..38359af2 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3386,10 +3386,8 @@ ImVec2 ImGui::GetWindowPos() return window->Pos; } -void ImGui::SetWindowPos(const ImVec2& pos, ImGuiSetCondition cond) +static void SetWindowPos(ImGuiWindow* window, const ImVec2& pos, ImGuiSetCondition cond) { - ImGuiWindow* window = GetCurrentWindow(); - // Test condition (NB: bit 0 is always true) and clear flags for next time if (cond && (window->SetWindowPosAllowFlags & cond) == 0) return; @@ -3402,16 +3400,27 @@ void ImGui::SetWindowPos(const ImVec2& pos, ImGuiSetCondition cond) window->DC.CursorPos += (window->Pos - old_pos); // As we happen to move the window while it is being appended to (which is a bad idea - will smear) let's at least offset the cursor } +void ImGui::SetWindowPos(const ImVec2& pos, ImGuiSetCondition cond) +{ + ImGuiWindow* window = GetCurrentWindow(); + SetWindowPos(window, pos, cond); +} + +void ImGui::SetWindowPos(const char* name, const ImVec2& pos, ImGuiSetCondition cond) +{ + ImGuiWindow* window = FindWindowByName(name); + if (window) + SetWindowPos(window, pos, cond); +} + ImVec2 ImGui::GetWindowSize() { ImGuiWindow* window = GetCurrentWindow(); return window->Size; } -void ImGui::SetWindowSize(const ImVec2& size, ImGuiSetCondition cond) +static void SetWindowSize(ImGuiWindow* window, const ImVec2& size, ImGuiSetCondition cond) { - ImGuiWindow* window = GetCurrentWindow(); - // Test condition (NB: bit 0 is always true) and clear flags for next time if (cond && (window->SetWindowSizeAllowFlags & cond) == 0) return; @@ -3431,10 +3440,21 @@ void ImGui::SetWindowSize(const ImVec2& size, ImGuiSetCondition cond) } } -void ImGui::SetWindowCollapsed(bool collapsed, ImGuiSetCondition cond) +void ImGui::SetWindowSize(const ImVec2& size, ImGuiSetCondition cond) { ImGuiWindow* window = GetCurrentWindow(); + SetWindowSize(window, size, cond); +} +void ImGui::SetWindowSize(const char* name, const ImVec2& size, ImGuiSetCondition cond) +{ + ImGuiWindow* window = FindWindowByName(name); + if (window) + SetWindowSize(window, size, cond); +} + +static void SetWindowCollapsed(ImGuiWindow* window, bool collapsed, ImGuiSetCondition cond) +{ // Test condition (NB: bit 0 is always true) and clear flags for next time if (cond && (window->SetWindowCollapsedAllowFlags & cond) == 0) return; @@ -3444,6 +3464,19 @@ void ImGui::SetWindowCollapsed(bool collapsed, ImGuiSetCondition cond) window->Collapsed = collapsed; } +void ImGui::SetWindowCollapsed(bool collapsed, ImGuiSetCondition cond) +{ + ImGuiWindow* window = GetCurrentWindow(); + SetWindowCollapsed(window); +} + +void ImGui::SetWindowCollapsed(const char* name, bool collapsed, ImGuiSetCondition cond) +{ + ImGuiWindow* window = FindWindowByName(name); + if (window) + SetWindowCollapsed(window); +} + void ImGui::SetWindowFocus() { ImGuiWindow* window = GetCurrentWindow(); diff --git a/imgui.h b/imgui.h index ff95ae8e..b614a31c 100644 --- a/imgui.h +++ b/imgui.h @@ -186,6 +186,9 @@ namespace ImGui 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 SetWindowPos(const char* name, const ImVec2& pos, ImGuiSetCondition cond = 0); // set named window position - call within Begin()/End(). may incur tearing. + IMGUI_API void SetWindowSize(const char* name, const ImVec2& size, ImGuiSetCondition cond = 0); // set named window size. set to ImVec2(0,0) to force an auto-fit. may incur tearing. + IMGUI_API void SetWindowCollapsed(const char* name, bool collapsed, ImGuiSetCondition cond = 0); // set named window collapsed state. 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.