Display widgets

dasImgui’s read-only display family wraps ImGui’s two main output widgets into the v2 boost surface. progress_bar wraps ImGui::ProgressBar with a ProgressBarState payload carrying {fraction, size, overlay}; image wraps ImGui::Image with the full uv0 / uv1 / tint_col / border_col quartet plus a uint64 reinterpret of the texture handle for snapshot readability.

progress_bar(PB_STATIC, (fraction = 0.33f,
                         size = float2(-1.0f, 0.0f),
                         overlay = "33%"))

image(IMG_PLAIN, (user_texture_id = font_tex,
                  size = float2(96.0f, 96.0f),
                  uv0 = float2(0.0f, 0.0f),
                  uv1 = float2(1.0f, 1.0f),
                  tint_col = float4(1.0f, 1.0f, 1.0f, 1.0f),
                  border_col = float4(0.0f, 0.0f, 0.0f, 0.0f)))

Display widgets are read-only, so they don’t need a caller-side ident — call them anonymously and only the parent window(DISPLAY_WIN, ...) registers a routable entry. This example names each one (PB_STATIC / PB_DRIVEN / PB_FIXED / IMG_PLAIN / IMG_TINT) so every widget registers its own snapshot path — which is what lets the recording assert each one’s output (the static bar on screen, the driven bar’s fraction sweeping, the images present).

Source: examples/tutorial/display_widgets.das.

Walkthrough

The recording narrates the three progress bars and two images while the middle bar’s fraction sweeps under a sine wave. These widgets take no input, so the self-check is on their output: the static bar and both images are asserted on screen, and the driven bar’s fraction is asserted to change over time - so a bar that stopped rendering or a sine that stopped sweeping would abort the recording.

  1options gen2
  2
  3require math
  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: display_widgets — boost v2 visual-output widgets.
 21//
 22// progress_bar wraps ImGui::ProgressBar with a ProgressBarState payload
 23// carrying {fraction, size, overlay}. image wraps ImGui::Image with full
 24// uv0/uv1/tint_col/border_col + a uint64 reinterpret of the texture handle
 25// for snapshot readability.
 26//
 27// The image() example uses the ImGui font atlas texture (always available),
 28// so this tutorial runs without any external asset.
 29//
 30// STANDALONE: daslang.exe modules/dasImgui/examples/tutorial/display_widgets.das
 31// LIVE:       daslang-live modules/dasImgui/examples/tutorial/display_widgets.das
 32//
 33// DRIVE (when running live):
 34//   curl -X POST -d '{"name":"imgui_snapshot"}' localhost:9090/command \
 35//        | jq '.globals."DISPLAY_WIN".payload'
 36// =============================================================================
 37
 38var private g_phase : float = 0.0f
 39
 40[export]
 41def init() {
 42    live_create_window("dasImgui display widgets", 940, 680)
 43    live_imgui_init(live_window)
 44    let io & = unsafe(GetIO())
 45    GetStyle().FontScaleMain = 1.4
 46}
 47
 48[export]
 49def update() {
 50    if (!live_begin_frame()) return
 51    begin_frame()
 52
 53    ImGui_ImplGlfw_NewFrame()
 54    apply_synth_io_override()
 55    NewFrame()
 56
 57    g_phase += 0.01f
 58    let driven_frac = 0.5f + 0.5f * sin(g_phase)
 59
 60    SetNextWindowPos(ImVec2(60.0, 60.0), ImGuiCond.Always)
 61    SetNextWindowSize(ImVec2(680.0, 420.0), ImGuiCond.Always)
 62    window(DISPLAY_WIN, (text = "Display widgets", closable = false,
 63                         flags = ImGuiWindowFlags.None)) {
 64        separator_text("progress_bar")
 65
 66        // Static bar - 33% with auto-formatted overlay.
 67        progress_bar(PB_STATIC, (fraction = 0.33f,
 68                                 size = float2(-1.0f, 0.0f),
 69                                 overlay = "33%"))
 70
 71        // Driven bar - sine-wave fraction, default overlay.
 72        progress_bar(PB_DRIVEN, (fraction = driven_frac,
 73                                 size = float2(-1.0f, 0.0f),
 74                                 overlay = ""))
 75
 76        // Fixed-width bar with custom overlay text.
 77        progress_bar(PB_FIXED, (fraction = 0.75f,
 78                                size = float2(240.0f, 0.0f),
 79                                overlay = "loading..."))
 80
 81        separator_text("image")
 82
 83        // Use the ImGui font atlas as our texture — always built by frame 1.
 84        let io & = unsafe(GetIO())
 85        if (io.Fonts.TexData == null) {
 86            text("Font atlas not ready — wait for first frame.")
 87        } else {
 88            text("image() against the font atlas - varying uv + tint per call.")
 89            image(IMG_PLAIN, (user_texture_id = io.Fonts.TexRef,
 90                              size = float2(96.0f, 96.0f),
 91                              uv0 = float2(0.0f, 0.0f),
 92                              uv1 = float2(1.0f, 1.0f),
 93                              tint_col = float4(1.0f, 1.0f, 1.0f, 1.0f),
 94                              border_col = float4(0.0f, 0.0f, 0.0f, 0.0f)))
 95            same_line(SL_IMG)
 96            image(IMG_TINT, (user_texture_id = io.Fonts.TexRef,
 97                             size = float2(96.0f, 96.0f),
 98                             uv0 = float2(0.0f, 0.0f),
 99                             uv1 = float2(1.0f, 1.0f),
100                             tint_col = float4(0.3f, 0.9f, 0.6f, 1.0f),
101                             border_col = float4(1.0f, 1.0f, 1.0f, 0.5f)))
102        }
103    }
104
105    end_of_frame()
106    Render()
107    var w, h : int
108    live_get_framebuffer_size(w, h)
109    glViewport(0, 0, w, h)
110    glClearColor(0.10f, 0.10f, 0.12f, 1.0f)
111    glClear(GL_COLOR_BUFFER_BIT)
112    live_imgui_render()
113
114    live_end_frame()
115}
116
117[export]
118def shutdown() {
119    live_imgui_shutdown()
120    live_destroy_window()
121}
122
123[export]
124def main() {
125    init()
126    while (!exit_requested()) {
127        update()
128    }
129    shutdown()
130}

Requires

Baseline boost layer (imgui/imgui_boost_v2 re-exports the rail family from imgui/imgui_widgets_builtin). No extra modules.

progress_bar

ProgressBarState mirrors the call-site values verbatim. fraction holds the raw call-site value (no clamp at the state level); ImGui clamps to [0, 1] for the rendered bar, but the snapshot payload reflects whatever the caller passed — so out-of-range inputs surface in the snapshot for assertion. Pass a negative value for indeterminate animation. size is the ImGui ImVec2: -1.0f for the X component fills available width; explicit pixels for fixed width. overlay is the centered label drawn on top of the bar — leave empty for the auto-formatted percentage.

image

ImageState exposes user_texture_id as a uint64 so the snapshot can carry the texture handle as a readable number (raw void? would serialize as a pointer string). All four uv0 / uv1 / tint_col / border_col defaults match the C++ ImGui::Image defaults so an unset call is the identity render. The tutorial uses the ImGui font atlas (GetIO().Fonts.TexID) as a guaranteed-available texture; production code passes a user_texture_id from your renderer that targets a real GPU resource.

Snapshot shape

Each named widget registers its own snapshot entry, so a rail’s state is readable directly. Probe with:

curl -X POST -d '{"name":"imgui_snapshot"}' localhost:9090/command \
    | jq '.globals."DISPLAY_WIN/PB_DRIVEN".payload'

That returns the driven bar’s {fraction, size, overlay} — useful for snapshot-driven regression tests when you want to assert PB_DRIVEN’s fraction matches the sine-driven value (the recording does exactly that, via record_check_changed). Left anonymous, a widget folds into a line-keyed entry under the window instead.

See also

Full source: examples/tutorial/display_widgets.das

Integration test: tests/integration/test_display_progress.das and tests/integration/test_display_image.das.

Boost macros — the macro layer.