8.19.41. Input numeric widgets
The input_* numeric family is type-the-number editing: click to
focus, type, Enter to commit. Optional + / - step buttons turn
scalar forms into discrete-step editors. Same call shape spans scalar /
vector / double-precision — nine widgets, one mental model.
input_float(IDENT, (text = "..", step = 0.0f, step_fast = 0.0f,
format = "%.3f", flags = ImGuiInputTextFlags....))
input_int(IDENT, (text = "..", step = 1, step_fast = 100,
flags = ImGuiInputTextFlags....))
input_double(IDENT, (text = "..", step = 0.0lf, step_fast = 0.0lf,
format = "%.6f"))
input_float2 / input_float3 / input_float4 // vector — format + flags, no step
input_int2 / input_int3 / input_int4 // vector — flags only
No bounds. input_* is for typed entry; if you need clamped
scrubbing, use Drag widgets or Slider widgets.
Source: modules/dasImgui/examples/tutorial/input_numeric.das.
8.19.41.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
19
20// =============================================================================
21// TUTORIAL: input_numeric widgets — type the number, optionally with
22// +/- step buttons.
23//
24// input_float(IDENT, (text = "..", step = 0.0f, step_fast = 0.0f,
25// format = "%.3f", flags = ImGuiInputTextFlags....))
26// input_int(IDENT, (text = "..", step = 1, step_fast = 100,
27// flags = ImGuiInputTextFlags....))
28// input_double / input_float2/3/4 / input_int2/3/4 — same shape;
29// scalar / vector / double-precision variants.
30//
31// Scalar forms get step / step_fast args — non-zero shows ImGui's +/-
32// buttons, click = step, ctrl-click = step_fast. Vector forms (2/3/4)
33// have no step args — the buttons would crowd the row.
34//
35// Default int step = 1 / step_fast = 100; float defaults are 0.0 (no
36// buttons). input_double defaults to 0.0lf (no buttons) with format
37// "%.6f" for the extra precision.
38//
39// STANDALONE: daslang.exe modules/dasImgui/examples/tutorial/input_numeric.das
40// LIVE: daslang-live modules/dasImgui/examples/tutorial/input_numeric.das
41//
42// DRIVE (when running live):
43// curl -X POST -d '{"name":"imgui_force_set","args":{"target":"IN_WIN/I_FLOAT","value":12.5}}' \
44// localhost:9090/command
45// curl -X POST -d '{"name":"imgui_force_set","args":{"target":"IN_WIN/I_VEC3","value":[1.0,2.0,3.0]}}' \
46// localhost:9090/command
47// =============================================================================
48
49[export]
50def init() {
51 live_create_window("dasImgui input_numeric tutorial", 760, 560)
52 live_imgui_init(live_window)
53 let io & = unsafe(GetIO())
54 GetStyle().FontScaleMain = 1.4
55}
56
57[export]
58def update() {
59 if (!live_begin_frame()) return
60 begin_frame()
61
62 ImGui_ImplGlfw_NewFrame()
63 apply_synth_io_override()
64 NewFrame()
65
66 SetNextWindowPos(ImVec2(20.0f, 20.0f), ImGuiCond.Always)
67 SetNextWindowSize(ImVec2(720.0f, 520.0f), ImGuiCond.Always)
68 window(IN_WIN, (text = "input_numeric tutorial", closable = false,
69 flags = ImGuiWindowFlags.None)) {
70
71 text("Click to focus, type the number, Enter to commit.")
72 text(I_HINT, (text = "Scalar forms have step / step_fast - non-zero shows +/- buttons."))
73 separator()
74
75 // ---- Stage 1: scalar float with step buttons ----
76 input_float(I_FLOAT, (text = "mass (kg)",
77 step = 0.1f, step_fast = 1.0f,
78 format = "%.3f"))
79 text("I_FLOAT.value = {I_FLOAT.value}")
80 spacing()
81
82 // ---- Stage 2: scalar int with step buttons ----
83 input_int(I_INT, (text = "level",
84 step = 1, step_fast = 100))
85 text("I_INT.value = {I_INT.value}")
86 spacing()
87
88 // ---- Stage 3: vector float3 — no step buttons (vector forms omit them) ----
89 input_float3(I_VEC3, (text = "position", format = "%.2f"))
90 text("I_VEC3.value = ({I_VEC3.value.x}, {I_VEC3.value.y}, {I_VEC3.value.z})")
91 spacing()
92
93 // ---- Stage 4: double precision ----
94 input_double(I_DOUBLE, (text = "epoch (s)",
95 step = 1.0lf, step_fast = 60.0lf,
96 format = "%.6f"))
97 text("I_DOUBLE.value = {I_DOUBLE.value}")
98 }
99
100 end_of_frame()
101 Render()
102 var w, h : int
103 live_get_framebuffer_size(w, h)
104 glViewport(0, 0, w, h)
105 glClearColor(0.10f, 0.10f, 0.12f, 1.0f)
106 glClear(GL_COLOR_BUFFER_BIT)
107 live_imgui_render()
108
109 live_end_frame()
110}
111
112[export]
113def shutdown() {
114 live_imgui_shutdown()
115 live_destroy_window()
116}
117
118[export]
119def main() {
120 init()
121 while (!exit_requested()) {
122 update()
123 maybe_collect_gc()
124 }
125 shutdown()
126}
8.19.41.1.1. Requires
Already in the baseline boost layer:
imgui/imgui_widgets_builtin— everyinput_*numeric rail.imgui/imgui_boost_runtime—InputStateFloat/InputStateInt/InputStateDouble(+ vector variants) state structs.
The caller-owned form at the end of this page also needs
daslib/safe_addr for safe_addr.
8.19.41.1.3. Format
format is the printf-style label format, on the float and double
forms only. Defaults are sane for most cases; bump precision when the
user needs to see it:
input_float(MASS, (text = "mass", format = "%.6f")) // 6 decimal places
input_float3(BOX, (text = "box", format = "%.1f")) // vectors take it too
input_double(EPOCH, (text = "epoch", format = "%.9f")) // sub-ns precision
The input_int* forms take no format argument — ImGui’s
InputInt picks the format itself (%d, or %08X when
CharsHexadecimal is set, see Flags below).
8.19.41.1.4. Vector forms
Same 2 / 3 / 4 convention — that many fields on one row.
state.value becomes float2 / float3 / float4 (or
int2 / int3 / int4). Tab cycles between components; Enter
commits the whole row.
input_float3(POSITION, (text = "position", format = "%.2f"))
// POSITION.value.x, POSITION.value.y, POSITION.value.z
8.19.41.1.5. Double precision
input_double is the only path to double-precision values in the
input family — drag and slider don’t have a double variant. Use it for
timestamps, geographic coordinates, anything that needs more than 7
significant digits:
input_double(EPOCH_SEC, (text = "epoch",
step = 1.0lf, step_fast = 60.0lf,
format = "%.6f"))
Default format "%.6f" (six places) vs input_float’s "%.3f"
reflects the extra precision.
8.19.41.1.6. Flags
flags : ImGuiInputTextFlags carries the standard text-input modifiers
— CharsDecimal, CharsHexadecimal, CharsScientific,
ReadOnly, Password (rarely useful on numeric inputs but
allowed), EscapeClearsAll, etc. Composable via |:
input_int(HEX_ADDR, (text = "addr",
flags = ImGuiInputTextFlags.CharsHexadecimal))
// ImGui renders and parses this field as %08X on its own
8.19.41.1.7. Driving from outside
Every input_* widget exposes the same telemetry channel as drag and
slider — imgui_force_set writes state.pending_value which the next
frame consumes:
# Scalar:
curl -X POST -d '{"name":"imgui_force_set","args":{"target":"IN_WIN/I_FLOAT","value":12.5}}' \
localhost:9090/command
# Vector — one number per component:
curl -X POST -d '{"name":"imgui_force_set","args":{"target":"IN_WIN/I_VEC3","value":[1.0,2.0,3.0]}}' \
localhost:9090/command
The dispatcher ([widget_dispatch] on InputStateFloat and
friends) accepts the right JSON shape per state type.
8.19.41.1.8. Input vs drag vs slider
The three numeric-edit families differ in interaction shape:
input — type the number, optionally with step buttons. Best for precise values where the user already knows the number.
drag — click and scrub, no fixed track. Best for “tweak this value” with open-ended range.
slider — click and drag along a fixed-width track between
v_min/v_max. Best for bounded percentages, settings.
All three families share vector / scalar / format conventions. See Drag widgets and Slider widgets.
8.19.41.1.9. Caller-owned variant
For sites where the value lives on an external scalar (not a widget
state struct), use the edit_input_* rail instead — it takes a
T? pointer via safe_addr and skips the state-struct allocation:
var g_mass : float = 1.0f
edit_input_float(safe_addr(g_mass), (id = "MASS",
text = "mass", step = 0.1f))
See External-pointer editing rail.
See also
Full source: modules/dasImgui/examples/tutorial/input_numeric.das
Features-side demo: modules/dasImgui/examples/features/inputs_numeric.das — every
numeric input in one window, useful for imgui_force_set smoke testing.
Sibling tutorials: Drag widgets, Slider widgets, Input text widgets.
Boost macros — the macro layer.