|
1 | | -// Docking demo — `imgui = { ..., features = ["docking"] }`. |
| 1 | +// Docking + multi-viewport demo — |
| 2 | +// imgui = { ..., features = ["docking", "viewports"] } |
2 | 3 | // |
3 | 4 | // On the first frame, DockBuilder splits the dockspace into an IDE-style |
4 | 5 | // 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. |
| 6 | +// a real dock node: drag any tab to re-split, stack, or float it. |
| 7 | +// With `viewports`, drag a tab OUTSIDE the main window and it detaches into |
| 8 | +// its own OS window; the "Detached" panel below starts outside on purpose. |
7 | 9 | import imgui.core; |
8 | 10 | import imgui.app; |
9 | 11 |
|
@@ -45,5 +47,16 @@ int main() { |
45 | 47 | ImGui::Begin("Console"); |
46 | 48 | ImGui::TextUnformatted("Log pane (bottom split)."); |
47 | 49 | ImGui::End(); |
| 50 | + |
| 51 | + // Starts OUTSIDE the main window: with `viewports` this is a real, |
| 52 | + // separate OS window from the very first frame. |
| 53 | + const auto* main_vp = ImGui::GetMainViewport(); |
| 54 | + ImGui::SetNextWindowPos( |
| 55 | + ImVec2{main_vp->Pos.x + main_vp->Size.x + 60.0f, main_vp->Pos.y + 80.0f}, |
| 56 | + ImGui::Cond_FirstUseEver); |
| 57 | + ImGui::Begin("Detached"); |
| 58 | + ImGui::TextUnformatted("I live in my own OS window."); |
| 59 | + ImGui::TextUnformatted("Drag me back inside to re-dock."); |
| 60 | + ImGui::End(); |
48 | 61 | }); |
49 | 62 | } |
0 commit comments