Skip to content

Commit cac16c5

Browse files
committed
add optional<ImGuiID>dockSpaceIdFromName
**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! @see #50
1 parent 9897c0a commit cac16c5

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

src/hello_imgui/docking_params.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <string>
66
#include <vector>
77
#include <utility>
8+
#include <optional>
89
#include <stdio.h>
910

1011
namespace HelloImGui
@@ -195,7 +196,10 @@ struct DockableWindow
195196
196197
* `DockableWindow * dockableWindowOfName(const std::string & name)`: returns a pointer to a dockable window
197198
* `void focusDockableWindow(const std::string& name)`: will focus a dockable window
198-
199+
* `optional<ImGuiID> dockSpaceIdFromName(const std::string& dockSpaceName)`: may return the ImGuiID corresponding
200+
to the dockspace with this name.
201+
**Warning**: this will work reliably only if layoutCondition = DockingLayoutCondition::ApplicationStart. In other
202+
cases, the ID may be cached by ImGui himself at the first run, and HelloImGui will *not* know it on subsequent runs!
199203
@@md
200204
*/
201205

@@ -217,6 +221,8 @@ struct DockingParams
217221

218222
DockableWindow * dockableWindowOfName(const std::string & name);
219223
void focusDockableWindow(const std::string& windowName);
224+
225+
std::optional<ImGuiID> dockSpaceIdFromName(const std::string& dockSpaceName);
220226
};
221227
} // namespace HelloImGui
222228

src/hello_imgui/hello_imgui_api.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,10 @@ _Members:_
553553
554554
* `DockableWindow * dockableWindowOfName(const std::string & name)`: returns a pointer to a dockable window
555555
* `void focusDockableWindow(const std::string& name)`: will focus a dockable window
556-
556+
* `optional<ImGuiID> dockSpaceIdFromName(const std::string& dockSpaceName)`: may return the ImGuiID corresponding
557+
to the dockspace with this name.
558+
**Warning**: this will work reliably only if layoutCondition = DockingLayoutCondition::ApplicationStart. In other
559+
cases, the ID may be cached by ImGui himself at the first run, and HelloImGui will *not* know it on subsequent runs!
557560
558561
---
559562

src/hello_imgui/internal/docking_details.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,5 +265,13 @@ void DockingParams::focusDockableWindow(const std::string& windowName)
265265
fprintf(stderr, "focusDockableWindow(%s) failed, window not found!\n", windowName.c_str());
266266
}
267267

268+
std::optional<ImGuiID> DockingParams::dockSpaceIdFromName(const std::string& dockSpaceName)
269+
{
270+
if (gImGuiSplitIDs.find(dockSpaceName) == gImGuiSplitIDs.end())
271+
return std::nullopt;
272+
else
273+
return gImGuiSplitIDs.at(dockSpaceName);
274+
}
275+
268276

269277
} // namespace HelloImGui

0 commit comments

Comments
 (0)