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: examples/tutorial/input_text.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_visual_aids
17require strings
18
19// =============================================================================
20// TUTORIAL: input_text family — text editing widgets.
21//
22// input_text(IDENT, (text = "..", flags = ImGuiInputTextFlags....))
23// input_text_with_hint(IDENT, (text, hint, flags))
24// input_text_multiline(IDENT, (text, size = float2(w, h), flags))
25// input_text_growable(IDENT, (text, flags)) — auto-grows buffer
26// input_text_callback(IDENT, text, flags, cb) — user callback
27// text_filter(IDENT, (text, width)) + passes_filter(IDENT, line)
28//
29// Six widgets, six modalities sharing one InputTextState struct (text_filter
30// uses TextFilterState — different shape, integrates with the family).
31//
32// STANDALONE: daslang.exe modules/dasImgui/examples/tutorial/input_text.das
33// LIVE: daslang-live modules/dasImgui/examples/tutorial/input_text.das
34//
35// DRIVE (when running live):
36// curl -X POST -d '{"name":"imgui_force_set","args":{"target":"IT_WIN/IT_NAME","value":"hello"}}' \
37// localhost:9090/command
38// curl -X POST -d '{"name":"imgui_force_set","args":{"target":"IT_WIN/IT_BIO","value":"line1\nline2"}}' \
39// localhost:9090/command
40// =============================================================================
41
42let private COMMANDS <- ["help", "history", "clear", "classify", "echo", "exit"]
43
44let private LOG_LINES <- [
45 "[info] startup complete",
46 "[warn] cache miss for key=42",
47 "[info] connected to api.example.com",
48 "[error] failed to write tmp/foo: disk full",
49 "[info] saved settings",
50 "[debug] frame budget = 16.6ms"
51]
52
53//! Indexed-form text widget requires explicit table declaration at module scope.
54var private IT_LINE : table<int; NarrativeState>
55
56
57def private completion_cb(var data : ImGuiInputTextCallbackData) : int {
58 if (data.EventFlag == ImGuiInputTextFlags.CallbackCompletion) {
59 let prefix = clone_string(data.Buf)
60 var matches <- [for (c in COMMANDS); c; where c |> starts_with(prefix)]
61 if (length(matches) == 1) {
62 data |> DeleteChars(0, data.BufTextLen)
63 data |> InsertChars(0, matches[0])
64 }
65 delete matches
66 }
67 return 0
68}
69
70[export]
71def init() {
72 live_create_window("dasImgui input_text tutorial", 760, 760)
73 live_imgui_init(live_window)
74 let io & = unsafe(GetIO())
75 GetStyle().FontScaleMain = 1.4
76}
77
78[export]
79def update() {
80 if (!live_begin_frame()) return
81 begin_frame()
82
83 ImGui_ImplGlfw_NewFrame()
84 apply_synth_io_override()
85 NewFrame()
86
87 SetNextWindowPos(ImVec2(20.0f, 20.0f), ImGuiCond.Always)
88 SetNextWindowSize(ImVec2(720.0f, 720.0f), ImGuiCond.Always)
89 window(IT_WIN, (text = "input_text tutorial", closable = false,
90 flags = ImGuiWindowFlags.None)) {
91
92 // ---- Stage 1: basic input_text ----
93 input_text(IT_NAME, (text = "name"))
94 text("IT_NAME.value = '{IT_NAME.value}' (capacity={IT_NAME.capacity})")
95 spacing()
96
97 // ---- Stage 2: with_hint — placeholder when empty ----
98 input_text_with_hint(IT_EMAIL, (text = "email",
99 hint = "you@example.com"))
100 text("IT_EMAIL.value = '{IT_EMAIL.value}'")
101 spacing()
102
103 // ---- Stage 3: multiline — CR/LF tolerant, sized box ----
104 input_text_multiline(IT_BIO, (text = "bio",
105 size = float2(0.0f, 90.0f)))
106 text("IT_BIO length = {length(IT_BIO.value)} bytes")
107 spacing()
108
109 // ---- Stage 4: growable — buffer expands past `capacity` automatically ----
110 input_text_growable(IT_FREE, (text = "free-form"))
111 text("IT_FREE capacity = {IT_FREE.capacity}, length = {length(IT_FREE.value)}")
112 spacing()
113
114 // ---- Stage 5: callback — TAB completes against COMMANDS dictionary ----
115 text("Type a prefix (h/cla/ex) and press TAB:")
116 if (input_text_callback(IT_CMD, "command",
117 ImGuiInputTextFlags.CallbackCompletion,
118 @(var data : ImGuiInputTextCallbackData) =>
119 completion_cb(data))) {}
120 spacing()
121 separator()
122
123 // ---- Stage 6: text_filter — incl,-excl token filter ----
124 text("text_filter - type 'info' or '-debug' to filter the log:")
125 text_filter(IT_FILTER)
126 for (i in range(length(LOG_LINES))) {
127 if (passes_filter(IT_FILTER, LOG_LINES[i])) {
128 text(IT_LINE[i], (text = LOG_LINES[i]))
129 }
130 }
131 }
132
133 end_of_frame()
134 Render()
135 var w, h : int
136 live_get_framebuffer_size(w, h)
137 glViewport(0, 0, w, h)
138 glClearColor(0.10f, 0.10f, 0.12f, 1.0f)
139 glClear(GL_COLOR_BUFFER_BIT)
140 live_imgui_render()
141
142 live_end_frame()
143}
144
145[export]
146def shutdown() {
147 live_imgui_shutdown()
148 live_destroy_window()
149}
150
151[export]
152def main() {
153 init()
154 while (!exit_requested()) {
155 update()
156 }
157 shutdown()
158}
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.
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.
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
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).
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.
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).
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.
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: examples/tutorial/input_text.das
Features-side demos: examples/features/inputs_text.das (all five
non-filter forms) and examples/features/input_text_callback.das
(canonical TAB-completion).
Sibling tutorial: Input numeric widgets.
Boost macros — the macro layer.