8.18.1.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 — no step args
input_int2   / input_int3   / input_int4

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.18.1.41.1. Walkthrough

  1options gen2
  2options _comment_hygiene = true
  3
  4require imgui
  5require imgui_app
  6require opengl/opengl_boost
  7require live/glfw_live
  8require live/live_api
  9require live/live_commands
 10require live/live_vars
 11require live_host
 12require imgui/imgui_live
 13require imgui/imgui_boost_runtime
 14require imgui/imgui_boost_v2
 15require imgui/imgui_widgets_builtin
 16require imgui/imgui_containers_builtin
 17require imgui/imgui_visual_aids
 18
 19// =============================================================================
 20// TUTORIAL: input_numeric widgets — type the number, optionally with
 21// +/- step buttons.
 22//
 23//   input_float(IDENT, (text = "..", step = 0.0f, step_fast = 0.0f,
 24//                       format = "%.3f", flags = ImGuiInputTextFlags....))
 25//   input_int(IDENT, (text = "..", step = 1, step_fast = 100,
 26//                     flags = ImGuiInputTextFlags....))
 27//   input_double / input_float2/3/4 / input_int2/3/4 — same shape;
 28//   scalar / vector / double-precision variants.
 29//
 30// Scalar forms get step / step_fast args — non-zero shows ImGui's +/-
 31// buttons, click = step, ctrl-click = step_fast. Vector forms (2/3/4)
 32// have no step args — the buttons would crowd the row.
 33//
 34// Default int step = 1 / step_fast = 100; float defaults are 0.0 (no
 35// buttons). input_double defaults to 0.0lf (no buttons) with format
 36// "%.6f" for the extra precision.
 37//
 38// STANDALONE: daslang.exe modules/dasImgui/examples/tutorial/input_numeric.das
 39// LIVE:       daslang-live modules/dasImgui/examples/tutorial/input_numeric.das
 40//
 41// DRIVE (when running live):
 42//   curl -X POST -d '{"name":"imgui_force_set","args":{"target":"IN_WIN/I_FLOAT","value":12.5}}' \
 43//        localhost:9090/command
 44//   curl -X POST -d '{"name":"imgui_force_set","args":{"target":"IN_WIN/I_VEC3","value":[1.0,2.0,3.0]}}' \
 45//        localhost:9090/command
 46// =============================================================================
 47
 48[export]
 49def init() {
 50    live_create_window("dasImgui input_numeric tutorial", 760, 560)
 51    live_imgui_init(live_window)
 52    let io & = unsafe(GetIO())
 53    GetStyle().FontScaleMain = 1.4
 54}
 55
 56[export]
 57def update() {
 58    if (!live_begin_frame()) return
 59    begin_frame()
 60
 61    ImGui_ImplGlfw_NewFrame()
 62    apply_synth_io_override()
 63    NewFrame()
 64
 65    SetNextWindowPos(ImVec2(20.0f, 20.0f), ImGuiCond.Always)
 66    SetNextWindowSize(ImVec2(720.0f, 520.0f), ImGuiCond.Always)
 67    window(IN_WIN, (text = "input_numeric tutorial", closable = false,
 68                    flags = ImGuiWindowFlags.None)) {
 69
 70        text("Click to focus, type the number, Enter to commit.")
 71        text(I_HINT, (text = "Scalar forms have step / step_fast - non-zero shows +/- buttons."))
 72        separator()
 73
 74        // ---- Stage 1: scalar float with step buttons ----
 75        input_float(I_FLOAT, (text = "mass (kg)",
 76                              step = 0.1f, step_fast = 1.0f,
 77                              format = "%.3f"))
 78        text("I_FLOAT.value = {I_FLOAT.value}")
 79        spacing()
 80
 81        // ---- Stage 2: scalar int with step buttons ----
 82        input_int(I_INT, (text = "level",
 83                          step = 1, step_fast = 100))
 84        text("I_INT.value = {I_INT.value}")
 85        spacing()
 86
 87        // ---- Stage 3: vector float3 — no step buttons (vector forms omit them) ----
 88        input_float3(I_VEC3, (text = "position", format = "%.2f"))
 89        text("I_VEC3.value = ({I_VEC3.value.x}, {I_VEC3.value.y}, {I_VEC3.value.z})")
 90        spacing()
 91
 92        // ---- Stage 4: double precision ----
 93        input_double(I_DOUBLE, (text = "epoch (s)",
 94                                step = 1.0lf, step_fast = 60.0lf,
 95                                format = "%.6f"))
 96        text("I_DOUBLE.value = {I_DOUBLE.value}")
 97    }
 98
 99    end_of_frame()
100    Render()
101    var w, h : int
102    live_get_framebuffer_size(w, h)
103    glViewport(0, 0, w, h)
104    glClearColor(0.10f, 0.10f, 0.12f, 1.0f)
105    glClear(GL_COLOR_BUFFER_BIT)
106    live_imgui_render()
107
108    live_end_frame()
109}
110
111[export]
112def shutdown() {
113    live_imgui_shutdown()
114    live_destroy_window()
115}
116
117[export]
118def main() {
119    init()
120    while (!exit_requested()) {
121        update()
122    }
123    shutdown()
124}

8.18.1.41.1.1. Requires

Already in the baseline boost layer:

  • imgui/imgui_widgets_builtin — every input_* numeric rail.

  • imgui/imgui_boost_runtimeInputStateFloat / InputStateInt / InputStateDouble (+ vector variants) state structs.

8.18.1.41.1.2. Step buttons

Scalar forms (input_float, input_int, input_double) accept step and step_fast. Non-zero values surface ImGui’s + / - buttons on the right of the field:

input_float(MASS, (text = "mass (kg)",
                   step = 0.1f, step_fast = 1.0f))    // +/- buttons visible
input_int(LEVEL, (text = "level",
                  step = 1, step_fast = 100))         // defaults match this

Plain click = step. Ctrl-click = step_fast. Defaults differ per type: input_int defaults step = 1 / step_fast = 100 (buttons visible by default); input_float and input_double default to 0.0 (buttons hidden — pure text entry).

Vector forms (input_float2 / 3 / 4, input_int2 / etc.) omit step args — three or four +/- pairs would crowd the row. Component-wise editing only.

8.18.1.41.1.3. Format

format is the printf-style label format. 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_int(LEVEL, (text = "level", format = "%03d"))   // 003, 042, etc.
input_double(EPOCH, (text = "epoch", format = "%.9f")) // sub-ns precision

8.18.1.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.18.1.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.18.1.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,
                     format = "0x%08X"))

8.18.1.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.18.1.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.18.1.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.