Docking
ImGui’s native docking lets the user grab a window’s tab and drop it into a
side pane, the bottom pane, or even pop it out to a free-floating window —
all preserved across runs through imgui.ini. The dasImgui boost layer
wraps the C++ surface in three macros: dockspace (the full-viewport
dockable region), the sibling dockspace_in_window (an explicit
DockSpace nested inside a host window(HOST, …)), and
dock_window (each dockable panel inside either dockspace). A small
DockBuilder helper seeds an initial layout so first-run users see
something meaningful before they start dragging tabs around.
Source: examples/tutorial/docking.das.
Walkthrough
The recording is voiced and self-verifying, and it docks the way a user does
— no programmatic shortcuts. It drives two REAL synthetic mouse drags: it grabs
the node splitter between Explorer and Source and drags it to widen the left
pane, then grabs Output’s tab and drags it onto Source to stack the two as tabs.
The synthetic mouse drives ImGui’s SplitterBehavior and its
window-move + dock-preview + drop path exactly like a hand on the mouse would.
Each drag asserts the layout actually moved (the resized pane’s size changed;
the re-docked panel’s dock_id changed); a no-op drag aborts the recording at
teardown rather than shipping a clip where nothing happened.
1options gen2
2
3require imgui
4require imgui_app
5require opengl/opengl_boost
6require live/glfw_live
7require live/live_api
8require live/live_commands
9require live/live_vars
10require live_host
11require imgui/imgui_live
12require imgui/imgui_boost_runtime
13require imgui/imgui_boost_v2
14require imgui/imgui_widgets_builtin
15require imgui/imgui_docking_builtin
16require imgui/imgui_visual_aids
17
18// =============================================================================
19// TUTORIAL: docking — full-viewport dockspace + draggable Begin/End windows.
20//
21// Three things compose to make dockable UI:
22// 1. `io.ConfigFlags |= ImGuiConfigFlags.DockingEnable` in `init()` — turns
23// on ImGui's docking machinery for the whole session.
24// 2. `dockspace(DOCK_ROOT, (flags=...))` in the frame loop — wraps
25// DockSpaceOverViewport so the whole window becomes a dock target, and
26// captures the returned `state.dock_id` for the layout helper to use.
27// 3. `dock_window(NAME, (text=..., closable=..., flags=...))` per panel —
28// Begin/End-wrapped windows that ImGui dynamically docks/undocks based
29// on the user dragging their tab.
30//
31// The DockBuilder helper (`setup_default_layout`) seeds a 3-pane layout on
32// the first frame so the user sees an arranged UI without having to drag
33// tabs manually. After the first run, dock state persists via ImGui's
34// `imgui.ini` — drag a tab anywhere and the layout sticks.
35//
36// STANDALONE: daslang.exe modules/dasImgui/examples/tutorial/docking.das
37// LIVE: daslang-live modules/dasImgui/examples/tutorial/docking.das
38//
39// DRIVE (when running live):
40// curl -X POST -d '{"name":"imgui_undock","args":{"target":"DOCK_ROOT/OUTPUT"}}' localhost:9090/command
41// curl -X POST -d '{"name":"imgui_set_window_pos","args":{"target":"DOCK_ROOT/OUTPUT","value":{"x":580,"y":220,"w":360,"h":220}}}' localhost:9090/command
42// curl -X POST -d '{"name":"imgui_dock_reset","args":{"target":"DOCK_ROOT"}}' localhost:9090/command
43// curl -X POST -d '{"name":"imgui_close","args":{"target":"DOCK_ROOT/OUTPUT"}}' localhost:9090/command
44//
45// Note: dockspace is a [container] that pushes its identifier onto the registry
46// path, so dock_window targets are path-qualified (``DOCK_ROOT/<name>``).
47// =============================================================================
48
49def setup_default_layout(dock_id : uint) {
50 //! Seed a 3-pane layout on the first frame:
51 //! +-----------+--------------------+
52 //! | | |
53 //! | | Source |
54 //! | Explorer | |
55 //! | +--------------------+
56 //! | | |
57 //! | | Output |
58 //! +-----------+--------------------+
59 //! Each pane's window-title string MUST match the corresponding
60 //! `dock_window`'s `text=` field; that's how ImGui ties dockable windows
61 //! to dock nodes.
62 DockBuilderRemoveNode(dock_id)
63 DockBuilderAddDockSpaceNode(dock_id, ImGuiDockNodeFlags.None)
64 let vp = GetMainViewport()
65 DockBuilderSetNodeSize(dock_id, ImVec2(vp.Size.x, vp.Size.y))
66 var left_id : uint = 0u
67 var right_id : uint = 0u
68 DockBuilderSplitNode(dock_id, ImGuiDir.Left, 0.25f, left_id, right_id)
69 var top_id : uint = 0u
70 var bottom_id : uint = 0u
71 DockBuilderSplitNode(right_id, ImGuiDir.Up, 0.6f, top_id, bottom_id)
72 DockBuilderDockWindow("Explorer", left_id)
73 DockBuilderDockWindow("Source", top_id)
74 DockBuilderDockWindow("Output", bottom_id)
75 DockBuilderFinish(dock_id)
76}
77
78[export]
79def init() {
80 live_create_window("dasImgui docking tutorial", 1024, 720)
81 live_imgui_init(live_window)
82 // Docking layout persists to imgui.ini; disable that so the recording always
83 // starts from setup_default_layout's seeded 3-pane arrangement (a leftover
84 // ini from a prior run would otherwise override the seed non-deterministically).
85 DisableIniPersistence()
86 var io & = unsafe(GetIO())
87 GetStyle().FontScaleMain = 1.5
88 // The single flag that turns docking on for the whole session. Without
89 // this, DockSpace() / DockSpaceOverViewport() render nothing.
90 io.ConfigFlags |= ImGuiConfigFlags.DockingEnable
91}
92
93[export]
94def update() {
95 if (!live_begin_frame()) return
96 begin_frame()
97
98 ImGui_ImplGlfw_NewFrame()
99 apply_synth_io_override()
100 NewFrame()
101
102 // Full-viewport dockspace. PassthruCentralNode lets the OS-window
103 // background show through the unsplit center (irrelevant here — we
104 // split everything — but it's the conventional default).
105 dockspace(DOCK_ROOT, (flags = ImGuiDockNodeFlags.PassthruCentralNode)) {
106 // Seed the layout once per session. has_initial_layout flips false on
107 // imgui_dock_reset; the renderer then re-runs setup. dock_id is
108 // captured by the dockspace wrapper before this block runs.
109 if (!DOCK_ROOT.has_initial_layout && DOCK_ROOT.dock_id != 0u) {
110 setup_default_layout(DOCK_ROOT.dock_id)
111 DOCK_ROOT.has_initial_layout = true
112 }
113 dock_window(EXPLORER, (text = "Explorer", closable = false,
114 flags = ImGuiWindowFlags.None)) {
115 text("Files")
116 button(REFRESH_BTN, (text = "Refresh"))
117 }
118 dock_window(SOURCE, (text = "Source", closable = false,
119 flags = ImGuiWindowFlags.None)) {
120 text("// drag tabs to rearrange")
121 text("// - layout sticks via imgui.ini")
122 button(SAVE_BTN, (text = "Save"))
123 }
124 dock_window(OUTPUT, (text = "Output", closable = true,
125 flags = ImGuiWindowFlags.None)) {
126 text("> ready.")
127 button(CLEAR_BTN, (text = "Clear"))
128 }
129 }
130
131 end_of_frame()
132 Render()
133 var w, h : int
134 live_get_framebuffer_size(w, h)
135 glViewport(0, 0, w, h)
136 glClearColor(0.10f, 0.10f, 0.12f, 1.0f)
137 glClear(GL_COLOR_BUFFER_BIT)
138 live_imgui_render()
139
140 live_end_frame()
141}
142
143[export]
144def shutdown() {
145 live_imgui_shutdown()
146 live_destroy_window()
147}
148
149[export]
150def main() {
151 init()
152 while (!exit_requested()) {
153 update()
154 }
155 shutdown()
156}
Requires
Same backend + boost layer as Layout, but layout helpers are replaced by the docking module:
imgui/imgui_docking_builtin— thedockspace,dockspace_in_window, anddock_windowmacros, plus theDockBuilder*bindings cherry-picked from ImGui’s internal API.
The flag that lights it up
ImGui docking is gated by a single io flag. Without it, DockSpace calls
render nothing and dock_window panels behave like ordinary windows:
io.ConfigFlags |= ImGuiConfigFlags.DockingEnable
This goes in init() once per session.
Seeding the layout
ImGui will happily start with every dockable window stacked in a single
tab-bar — the user is expected to drag tabs into place. For a tutorial we
ship a default arrangement via DockBuilder:
DockBuilderRemoveNode(dock_id) // clear any prior state
DockBuilderAddDockSpaceNode(dock_id, flags) // fresh dockspace root
DockBuilderSetNodeSize(dock_id, ImVec2(vp.Size.x, vp.Size.y))
var left_id, right_id : uint
DockBuilderSplitNode(dock_id, ImGuiDir.Left, 0.25f, left_id, right_id)
var top_id, bottom_id : uint
DockBuilderSplitNode(right_id, ImGuiDir.Up, 0.6f, top_id, bottom_id)
DockBuilderDockWindow("Explorer", left_id)
DockBuilderDockWindow("Source", top_id)
DockBuilderDockWindow("Output", bottom_id)
DockBuilderFinish(dock_id)
DockBuilderDockWindow matches by window title string — the same string
you pass to dock_window(NAME, (text = "Explorer")). The boost macro
doesn’t auto-derive the title from the identifier so the binding is
explicit.
The setup is gated on state.has_initial_layout so it runs once per
session — or after imgui_dock_reset flips the flag back to false.
Variant: dockspace inside a host window
dockspace wraps DockSpaceOverViewport — the dock region claims the
entire OS window. The sibling dockspace_in_window wraps the explicit
DockSpace(id, size, flags, null) call so the dock node lives INSIDE
an enclosing window(HOST, ...) rather than over the viewport. Use
this when the host window needs its own menu bar, decorations, or a
floating / moveable frame around the dockable area.
SetNextWindowSize(ImVec2(680.0f, 440.0f), ImGuiCond.FirstUseEver)
window(HOST, (text = "Editor",
closable = false,
flags = ImGuiWindowFlags.MenuBar |
ImGuiWindowFlags.NoDocking)) {
menu_bar(HOST_MENU) {
menu(FILE_MENU, (text = "File", enabled = true)) {
menu_item(SAVE_ITEM, (text = "Save"))
}
}
dockspace_in_window(DS, (size = float2(0.0f, 0.0f),
flags = ImGuiDockNodeFlags.None)) {
dock_window(FILES, (text = "Files", closable = false,
flags = ImGuiWindowFlags.None)) { ... }
dock_window(OUTPUT, (text = "Output", closable = false,
flags = ImGuiWindowFlags.None)) { ... }
}
}
The host’s ImGuiWindowFlags.MenuBar / NoDocking live on the
window call, not on dockspace_in_window — the dockspace container
only manages the dock node. size = (0,0) (typical) fills the host’s
available content region after the menu bar.
DS.dock_id is captured for DockBuilder* layout calls the same way
as dockspace — the choice between the two is purely about whether
you want the host frame around the dock area.
See examples/features/dockspace_in_window.das for the full
scene.
The frame loop
The dockspace(DOCK_ROOT, ...) macro wraps DockSpaceOverViewport —
the dock region is the entire OS window. Inside its block, each
dock_window(NAME, ...) is a Begin/End-wrapped panel that participates
in the docking system. Path-prefixing works the same as containers
(window / child / tab_bar): dock_window(EXPLORER) {
button(REFRESH_BTN, ...) } registers the button under
DOCK_ROOT/EXPLORER/REFRESH_BTN.
The closable = true option (on OUTPUT here) wires the X-button in
the tab to state.open — closing the panel without rebuilding the
layout.
Standalone vs live
Same as previous tutorials — main() runs the loop standalone;
daslang-live invokes init / update / shutdown directly.
ImGui’s docking state is preserved across reloads because the ImGui
context survives reload (imgui_live serializes the context pointer
through the reload, and the dock state lives inside that context).
Driving from outside
Several live commands cover the docking surface. Targets are path-qualified
— the dockspace pushes its name onto the path, so panel targets are
DOCK_ROOT/<name>:
# Pop Output out into a floating window
curl -X POST -d '{"name":"imgui_undock","args":{"target":"DOCK_ROOT/OUTPUT"}}' \
localhost:9090/command
# Reposition the floating window (also works on docked windows — ImGui ignores
# the SetNextWindowPos while a window is docked, so this is most useful after
# imgui_undock). w/h are optional.
curl -X POST -d '{"name":"imgui_set_window_pos","args":{"target":"DOCK_ROOT/OUTPUT","value":{"x":580,"y":220,"w":360,"h":220}}}' \
localhost:9090/command
# Reset the dockspace back to the default layout
curl -X POST -d '{"name":"imgui_dock_reset","args":{"target":"DOCK_ROOT"}}' \
localhost:9090/command
# Close the OUTPUT panel (X-button equivalent — closable=true required)
curl -X POST -d '{"name":"imgui_close","args":{"target":"DOCK_ROOT/OUTPUT"}}' \
localhost:9090/command
# Raise a panel to the front of its dock node — selects its tab when stacked
curl -X POST -d '{"name":"imgui_raise","args":{"target":"DOCK_ROOT/OUTPUT"}}' \
localhost:9090/command
imgui_dock is the inverse of imgui_undock — it takes a value of
type uint (a dock-node id from a prior DockBuilder* call) and
re-docks the panel into that node. imgui_set_window_pos is the
companion you’ll usually pair with imgui_undock, since a freshly
undocked window picks its position from imgui.ini (or (0,0) if
the window has never floated). imgui_raise brings a panel to the front
of its dock node — when several panels share a node (so they render as a tab
strip) it selects that panel’s tab; it’s the automation counterpart of
clicking a tab, which a real click can’t reach (the dock node’s tab bar is
ImGui-internal, not a registered widget).
Next steps
Style scopes are next — with_style for pushing colors and metrics
across a sub-tree of widgets, balanced pop, and how nesting stacks.
See also
Full source: examples/tutorial/docking.das
Richer reference: examples/features/dock_basic.das — same boost
surface with a 4-panel initial layout and a wider widget set.
Integration test: tests/integration/test_docking_basic.das —
registration, initial-layout geometry, and live-command round-trips.
Previous tutorial: Layout
Boost macros — the macro layer.