Skip to content

Commit 0ed45d0

Browse files
committed
feat(docking): DockBuilder surface + real split-layout demo
The previous demo pre-docked both panels into one tab group — visually just a tab bar, no visible docking. Export the minimal DockBuilder surface (DockBuilderSplitNode/DockWindow/Finish + ImGuiDir-typed Dir_* constants, gated by the docking feature; imgui_internal.h enters the GMF only when the feature is on) and rebuild the example as an IDE-style first-frame layout: Scene | Viewport | Inspector with Console split below — four real dock nodes, drag any tab to re-split/stack/float. Default (feature-off) build/tests unchanged.
1 parent 0f75121 commit 0ed45d0

2 files changed

Lines changed: 53 additions & 13 deletions

File tree

examples/docking/src/main.cpp

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,49 @@
11
// Docking demo — `imgui = { ..., features = ["docking"] }`.
2-
// The imgui.app facade auto-enables ImGuiConfigFlags_DockingEnable when the
3-
// feature is active; DockSpaceOverViewport turns the whole window into a
4-
// dock host, so the two panels below can be dragged into / split around it.
2+
//
3+
// On the first frame, DockBuilder splits the dockspace into an IDE-style
4+
// layout (Scene | Viewport | Inspector, Console at the bottom). Every pane is
5+
// a real dock node: drag any tab to re-split, stack, or float it — the
6+
// docking previews/overlays appear while dragging.
57
import imgui.core;
68
import imgui.app;
79

810
int main() {
911
return ImGui::App::run({.title = "mcpp imgui docking demo"}, [] {
10-
const auto dockspace = ImGui::DockSpaceOverViewport();
12+
auto dockspace = ImGui::DockSpaceOverViewport();
1113

12-
// Pre-dock both panels into the dockspace on first run; they remain
13-
// freely draggable/splittable afterwards.
14-
ImGui::SetNextWindowDockID(dockspace, ImGui::Cond_FirstUseEver);
15-
ImGui::Begin("Toolbox");
16-
ImGui::TextUnformatted("Drag this panel onto the dockspace.");
17-
ImGui::TextUnformatted("Docked: ");
18-
ImGui::TextUnformatted(ImGui::IsWindowDocked() ? "yes" : "no");
14+
static bool layout_built = false;
15+
if (!layout_built) {
16+
layout_built = true;
17+
const auto root = dockspace;
18+
auto left = ImGui::DockBuilderSplitNode(
19+
dockspace, ImGui::Dir_Left, 0.22f, nullptr, &dockspace);
20+
auto down = ImGui::DockBuilderSplitNode(
21+
dockspace, ImGui::Dir_Down, 0.28f, nullptr, &dockspace);
22+
auto right = ImGui::DockBuilderSplitNode(
23+
dockspace, ImGui::Dir_Right, 0.30f, nullptr, &dockspace);
24+
ImGui::DockBuilderDockWindow("Scene", left);
25+
ImGui::DockBuilderDockWindow("Console", down);
26+
ImGui::DockBuilderDockWindow("Inspector", right);
27+
ImGui::DockBuilderDockWindow("Viewport", dockspace);
28+
ImGui::DockBuilderFinish(root);
29+
}
30+
31+
ImGui::Begin("Scene");
32+
ImGui::TextUnformatted("Scene tree pane (left split).");
33+
ImGui::TextUnformatted(ImGui::IsWindowDocked() ? "docked: yes" : "docked: no");
34+
ImGui::End();
35+
36+
ImGui::Begin("Viewport");
37+
ImGui::TextUnformatted("Central pane. Drag any tab to");
38+
ImGui::TextUnformatted("re-split / stack / float it.");
1939
ImGui::End();
2040

21-
ImGui::SetNextWindowDockID(dockspace, ImGui::Cond_FirstUseEver);
2241
ImGui::Begin("Inspector");
23-
ImGui::TextUnformatted("Split me against the Toolbox.");
42+
ImGui::TextUnformatted("Properties pane (right split).");
43+
ImGui::End();
44+
45+
ImGui::Begin("Console");
46+
ImGui::TextUnformatted("Log pane (bottom split).");
2447
ImGui::End();
2548
});
2649
}

src/core.cppm

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
module;
22

33
#include <imgui.h>
4+
#ifdef MCPP_FEATURE_DOCKING
5+
// DockBuilder (programmatic dock layouts) lives in the internal header.
6+
#include <imgui_internal.h>
7+
#endif
48

59
export module imgui.core;
610

@@ -42,9 +46,22 @@ export namespace ImGui {
4246
using ::ImGui::GetWindowDockID;
4347
using ::ImGui::IsWindowDocked;
4448

49+
// DockBuilder — programmatic dock layouts (e.g. an IDE-style default
50+
// split). Upstream ships it in imgui_internal.h; the docking feature
51+
// exports the minimal stable surface needed to build layouts.
52+
using ::ImGui::DockBuilderSplitNode;
53+
using ::ImGui::DockBuilderDockWindow;
54+
using ::ImGui::DockBuilderFinish;
55+
4556
// Unscoped global enumerators, re-exported as namespaced constants for
4657
// module consumers.
4758
inline constexpr int ConfigFlags_DockingEnable = ::ImGuiConfigFlags_DockingEnable;
4859
inline constexpr int Cond_FirstUseEver = ::ImGuiCond_FirstUseEver;
60+
// Typed as the underlying enum so they pass straight into
61+
// DockBuilderSplitNode without the consumer naming ImGuiDir.
62+
inline constexpr ::ImGuiDir Dir_Left = ::ImGuiDir_Left;
63+
inline constexpr ::ImGuiDir Dir_Right = ::ImGuiDir_Right;
64+
inline constexpr ::ImGuiDir Dir_Up = ::ImGuiDir_Up;
65+
inline constexpr ::ImGuiDir Dir_Down = ::ImGuiDir_Down;
4966
}
5067
#endif

0 commit comments

Comments
 (0)