Skip to content

Commit d94227d

Browse files
jcardonneiMeaNz
authored andcommitted
feat: docking split init
1 parent 8b5a4c0 commit d94227d

6 files changed

Lines changed: 72 additions & 37 deletions

File tree

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,9 @@ _CPack_Packages/
173173

174174
myinstall/
175175
*.gcov
176+
177+
.nexo/search_history.json
178+
179+
.task/checksum/configure
180+
181+
Taskfile.yml

editor/src/DocumentWindows/EditorScene/EditorScene.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,6 @@ namespace nexo::editor
126126
bool m_shouldFocusGameWindow = false;
127127
std::string m_gameWindowToFocus;
128128

129-
// Deferred dock split operation
130-
bool m_shouldSplitDock = false;
131-
std::string m_gameWindowNameToSplit;
132-
133129
// Selected button gradient - lighter blue gradient
134130
const std::vector<ImNexo::GradientStop> m_selectedGradient = {
135131
{0.0f, IM_COL32(70, 70, 120, 230)},

editor/src/DocumentWindows/EditorScene/Show.cpp

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -163,34 +163,6 @@ namespace nexo::editor
163163

164164
void EditorScene::show()
165165
{
166-
// Handle deferred dock split before rendering
167-
if (m_shouldSplitDock && !m_gameWindowNameToSplit.empty())
168-
{
169-
const std::string currentWindowName = m_windowName;
170-
const ImGuiWindow *currentImGuiWindow = ImGui::FindWindowByName((currentWindowName + NEXO_WND_USTRID_DEFAULT_SCENE + std::to_string(m_sceneId)).c_str());
171-
172-
if (currentImGuiWindow && currentImGuiWindow->DockId)
173-
{
174-
const ImGuiID editorDockId = currentImGuiWindow->DockId;
175-
ImGuiID rightNode, leftNode;
176-
177-
if (ImGui::DockBuilderSplitNode(editorDockId, ImGuiDir_Right, 0.5f, &rightNode, &leftNode))
178-
{
179-
// Dock the windows
180-
ImGui::DockBuilderDockWindow((currentWindowName + NEXO_WND_USTRID_DEFAULT_SCENE + std::to_string(m_sceneId)).c_str(), leftNode);
181-
ImGui::DockBuilderDockWindow(m_gameWindowNameToSplit.c_str(), rightNode);
182-
ImGui::DockBuilderFinish(editorDockId);
183-
184-
// Update registry
185-
m_windowRegistry.setDockId(currentWindowName + NEXO_WND_USTRID_DEFAULT_SCENE + std::to_string(m_sceneId), leftNode);
186-
m_windowRegistry.setDockId(m_gameWindowNameToSplit, rightNode);
187-
}
188-
}
189-
190-
m_shouldSplitDock = false;
191-
m_gameWindowNameToSplit.clear();
192-
}
193-
194166
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
195167
ImGui::SetNextWindowSizeConstraints(ImVec2(480, 270), ImVec2(1920, 1080));
196168
auto& selector = Selector::get();

editor/src/DocumentWindows/EditorScene/Toolbar.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,16 @@ namespace nexo::editor {
5959
newGameWindow->setup();
6060
newGameWindow->setOpened(true);
6161

62-
// Schedule dock split for next frame
63-
m_shouldSplitDock = true;
64-
m_gameWindowNameToSplit = gameWindowName;
65-
66-
// Also schedule focus for after the split
62+
// Split the dock and attach the new game window
63+
const std::string editorWindowFullName = std::format("{}{}{}", m_windowName, NEXO_WND_USTRID_DEFAULT_SCENE, m_sceneId);
64+
m_windowRegistry.splitDockAndAttachWindow(
65+
editorWindowFullName,
66+
gameWindowName,
67+
ImGuiDir_Right,
68+
0.5f
69+
);
70+
71+
// Schedule focus for the new window
6772
m_shouldFocusGameWindow = true;
6873
m_gameWindowToFocus = gameWindowName;
6974
}

editor/src/WindowRegistry.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
///////////////////////////////////////////////////////////////////////////////
1818

1919
#include "WindowRegistry.hpp"
20+
#include "Logger.hpp"
21+
#include <imgui_internal.h>
2022

2123
namespace nexo::editor {
2224

@@ -93,4 +95,38 @@ namespace nexo::editor {
9395
}
9496
}
9597
}
98+
99+
bool WindowRegistry::splitDockAndAttachWindow(
100+
const std::string& sourceWindowName,
101+
const std::string& newWindowName,
102+
const ImGuiDir splitDirection,
103+
const float splitRatio)
104+
{
105+
const ImGuiWindow* sourceImGuiWindow = ImGui::FindWindowByName(sourceWindowName.c_str());
106+
107+
if (!sourceImGuiWindow || !sourceImGuiWindow->DockId)
108+
{
109+
LOG(NEXO_WARN, "Cannot split dock: source window '{}' not found or not docked", sourceWindowName);
110+
return false;
111+
}
112+
113+
const ImGuiID sourceDockId = sourceImGuiWindow->DockId;
114+
ImGuiID newNode, remainingNode;
115+
116+
if (!ImGui::DockBuilderSplitNode(sourceDockId, splitDirection, splitRatio, &newNode, &remainingNode))
117+
{
118+
LOG(NEXO_WARN, "Failed to split dock node for window '{}'", sourceWindowName);
119+
return false;
120+
}
121+
122+
ImGui::DockBuilderDockWindow(sourceWindowName.c_str(), remainingNode);
123+
ImGui::DockBuilderDockWindow(newWindowName.c_str(), newNode);
124+
ImGui::DockBuilderFinish(sourceDockId);
125+
126+
m_dockingRegistry.setDockId(sourceWindowName, remainingNode);
127+
m_dockingRegistry.setDockId(newWindowName, newNode);
128+
129+
LOG(NEXO_DEBUG, "Successfully split dock for '{}' and attached '{}'", sourceWindowName, newWindowName);
130+
return true;
131+
}
96132
}

editor/src/WindowRegistry.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,26 @@ namespace nexo::editor {
268268
*/
269269
void resetDockId(const std::string &name);
270270

271+
/**
272+
* @brief Splits a dock node and attaches a new window to the split.
273+
*
274+
* Finds the source window's dock node, splits it in the specified direction,
275+
* and docks both windows to the resulting nodes. Updates the docking registry
276+
* with the new dock IDs.
277+
*
278+
* @param sourceWindowName Name of the window whose dock will be split
279+
* @param newWindowName Name of the window to dock in the new split
280+
* @param splitDirection Direction to split (ImGuiDir_Left/Right/Up/Down)
281+
* @param splitRatio Ratio of the split (0.0-1.0, typically 0.5 for 50/50)
282+
* @return true if split was successful, false if source window not found
283+
*/
284+
bool splitDockAndAttachWindow(
285+
const std::string& sourceWindowName,
286+
const std::string& newWindowName,
287+
ImGuiDir splitDirection,
288+
float splitRatio
289+
);
290+
271291
/**
272292
* @brief Initializes all managed windows.
273293
*

0 commit comments

Comments
 (0)