Widgets tour

One of every common boost widget on a single panel. The example frames as an audio-settings dialog so each widget reads contextually: a text input for the user name, a slider for volume, a checkbox for mute, a combo for codec quality, a color editor for the accent color, and a button to save.

Source: examples/tutorial/widgets_tour.das.

Walkthrough

widgets_tour recording
  1options gen2
  2
  3require imgui
  4require imgui_app
  5require glfw/glfw_boost
  6require opengl/opengl_boost
  7require live/glfw_live
  8require live/live_api
  9require live/live_commands
 10require live/live_vars
 11require live/opengl_live
 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: widgets_tour — one of every common boost widget on a single panel.
 22//
 23// Frame as an audio-settings dialog so each widget reads contextually:
 24//   USER_NAME  : input_text   — who's listening
 25//   VOLUME     : slider_float — master volume
 26//   MUTED      : checkbox     — mute toggle
 27//   QUALITY    : combo        — codec quality preset
 28//   TINT       : color_edit3  — accent color for the UI
 29//   SAVE_BTN   : button       — apply the settings
 30//
 31// Read alongside :ref:`tutorial_boost_basics` for the frame-loop shape; this
 32// tutorial only adds widgets on top of that scaffold.
 33//
 34// STANDALONE: daslang.exe modules/dasImgui/examples/tutorial/widgets_tour.das
 35// LIVE:       daslang-live modules/dasImgui/examples/tutorial/widgets_tour.das
 36//
 37// DRIVE (when running live):
 38//   curl -X POST -d '{"name":"imgui_set","args":{"target":"AUDIO_WIN/USER_NAME","value":"Boris"}}'        localhost:9090/command
 39//   curl -X POST -d '{"name":"imgui_set","args":{"target":"AUDIO_WIN/VOLUME","value":0.75}}'              localhost:9090/command
 40//   curl -X POST -d '{"name":"imgui_set","args":{"target":"AUDIO_WIN/MUTED","value":true}}'               localhost:9090/command
 41//   curl -X POST -d '{"name":"imgui_set","args":{"target":"AUDIO_WIN/QUALITY","value":2}}'                localhost:9090/command
 42//   curl -X POST -d '{"name":"imgui_set","args":{"target":"AUDIO_WIN/TINT","value":{"x":0.2,"y":0.8,"z":0.4}}}' localhost:9090/command
 43//   curl -X POST -d '{"name":"imgui_click","args":{"target":"AUDIO_WIN/SAVE_BTN"}}'                       localhost:9090/command
 44// =============================================================================
 45
 46[export]
 47def init() {
 48    live_create_window("dasImgui widgets tour", 1024, 720)
 49    live_imgui_init(live_window)
 50    var io & = unsafe(GetIO())
 51    io.FontGlobalScale = 1.5
 52}
 53
 54[export]
 55def update() {
 56    if (!live_begin_frame()) return
 57    begin_frame()
 58
 59    ImGui_ImplOpenGL3_NewFrame()
 60    ImGui_ImplGlfw_NewFrame()
 61    apply_synth_io_override()
 62    NewFrame()
 63
 64    // Sized for content with breathing room on the right + below for narrate
 65    // post-its to appear without overlapping the panel.
 66    SetNextWindowPos(ImVec2(60.0, 60.0), ImGuiCond.Always)
 67    SetNextWindowSize(ImVec2(720.0, 540.0), ImGuiCond.Always)
 68    window(AUDIO_WIN, (text = "Audio settings", closable = false,
 69                       flags = ImGuiWindowFlags.None)) {
 70        // Text input — buffer + string-mirror managed by the state struct.
 71        input_text(USER_NAME, (text = "Your name"))
 72
 73        spacing(WT_SP_1)
 74
 75        // Slider — float state with [0, 1] bounds set per-frame.
 76        VOLUME.bounds = (0.0f, 1.0f)
 77        slider_float(VOLUME, (text = "Master volume"))
 78
 79        // Checkbox — bool state, toggles on click.
 80        checkbox(MUTED, (text = "Mute"))
 81
 82        spacing(WT_SP_2)
 83
 84        // Combo — int state indexing into the items array.
 85        combo(QUALITY, (text = "Quality",
 86                        items <- ["Low", "Medium", "High", "Ultra"]))
 87
 88        spacing(WT_SP_3)
 89
 90        // Color editor — three-channel RGB, opens a picker on click.
 91        color_edit3(TINT, (text = "Accent color"))
 92
 93        spacing(WT_SP_4)
 94        separator(WT_SEP_1)
 95        spacing(WT_SP_5)
 96
 97        // Button — true on the frame the click registers; click_count accumulates.
 98        if (button(SAVE_BTN, (text = "Save settings"))) {
 99            print("save clicked: name={USER_NAME.value} vol={VOLUME.value} muted={MUTED.value} q={QUALITY.value}\n")
100        }
101
102        spacing(WT_SP_6)
103        text("saves so far: {SAVE_BTN.click_count}")
104    }
105
106    end_of_frame()
107    Render()
108    var w, h : int
109    live_get_framebuffer_size(w, h)
110    glViewport(0, 0, w, h)
111    glClearColor(0.10f, 0.10f, 0.12f, 1.0f)
112    glClear(GL_COLOR_BUFFER_BIT)
113    ImGui_ImplOpenGL3_RenderDrawData(GetDrawData())
114
115    live_end_frame()
116}
117
118[export]
119def shutdown() {
120    live_imgui_shutdown()
121    live_destroy_window()
122}
123
124[export]
125def main() {
126    init()
127    while (!exit_requested()) {
128        update()
129    }
130    shutdown()
131}

Requires

The require block matches Boost basics exactly — backend (imgui_app / glfw / opengl), live host (live/*), and the v2 boost layer (imgui_live, imgui_boost_runtime, imgui_boost_v2, imgui_widgets_builtin, imgui_containers_builtin for the window(...) block container). One extra line pulls in imgui/imgui_visual_aids so the post-it narrate overlay the driver script paints into the recording is available at render time.

Init and shutdown

init() opens a 1024x720 GLFW window via live_create_window and hands the handle to live_imgui_init. It also bumps io.FontGlobalScale to 1.5 so the recorded APNG reads at typical Sphinx HTML widths without zooming. shutdown() mirrors the pair in reverse order.

The frame loop

update() follows the standard dasImgui v2 shape — see Boost basics for the line-by-line breakdown. The only addition is a single call to apply_synth_io_override() between ImGui_ImplGlfw_NewFrame and NewFrame. The GLFW backend polls real OS mouse data every focused frame and would otherwise win the IO race against any synthesized event the driver script posted just before. The override re-asserts the synth IO so live-driven clicks land at the right widget.

Widgets

All six widgets live inside a single window(AUDIO_WIN, ...) boost container — same pattern Boost basics introduced, so leaves register at AUDIO_WIN/<ident>:

window(AUDIO_WIN, (text = "Audio settings", closable = false,
                   flags = ImGuiWindowFlags.None)) {
    input_text(USER_NAME, (text = "Your name"))
    slider_float(VOLUME, (text = "Master volume"))
    checkbox(MUTED, (text = "Mute"))
    combo(QUALITY, (text = "Quality", items <- ["Low", "Medium", "High", "Ultra"]))
    color_edit3(TINT, (text = "Accent color"))
    if (button(SAVE_BTN, (text = "Save settings"))) { ... }
}

Each boost macro declares the named global the first time it expands and registers it under the path-prefixed name. The slider’s range comes from a plain field assignment one line above the macro call: VOLUME.bounds = (0.0f, 1.0f). The combo’s item list moves into the named argument with items <- because string arrays are non-copyable. SAVE_BTN.click_count accumulates across frames — handy for assertions in a test harness.

Standalone vs live

main() runs the loop directly when invoked as daslang.exe widgets_tour.das. Under daslang-live the host calls init / update / shutdown itself; main is ignored. Every state struct (USER_NAME, VOLUME, MUTED, QUALITY, TINT, SAVE_BTN) carries @live by default, so live-reloading the source preserves the widget contents.

Driving from outside

Under daslang-live the boost layer exposes imgui_set and imgui_click over localhost:9090. The top of the source file lists one curl invocation per widget. Each target is path-qualified:

curl -X POST -d '{"name":"imgui_set","args":{"target":"AUDIO_WIN/USER_NAME","value":"Boris"}}' \
     localhost:9090/command

For color_edit3, value is a JSON object with x / y / z fields — from_JV reads float3 from object form, not array form. For combo, value is the zero-based index into the items array.

Next steps

Layout helpers — splitters, columns, child windows — are next on top of the same widget set. To write your own widget kind on the same rails — a rotary knob, an XY-pad, a meter — see Custom widgets.

See also

Full source: examples/tutorial/widgets_tour.das

Richer reference: examples/features/inputs_*.das — every widget with every option exercised, against the same boost layer.

Previous tutorial: Boost basics

Next tutorial: Custom widgets

Boost macros — the macro layer.

Builtin widgets — widget reference.