8.18.1.4. 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: modules/dasImgui/examples/tutorial/display_widgets.das.

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

8.18.1.4.1.1. Requires

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

8.18.1.4.1.2. 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.

8.18.1.4.1.3. 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.

8.18.1.4.1.4. 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: modules/dasImgui/examples/tutorial/display_widgets.das

Integration test: modules/dasImgui/tests/test_display_progress.das and modules/dasImgui/tests/test_display_image.das.

Boost macros — the macro layer.