Skip to content

Commit

Permalink
add optional<ImGuiID>dockSpaceIdFromName
Browse files Browse the repository at this point in the history
   **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
  • Loading branch information
pthom committed Mar 17, 2023
1 parent 9897c0a commit cac16c5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/hello_imgui/docking_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <string>
#include <vector>
#include <utility>
#include <optional>
#include <stdio.h>

namespace HelloImGui
Expand Down Expand Up @@ -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<ImGuiID> 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
*/

Expand All @@ -217,6 +221,8 @@ struct DockingParams

DockableWindow * dockableWindowOfName(const std::string & name);
void focusDockableWindow(const std::string& windowName);

std::optional<ImGuiID> dockSpaceIdFromName(const std::string& dockSpaceName);
};
} // namespace HelloImGui

5 changes: 4 additions & 1 deletion src/hello_imgui/hello_imgui_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<ImGuiID> 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!
---
Expand Down
8 changes: 8 additions & 0 deletions src/hello_imgui/internal/docking_details.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ImGuiID> DockingParams::dockSpaceIdFromName(const std::string& dockSpaceName)
{
if (gImGuiSplitIDs.find(dockSpaceName) == gImGuiSplitIDs.end())
return std::nullopt;
else
return gImGuiSplitIDs.at(dockSpaceName);
}


} // namespace HelloImGui

0 comments on commit cac16c5

Please sign in to comment.