8.19.56. 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: modules/dasImgui/examples/tutorial/log_capture.das.
8.19.56.1. Walkthrough
1options gen2
2options _comment_hygiene = true
3options gc
4
5require imgui
6require imgui_app
7require opengl/opengl_boost
8require live/glfw_live
9require live/live_api
10require live/live_commands
11require live/live_vars
12require live_host
13require imgui/imgui_live
14require imgui/imgui_boost_runtime
15require imgui/imgui_boost_v2
16require imgui/imgui_widgets_builtin
17require imgui/imgui_containers_builtin
18require imgui/imgui_scope_builtin
19require imgui/imgui_visual_aids
20
21// =============================================================================
22// TUTORIAL: log_capture — capture rendered widget text with with_log.
23//
24// 1.92 renamed the log-target enum: ImGuiLogType -> ImGuiLogFlags, and the
25// values gained an Output prefix (TTY -> OutputTTY, Clipboard -> OutputClipboard,
26// File -> OutputFile, Buffer -> OutputBuffer). The boost with_log wrapper now
27// takes an ImGuiLogFlags:
28//
29// with_log(ImGuiLogFlags.OutputClipboard, -1) {
30// text("captured") // every widget's rendered text is logged
31// }
32//
33// LogBegin asserts logging is not already active, so with_log must NOT nest.
34//
35// STANDALONE: daslang.exe modules/dasImgui/examples/tutorial/log_capture.das
36// LIVE: daslang-live modules/dasImgui/examples/tutorial/log_capture.das
37// =============================================================================
38
39var private g_capture_count = 0
40var private g_last_clip = ""
41var private g_capture_requested = false
42
43[export]
44def init() {
45 live_create_window("dasImgui log_capture tutorial", 820, 600)
46 live_imgui_init(live_window)
47 let io & = unsafe(GetIO())
48 GetStyle().FontScaleMain = 1.3
49}
50
51[export]
52def update() {
53 if (!live_begin_frame()) return
54 begin_frame()
55
56 ImGui_ImplGlfw_NewFrame()
57 apply_synth_io_override()
58 NewFrame()
59
60 SetNextWindowPos(ImVec2(40.0f, 40.0f), ImGuiCond.Always)
61 SetNextWindowSize(ImVec2(740.0f, 520.0f), ImGuiCond.Always)
62 window(LC_WIN, (text = "log_capture", closable = false,
63 flags = ImGuiWindowFlags.None)) {
64 text("with_log(ImGuiLogFlags.OutputClipboard, -1) captures rendered widget")
65 text("text to the clipboard. Click to capture, then read it back below.")
66 separator()
67
68 if (button(LC_BTN, (text = "Capture report to clipboard"))) {
69 g_capture_requested = true
70 }
71 separator()
72
73 // The report renders every frame. On a capture frame, wrap it in a
74 // clipboard log so each widget's text lands in the clipboard, then read
75 // it straight back with GetClipboardText.
76 let capture_now = g_capture_requested
77 g_capture_requested = false
78 if (capture_now) {
79 g_capture_count++
80 with_log(ImGuiLogFlags.OutputClipboard, -1) {
81 text("=== Daslang Widget Report ===")
82 text("Section: Fruits")
83 text(" Apple, Banana, Cherry")
84 LogRenderedText("(injected via LogRenderedText - capture #{g_capture_count})")
85 }
86 g_last_clip = GetClipboardText()
87 } else {
88 text("=== Daslang Widget Report ===")
89 text("Section: Fruits")
90 text(" Apple, Banana, Cherry")
91 }
92
93 separator()
94 text("Captures so far: {g_capture_count}. The injected line below appears ONLY")
95 text("in the capture, never in the on-screen report above:")
96 child(LC_VIEW, (text = "clip", size = float2(660.0f, 200.0f),
97 child_flags = ImGuiChildFlags.Borders,
98 window_flags = ImGuiWindowFlags.None)) {
99 text(LC_TEXT, (text = g_last_clip))
100 }
101 }
102
103 end_of_frame()
104 Render()
105 var w, h : int
106 live_get_framebuffer_size(w, h)
107 glViewport(0, 0, w, h)
108 glClearColor(0.10f, 0.10f, 0.12f, 1.0f)
109 glClear(GL_COLOR_BUFFER_BIT)
110 live_imgui_render()
111
112 live_end_frame()
113}
114
115[export]
116def shutdown() {
117 live_imgui_shutdown()
118 live_destroy_window()
119}
120
121[export]
122def main() {
123 init()
124 while (!exit_requested()) {
125 update()
126 maybe_collect_gc()
127 }
128 shutdown()
129}
8.19.56.1.1. Requires
with_log is in imgui/imgui_scope_builtin — require it explicitly,
the way the companion does; the baseline boost layer does not pull it in.
GetClipboardText and LogRenderedText are in the carve-out of raw
calls the lint allows.
8.19.56.1.2. 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.
8.19.56.1.3. 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: modules/dasImgui/examples/tutorial/log_capture.das
Feature smoke: modules/dasImgui/examples/features/internal_log_capture.das.
Boost macros — the macro layer.