|
1 | 1 | // 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. |
5 | 7 | import imgui.core; |
6 | 8 | import imgui.app; |
7 | 9 |
|
8 | 10 | int main() { |
9 | 11 | return ImGui::App::run({.title = "mcpp imgui docking demo"}, [] { |
10 | | - const auto dockspace = ImGui::DockSpaceOverViewport(); |
| 12 | + auto dockspace = ImGui::DockSpaceOverViewport(); |
11 | 13 |
|
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."); |
19 | 39 | ImGui::End(); |
20 | 40 |
|
21 | | - ImGui::SetNextWindowDockID(dockspace, ImGui::Cond_FirstUseEver); |
22 | 41 | 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)."); |
24 | 47 | ImGui::End(); |
25 | 48 | }); |
26 | 49 | } |
0 commit comments