8.19.42. Input text widgets
The input_text family is text editing — single-line, multiline,
grow-on-overflow, callback-driven, and the inline filter editor. Six
widgets, one InputTextState (text_filter uses its own
TextFilterState).
input_text(IDENT, (text = "..", flags = ImGuiInputTextFlags....))
input_text_with_hint(IDENT, (text, hint, flags))
input_text_multiline(IDENT, (text, size = float2(w, h), flags))
input_text_growable(IDENT, (text, flags)) // CallbackResize plumbed
input_text_callback(IDENT, text, flags, cb) // user lambda on flagged events
text_filter(IDENT, (text, width)) + passes_filter(IDENT, line)
Buffer-as-pointer path: state owns array<uint8> buffer + a string
mirror. input_text_growable plumbs ImGui’s CallbackResize through
a daslang lambda + stack thunk so the buffer expands past
state.capacity automatically.
Source: modules/dasImgui/examples/tutorial/input_text.das.
8.19.42.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_visual_aids
19require strings
20
21// =============================================================================
22// TUTORIAL: input_text family — text editing widgets.
23//
24// input_text(IDENT, (text = "..", flags = ImGuiInputTextFlags....))
25// input_text_with_hint(IDENT, (text, hint, flags))
26// input_text_multiline(IDENT, (text, size = float2(w, h), flags))
27// input_text_growable(IDENT, (text, flags)) — auto-grows buffer
28// input_text_callback(IDENT, text, flags, cb) — user callback
29// text_filter(IDENT, (text, width)) + passes_filter(IDENT, line)
30//
31// Six widgets, six modalities sharing one InputTextState struct (text_filter
32// uses TextFilterState — different shape, integrates with the family).
33//
34// STANDALONE: daslang.exe modules/dasImgui/examples/tutorial/input_text.das
35// LIVE: daslang-live modules/dasImgui/examples/tutorial/input_text.das
36//
37// DRIVE (when running live):
38// curl -X POST -d '{"name":"imgui_force_set","args":{"target":"IT_WIN/IT_NAME","value":"hello"}}' \
39// localhost:9090/command
40// curl -X POST -d '{"name":"imgui_force_set","args":{"target":"IT_WIN/IT_BIO","value":"line1\nline2"}}' \
41// localhost:9090/command
42// =============================================================================
43
44let private COMMANDS <- ["help", "history", "clear", "classify", "echo", "exit"]
45
46let private LOG_LINES <- [
47 "[info] startup complete",
48 "[warn] cache miss for key=42",
49 "[info] connected to api.example.com",
50 "[error] failed to write tmp/foo: disk full",
51 "[info] saved settings",
52 "[debug] frame budget = 16.6ms"
53]
54
55//! Indexed-form text widget requires explicit table declaration at module scope.
56var private IT_LINE : table<int; NarrativeState>
57
58
59def private completion_cb(var data : ImGuiInputTextCallbackData) : int {
60 if (data.EventFlag == ImGuiInputTextFlags.CallbackCompletion) {
61 let prefix = clone_string(data.Buf)
62 var matches <- [for (c in COMMANDS); c; where c |> starts_with(prefix)]
63 if (length(matches) == 1) {
64 data |> DeleteChars(0, data.BufTextLen)
65 data |> InsertChars(0, matches[0])
66 }
67 delete matches
68 }
69 return 0
70}
71
72[export]
73def init() {
74 live_create_window("dasImgui input_text tutorial", 760, 760)
75 live_imgui_init(live_window)
76 let io & = unsafe(GetIO())
77 GetStyle().FontScaleMain = 1.4
78}
79
80[export]
81def update() {
82 if (!live_begin_frame()) return
83 begin_frame()
84
85 ImGui_ImplGlfw_NewFrame()
86 apply_synth_io_override()
87 NewFrame()
88
89 SetNextWindowPos(ImVec2(20.0f, 20.0f), ImGuiCond.Always)
90 SetNextWindowSize(ImVec2(720.0f, 720.0f), ImGuiCond.Always)
91 window(IT_WIN, (text = "input_text tutorial", closable = false,
92 flags = ImGuiWindowFlags.None)) {
93
94 // ---- Stage 1: basic input_text ----
95 input_text(IT_NAME, (text = "name"))
96 text("IT_NAME.value = '{IT_NAME.value}' (capacity={IT_NAME.capacity})")
97 spacing()
98
99 // ---- Stage 2: with_hint — placeholder when empty ----
100 input_text_with_hint(IT_EMAIL, (text = "email",
101 hint = "you@example.com"))
102 text("IT_EMAIL.value = '{IT_EMAIL.value}'")
103 spacing()
104
105 // ---- Stage 3: multiline — CR/LF tolerant, sized box ----
106 input_text_multiline(IT_BIO, (text = "bio",
107 size = float2(0.0f, 90.0f)))
108 text("IT_BIO length = {length(IT_BIO.value)} bytes")
109 spacing()
110
111 // ---- Stage 4: growable — buffer expands past `capacity` automatically ----
112 input_text_growable(IT_FREE, (text = "free-form"))
113 text("IT_FREE capacity = {IT_FREE.capacity}, length = {length(IT_FREE.value)}")
114 spacing()
115
116 // ---- Stage 5: callback — TAB completes against COMMANDS dictionary ----
117 text("Type a prefix (h/cla/ex) and press TAB:")
118 if (input_text_callback(IT_CMD, "command",
119 ImGuiInputTextFlags.CallbackCompletion,
120 @(var data : ImGuiInputTextCallbackData) =>
121 completion_cb(data))) {}
122 spacing()
123 separator()
124
125 // ---- Stage 6: text_filter — incl,-excl token filter ----
126 text("text_filter - type 'info' or '-debug' to filter the log:")
127 text_filter(IT_FILTER)
128 for (i in range(length(LOG_LINES))) {
129 if (passes_filter(IT_FILTER, LOG_LINES[i])) {
130 text(IT_LINE[i], (text = LOG_LINES[i]))
131 }
132 }
133 }
134
135 end_of_frame()
136 Render()
137 var w, h : int
138 live_get_framebuffer_size(w, h)
139 glViewport(0, 0, w, h)
140 glClearColor(0.10f, 0.10f, 0.12f, 1.0f)
141 glClear(GL_COLOR_BUFFER_BIT)
142 live_imgui_render()
143
144 live_end_frame()
145}
146
147[export]
148def shutdown() {
149 live_imgui_shutdown()
150 live_destroy_window()
151}
152
153[export]
154def main() {
155 init()
156 while (!exit_requested()) {
157 update()
158 maybe_collect_gc()
159 }
160 shutdown()
161}
8.19.42.1.1. Requires
Already in the baseline boost layer:
imgui/imgui_widgets_builtin— everyinput_text*rail +text_filter+passes_filter.imgui/imgui_boost_runtime—InputTextState(buffer + mirror) andTextFilterState(boundImGuiTextFilterinline).strings— forstarts_withused in the callback completion stage.
8.19.42.1.2. Basic and with_hint
input_text is the single-line editor backed by a fixed-size buffer
(state.capacity, default 256 bytes). input_text_with_hint adds a
placeholder rendered when the buffer is empty:
input_text(NAME, (text = "name"))
input_text_with_hint(EMAIL, (text = "email",
hint = "you@example.com"))
Both share InputTextState. state.value is a clone of the buffer
content updated each frame.
8.19.42.1.3. Multiline
input_text_multiline accepts CR / LF and exposes a sized text box.
size = float2(0, 0) lets ImGui pick a default rect — wide and short.
Pass an explicit (w, h) for editor-style panels:
input_text_multiline(BIO, (text = "bio",
size = float2(0.0f, 90.0f))) // 90px tall
8.19.42.1.4. Growable
input_text_growable is the same as input_text but the buffer
resizes itself when the user types past state.capacity. ImGui’s
CallbackResize event is plumbed through a daslang lambda; the thunk
holding (Context*, LineInfo*, lambda) lives on the C call stack for
the duration of the ImGui::InputText call:
input_text_growable(FREE, (text = "free-form"))
// state.capacity grows as needed; state.buffer follows
Use this when the input is genuinely free-form (notes, code, long URLs); use the fixed-size form when 256 bytes is enough (names, emails, identifiers).
8.19.42.1.5. Callback
input_text_callback takes an extra cb arg — a lambda fired by
ImGui on flagged events. Wire the events you want via flags:
CallbackCompletion— TAB pressedCallbackHistory— Up/Down arrowsCallbackAlways— every frame the field is activeCallbackCharFilter— per-character; return non-zero to rejectCallbackEdit— buffer modifiedCallbackResize— buffer overflow (useinput_text_growablefor the standard impl)
input_text_callback(CMD, "command",
ImGuiInputTextFlags.CallbackCompletion,
@(var data : ImGuiInputTextCallbackData) =>
completion_cb(data))
The data : ImGuiInputTextCallbackData pointer is valid only inside
the call. data.Buf is the current buffer; DeleteChars /
InsertChars are the in-place edit helpers. Cloning data.Buf to a
daslang string + doing the matching in pure das is the common pattern.
8.19.42.1.6. text_filter
text_filter renders an inline InputText editor whose buffer is
parsed as comma-separated tokens:
foo,bar— pass lines containingfooORbar-debug— exclude lines containingdebuginfo,-debug— combine
Pair with passes_filter(STATE, line) : bool to gate output:
text_filter(FILTER)
for (i in range(length(LOG_LINES))) {
if (passes_filter(FILTER, LOG_LINES[i])) {
text(LOG_LINE[i], (text = LOG_LINES[i]))
}
}
While the filter expression is empty, passes_filter returns true
for every line — the filter is silently disabled until the user types.
Use is_active(STATE) to branch on filter-empty vs filter-non-empty
when you want a different code path (e.g. clipper-cull vs sequential
scan).
8.19.42.1.7. Indexed-form note
The text(IDENT[i], (text = ...)) form requires you to declare the
table at module scope:
var private LOG_LINE : table<int; NarrativeState>
The single-state form (text(IDENT, (text = ...))) auto-emits the
state global from the macro. Indexed form does not — the table key type
needs the user’s hand.
8.19.42.1.8. Driving from outside
The walkthrough above types into every field with real synthetic key
events (a real click to focus, then imgui_key_type), so it exercises
exactly what a user would: the completion callback fires on Tab, the filter
narrows the log as you type, and one \n in the multiline buffer inserts
exactly one line break. For scripted setup that skips the keystrokes,
imgui_force_set writes state.pending_value and the next frame
overwrites the buffer:
curl -X POST -d '{"name":"imgui_force_set","args":{"target":"IT_WIN/IT_NAME","value":"hello"}}' \
localhost:9090/command
# Multiline content — embed \n in the JSON string:
curl -X POST -d '{"name":"imgui_force_set","args":{"target":"IT_WIN/IT_BIO","value":"line 1\nline 2"}}' \
localhost:9090/command
For input_text_growable, sending a payload longer than current
state.capacity triggers CallbackResize on the same frame the
buffer is consumed.
text_filter is currently read-only via telemetry — there’s no
imgui_force_set path that writes the filter expression. Click the filter
field and type directly to change it.
See also
Full source: modules/dasImgui/examples/tutorial/input_text.das
Features-side demos: modules/dasImgui/examples/features/inputs_text.das (all five
non-filter forms) and modules/dasImgui/examples/features/input_text_callback.das
(canonical TAB-completion).
Sibling tutorial: Input numeric widgets.
Boost macros — the macro layer.