Added SetWindowFocus(), SetWindowFocus(const char*), SetNextWindowFocus() (#146)

This commit is contained in:
ocornut 2015-02-27 09:01:12 +00:00
parent 7591252607
commit 6d89285f59
2 changed files with 30 additions and 0 deletions

View File

@ -1005,6 +1005,7 @@ struct ImGuiState
ImGuiSetCondition SetNextWindowSizeCond;
bool SetNextWindowCollapsedVal;
ImGuiSetCondition SetNextWindowCollapsedCond;
bool SetNextWindowFocus;
// Render
ImVector<ImDrawList*> 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();

View File

@ -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.