mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-22 11:57:00 +00:00
Factoring bits out of Begin() into a private CreateNewWindow() funciton
(Hopefully to ease a bit the merging work for ProDBG)
This commit is contained in:
parent
5b7ed5432e
commit
e2fbbe0274
75
imgui.cpp
75
imgui.cpp
@ -303,7 +303,6 @@ static bool IsKeyPressedMap(ImGuiKey key, bool repeat = true);
|
||||
|
||||
static bool CloseWindowButton(bool* p_opened = NULL);
|
||||
static void FocusWindow(ImGuiWindow* window);
|
||||
static ImGuiWindow* FindWindow(const char* name);
|
||||
static ImGuiWindow* FindHoveredWindow(ImVec2 pos, bool excluding_childs);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -2060,15 +2059,6 @@ int ImGui::GetFrameCount()
|
||||
return GImGui.FrameCount;
|
||||
}
|
||||
|
||||
static ImGuiWindow* FindWindow(const char* name)
|
||||
{
|
||||
ImGuiState& g = GImGui;
|
||||
for (size_t i = 0; i != g.Windows.size(); i++)
|
||||
if (strcmp(g.Windows[i]->Name, name) == 0)
|
||||
return g.Windows[i];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void ImGui::BeginTooltip()
|
||||
{
|
||||
ImGui::Begin("##Tooltip", NULL, ImVec2(0,0), 0.9f, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_Tooltip);
|
||||
@ -2138,38 +2128,34 @@ void ImGui::EndChild()
|
||||
}
|
||||
}
|
||||
|
||||
// Push a new ImGui window to add widgets to.
|
||||
// - A default window called "Debug" is automatically stacked at the beginning of every frame.
|
||||
// - This can be called multiple times during the frame with the same window name to append content to the same window.
|
||||
// - The window name is used as a unique identifier to preserve window information across frames (and save rudimentary information to the .ini file). Note that you can use ## to append unique data that isn't displayed, e.g. "My window##1" will use "My window##1" as unique window ID but display "My window" to the user.
|
||||
// - Return false when window is collapsed, so you can early out in your code. You always need to call ImGui::End() even if false is returned.
|
||||
// - Passing 'bool* p_opened' displays a Close button on the upper-right corner of the window, the pointed value will be set to false when the button is pressed.
|
||||
// - Passing non-zero 'size' is roughly equivalent to calling SetNextWindowSize(size, ImGuiSetCondition_FirstUseEver) prior to calling Begin().
|
||||
bool ImGui::Begin(const char* name, bool* p_opened, ImVec2 size, float fill_alpha, ImGuiWindowFlags flags)
|
||||
static ImGuiWindow* FindWindowByName(const char* name)
|
||||
{
|
||||
// FIXME-OPT: Consider optimizing this (e.g. sorted hashes to window pointers)
|
||||
ImGuiState& g = GImGui;
|
||||
for (size_t i = 0; i != g.Windows.size(); i++)
|
||||
if (strcmp(g.Windows[i]->Name, name) == 0)
|
||||
return g.Windows[i];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static ImGuiWindow* CreateNewWindow(const char* name, ImVec2 size, ImGuiWindowFlags flags)
|
||||
{
|
||||
ImGuiState& g = GImGui;
|
||||
const ImGuiStyle& style = g.Style;
|
||||
IM_ASSERT(g.Initialized); // Forgot to call ImGui::NewFrame()
|
||||
IM_ASSERT(name != NULL); // Must pass a name
|
||||
|
||||
ImGuiWindow* window = FindWindow(name);
|
||||
if (!window)
|
||||
{
|
||||
// Create window the first time
|
||||
ImGuiWindow* window = (ImGuiWindow*)ImGui::MemAlloc(sizeof(ImGuiWindow));
|
||||
new(window) ImGuiWindow(name);
|
||||
window->Flags = flags;
|
||||
|
||||
if (flags & ImGuiWindowFlags_NoSavedSettings)
|
||||
{
|
||||
// Tooltip and child windows don't store settings
|
||||
window = (ImGuiWindow*)ImGui::MemAlloc(sizeof(ImGuiWindow));
|
||||
new(window) ImGuiWindow(name);
|
||||
|
||||
// User can disable loading and saving of settings. Tooltip and child windows also don't store settings.
|
||||
window->Size = window->SizeFull = size;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Normal windows store settings in .ini file
|
||||
window = (ImGuiWindow*)ImGui::MemAlloc(sizeof(ImGuiWindow));
|
||||
new(window) ImGuiWindow(name);
|
||||
|
||||
// Retrieve settings from .ini file
|
||||
// Use SetWindowPos() or SetNextWindowPos() with the appropriate condition flag to change the initial position of a window.
|
||||
window->PosFloat = ImVec2(60, 60);
|
||||
window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y);
|
||||
|
||||
@ -2197,9 +2183,30 @@ bool ImGui::Begin(const char* name, bool* p_opened, ImVec2 size, float fill_alph
|
||||
window->Size = window->SizeFull = size;
|
||||
}
|
||||
g.Windows.push_back(window);
|
||||
}
|
||||
return window;
|
||||
}
|
||||
|
||||
// Push a new ImGui window to add widgets to.
|
||||
// - A default window called "Debug" is automatically stacked at the beginning of every frame.
|
||||
// - This can be called multiple times during the frame with the same window name to append content to the same window.
|
||||
// - The window name is used as a unique identifier to preserve window information across frames (and save rudimentary information to the .ini file). Note that you can use ## to append unique data that isn't displayed, e.g. "My window##1" will use "My window##1" as unique window ID but display "My window" to the user.
|
||||
// - Return false when window is collapsed, so you can early out in your code. You always need to call ImGui::End() even if false is returned.
|
||||
// - Passing 'bool* p_opened' displays a Close button on the upper-right corner of the window, the pointed value will be set to false when the button is pressed.
|
||||
// - Passing non-zero 'size' is roughly equivalent to calling SetNextWindowSize(size, ImGuiSetCondition_FirstUseEver) prior to calling Begin().
|
||||
bool ImGui::Begin(const char* name, bool* p_opened, ImVec2 size, float fill_alpha, ImGuiWindowFlags flags)
|
||||
{
|
||||
ImGuiState& g = GImGui;
|
||||
const ImGuiStyle& style = g.Style;
|
||||
IM_ASSERT(g.Initialized); // Forgot to call ImGui::NewFrame()
|
||||
IM_ASSERT(name != NULL); // Must pass a name
|
||||
|
||||
// Find or create
|
||||
ImGuiWindow* window = FindWindowByName(name);
|
||||
if (!window)
|
||||
window = CreateNewWindow(name, size, flags);
|
||||
window->Flags = (ImGuiWindowFlags)flags;
|
||||
|
||||
// Add to stack
|
||||
g.CurrentWindowStack.push_back(window);
|
||||
g.CurrentWindow = window;
|
||||
|
||||
@ -2222,7 +2229,7 @@ bool ImGui::Begin(const char* name, bool* p_opened, ImVec2 size, float fill_alph
|
||||
g.SetNextWindowCollapsedCond = 0;
|
||||
}
|
||||
|
||||
// Find root
|
||||
// Find root (if we are a child window)
|
||||
size_t root_idx = g.CurrentWindowStack.size() - 1;
|
||||
while (root_idx > 0)
|
||||
{
|
||||
|
4
imgui.h
4
imgui.h
@ -161,10 +161,10 @@ namespace ImGui
|
||||
IMGUI_API ImVec2 GetWindowSize(); // get current window position.
|
||||
IMGUI_API float GetWindowWidth();
|
||||
IMGUI_API bool GetWindowCollapsed();
|
||||
IMGUI_API void SetWindowPos(const ImVec2& pos, ImGuiSetCondition cond = 0); // set current window position.
|
||||
IMGUI_API void SetWindowPos(const ImVec2& pos, ImGuiSetCondition cond = 0); // set current window position - call within Begin()/End().
|
||||
IMGUI_API void SetWindowSize(const ImVec2& size, ImGuiSetCondition cond = 0); // set current window size. set to ImVec2(0,0) to force an auto-fit
|
||||
IMGUI_API void SetWindowCollapsed(bool collapsed, ImGuiSetCondition cond = 0); // set current window collapsed state.
|
||||
IMGUI_API void SetNextWindowPos(const ImVec2& pos, ImGuiSetCondition cond = 0); // set next window position.
|
||||
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.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user