Log capture
ImGui’s logging API captures the rendered text of every widget submitted
inside a log scope to a target (TTY, file, clipboard, or an in-memory buffer).
Dear ImGui 1.92 renamed the target enum from ImGuiLogType to
ImGuiLogFlags and gave the values an Output prefix
(OutputTTY / OutputFile / OutputClipboard / OutputBuffer). The
boost with_log wrapper takes the renamed enum:
with_log(ImGuiLogFlags.OutputClipboard, -1) {
text("=== Daslang Widget Report ===")
text("Section: Fruits")
LogRenderedText("(this line is captured but never drawn)")
}
let captured = GetClipboardText()
The second argument is the tree depth to auto-expand (-1 = default).
LogBegin asserts that logging is not already active, so with_log must
not nest.
Source: examples/tutorial/log_capture.das.
Walkthrough
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_containers_builtin
16require imgui/imgui_scope_builtin
17require imgui/imgui_visual_aids
18
19// =============================================================================
20// TUTORIAL: log_capture — capture rendered widget text with with_log.
21//
22// 1.92 renamed the log-target enum: ImGuiLogType -> ImGuiLogFlags, and the
23// values gained an Output prefix (TTY -> OutputTTY, Clipboard -> OutputClipboard,
24// File -> OutputFile, Buffer -> OutputBuffer). The boost with_log wrapper now
25// takes an ImGuiLogFlags:
26//
27// with_log(ImGuiLogFlags.OutputClipboard, -1) {
28// text("captured") // every widget's rendered text is logged
29// }
30//
31// LogBegin asserts logging is not already active, so with_log must NOT nest.
32//
33// STANDALONE: daslang.exe modules/dasImgui/examples/tutorial/log_capture.das
34// LIVE: daslang-live modules/dasImgui/examples/tutorial/log_capture.das
35// =============================================================================
36
37var private g_capture_count = 0
38var private g_last_clip = ""
39var private g_capture_requested = false
40
41[export]
42def init() {
43 live_create_window("dasImgui log_capture tutorial", 820, 600)
44 live_imgui_init(live_window)
45 let io & = unsafe(GetIO())
46 GetStyle().FontScaleMain = 1.3
47}
48
49[export]
50def update() {
51 if (!live_begin_frame()) return
52 begin_frame()
53
54 ImGui_ImplGlfw_NewFrame()
55 apply_synth_io_override()
56 NewFrame()
57
58 SetNextWindowPos(ImVec2(40.0f, 40.0f), ImGuiCond.Always)
59 SetNextWindowSize(ImVec2(740.0f, 520.0f), ImGuiCond.Always)
60 window(LC_WIN, (text = "log_capture", closable = false,
61 flags = ImGuiWindowFlags.None)) {
62 text("with_log(ImGuiLogFlags.OutputClipboard, -1) captures rendered widget")
63 text("text to the clipboard. Click to capture, then read it back below.")
64 separator()
65
66 if (button(LC_BTN, (text = "Capture report to clipboard"))) {
67 g_capture_requested = true
68 }
69 separator()
70
71 // The report renders every frame. On a capture frame, wrap it in a
72 // clipboard log so each widget's text lands in the clipboard, then read
73 // it straight back with GetClipboardText.
74 let capture_now = g_capture_requested
75 g_capture_requested = false
76 if (capture_now) {
77 g_capture_count++
78 with_log(ImGuiLogFlags.OutputClipboard, -1) {
79 text("=== Daslang Widget Report ===")
80 text("Section: Fruits")
81 text(" Apple, Banana, Cherry")
82 LogRenderedText("(injected via LogRenderedText - capture #{g_capture_count})")
83 }
84 g_last_clip := GetClipboardText()
85 } else {
86 text("=== Daslang Widget Report ===")
87 text("Section: Fruits")
88 text(" Apple, Banana, Cherry")
89 }
90
91 separator()
92 text("Captures so far: {g_capture_count}. The injected line below appears ONLY")
93 text("in the capture, never in the on-screen report above:")
94 child(LC_VIEW, (text = "clip", size = float2(660.0f, 200.0f),
95 child_flags = ImGuiChildFlags.Borders,
96 window_flags = ImGuiWindowFlags.None)) {
97 text(LC_TEXT, (text = g_last_clip))
98 }
99 }
100
101 end_of_frame()
102 Render()
103 var w, h : int
104 live_get_framebuffer_size(w, h)
105 glViewport(0, 0, w, h)
106 glClearColor(0.10f, 0.10f, 0.12f, 1.0f)
107 glClear(GL_COLOR_BUFFER_BIT)
108 live_imgui_render()
109
110 live_end_frame()
111}
112
113[export]
114def shutdown() {
115 live_imgui_shutdown()
116 live_destroy_window()
117}
118
119[export]
120def main() {
121 init()
122 while (!exit_requested()) {
123 update()
124 }
125 shutdown()
126}
Requires
with_log is in imgui/imgui_scope_builtin (re-exported by
imgui/imgui_boost_v2). GetClipboardText and LogRenderedText are in
the carve-out of raw calls the lint allows.
Behaviour
Each widget submitted inside the
with_logblock has its rendered text appended to the chosen target.LogRenderedTextinjects a line into the capture that is never drawn on screen — useful for machine-readable markers.On the capture frame the demo logs to the clipboard, then reads it straight back with
GetClipboardTextand displays it in a child panel, so you can see exactly what was captured.
Migration note
Pre-1.92 code calling LogBegin(ImGuiLogType.Clipboard, ...) — or
with_log(ImGuiLogType.Clipboard, ...) — should move to
ImGuiLogFlags.OutputClipboard (and the matching Output* value for other
targets).
See also
Full source: examples/tutorial/log_capture.das
Feature smoke: examples/features/internal_log_capture.das.
Boost macros — the macro layer.