diff --git a/src/hello_imgui/docking_params.h b/src/hello_imgui/docking_params.h index a36792a5..88603b47 100644 --- a/src/hello_imgui/docking_params.h +++ b/src/hello_imgui/docking_params.h @@ -5,6 +5,7 @@ #include #include #include +#include #include namespace HelloImGui @@ -195,7 +196,10 @@ struct DockableWindow * `DockableWindow * dockableWindowOfName(const std::string & name)`: returns a pointer to a dockable window * `void focusDockableWindow(const std::string& name)`: will focus a dockable window - + * `optional dockSpaceIdFromName(const std::string& dockSpaceName)`: may return the ImGuiID corresponding + to the dockspace with this name. + **Warning**: this will work reliably only if layoutCondition = DockingLayoutCondition::ApplicationStart. In other + cases, the ID may be cached by ImGui himself at the first run, and HelloImGui will *not* know it on subsequent runs! @@md */ @@ -217,6 +221,8 @@ struct DockingParams DockableWindow * dockableWindowOfName(const std::string & name); void focusDockableWindow(const std::string& windowName); + + std::optional dockSpaceIdFromName(const std::string& dockSpaceName); }; } // namespace HelloImGui diff --git a/src/hello_imgui/hello_imgui_api.md b/src/hello_imgui/hello_imgui_api.md index d0156cfc..6e1e64f7 100644 --- a/src/hello_imgui/hello_imgui_api.md +++ b/src/hello_imgui/hello_imgui_api.md @@ -553,7 +553,10 @@ _Members:_ * `DockableWindow * dockableWindowOfName(const std::string & name)`: returns a pointer to a dockable window * `void focusDockableWindow(const std::string& name)`: will focus a dockable window - + * `optional dockSpaceIdFromName(const std::string& dockSpaceName)`: may return the ImGuiID corresponding + to the dockspace with this name. + **Warning**: this will work reliably only if layoutCondition = DockingLayoutCondition::ApplicationStart. In other + cases, the ID may be cached by ImGui himself at the first run, and HelloImGui will *not* know it on subsequent runs! --- diff --git a/src/hello_imgui/internal/docking_details.cpp b/src/hello_imgui/internal/docking_details.cpp index 142efb11..312db4c7 100644 --- a/src/hello_imgui/internal/docking_details.cpp +++ b/src/hello_imgui/internal/docking_details.cpp @@ -265,5 +265,13 @@ void DockingParams::focusDockableWindow(const std::string& windowName) fprintf(stderr, "focusDockableWindow(%s) failed, window not found!\n", windowName.c_str()); } +std::optional DockingParams::dockSpaceIdFromName(const std::string& dockSpaceName) +{ + if (gImGuiSplitIDs.find(dockSpaceName) == gImGuiSplitIDs.end()) + return std::nullopt; + else + return gImGuiSplitIDs.at(dockSpaceName); +} + } // namespace HelloImGui \ No newline at end of file