With disabled / font / button_repeat

Four stateless scope-wrappers landed alongside the v2 boost surface. They share the same shape: a top-level function that takes a single value plus a trailing block, pushes the corresponding ImGui scope on entry, pops on exit. None of them emit telemetry — no [widget] / [container] annotation, no idents — they exist to subsume the raw Push* / Pop* pairs that v2’s lint flags as invisible state changes.

  • with_disabled(disabled, blk)BeginDisabled / EndDisabled.

  • with_font(font, blk)PushFont / PopFont.

  • with_button_repeat(repeat, blk)PushButtonRepeat / PopButtonRepeat.

  • with_clip_rect(min, max, isect, blk)PushClipRect / PopClipRect.

with_disabled(!ENABLED_MASTER.value) {
    button(CHILD_SAVE, (text = "Save"))
    button(CHILD_LOAD, (text = "Load"))
    slider_float(CHILD_VOL, (text = "Volume"))
}

The block’s interior renders normally; the wrapper’s argument drives the ImGui-stack push that surrounds it. Toggling ENABLED_MASTER flips with_disabled’s argument and the child widgets re-render greyed (or active) on the next frame.

Source: examples/tutorial/with_disabled.das.

Walkthrough

The recording drives the with_disabled contrast with real synthetic input and self-verifies each step. While the checkbox is off it clicks the greyed Save button — nothing happens. It then ticks the checkbox on (asserting the value flipped), clicks Save again, and asserts CHILD_SAVE.click_count is now exactly one — proving the earlier greyed click never registered. Finally it presses and holds the + button under with_button_repeat and asserts the counter climbs twice under the single hold — a genuine repeat stream, not one click. Any step that failed to land would abort the recording.

  1options gen2
  2
  3require imgui
  4require imgui_app
  5require opengl/opengl_boost
  6require live/glfw_live
  7require live/live_api
  8require live/live_commands
  9require live/live_vars
 10require live_host
 11require imgui/imgui_live
 12require imgui/imgui_boost_runtime
 13require imgui/imgui_boost_v2
 14require imgui/imgui_widgets_builtin
 15require imgui/imgui_containers_builtin
 16require imgui/imgui_scope_builtin
 17require imgui/imgui_visual_aids
 18
 19// =============================================================================
 20// TUTORIAL: with_disabled — stateless scope-wrapper family.
 21//
 22// Four new wrappers landed alongside the v2 boost surface. They share the
 23// same shape: a top-level function that takes a single value + trailing
 24// block, pushes the corresponding ImGui scope on entry, pops on exit. None
 25// emit telemetry (no [widget] / [container] annotation, no idents).
 26//
 27//   with_disabled(disabled, blk)         — BeginDisabled / EndDisabled
 28//   with_font(font, blk)                 — PushFont / PopFont
 29//   with_button_repeat(repeat, blk)      — PushButtonRepeat / PopButtonRepeat
 30//   with_clip_rect(min, max, isect, blk) — PushClipRect / PopClipRect
 31//
 32// They subsume the raw Push/Pop pairs that v2's lint flags as invisible.
 33//
 34// STANDALONE: daslang.exe modules/dasImgui/examples/tutorial/with_disabled.das
 35// LIVE:       daslang-live modules/dasImgui/examples/tutorial/with_disabled.das
 36// =============================================================================
 37
 38[export]
 39def init() {
 40    live_create_window("dasImgui with_disabled family", 760, 520)
 41    live_imgui_init(live_window)
 42    let io & = unsafe(GetIO())
 43    GetStyle().FontScaleMain = 1.4
 44}
 45
 46[export]
 47def update() {
 48    if (!live_begin_frame()) return
 49    begin_frame()
 50
 51    ImGui_ImplGlfw_NewFrame()
 52    apply_synth_io_override()
 53    NewFrame()
 54
 55    SetNextWindowPos(ImVec2(60.0, 60.0), ImGuiCond.Always)
 56    SetNextWindowSize(ImVec2(640.0, 440.0), ImGuiCond.Always)
 57    window(SCOPES_WIN, (text = "Scope wrappers", closable = false,
 58                        flags = ImGuiWindowFlags.None)) {
 59        separator_text("with_disabled")
 60
 61        text("Toggle ENABLED_MASTER; child widgets follow.")
 62        checkbox(ENABLED_MASTER, (text = "Enable child group"))
 63
 64        // The whole block inside `with_disabled(...)` is rendered greyed-out
 65        // when the disabled flag is true; child clicks are inert.
 66        with_disabled(!ENABLED_MASTER.value) {
 67            if (button(CHILD_SAVE, (text = "Save"))) {
 68                print("save\n")
 69            }
 70            same_line(SL_CHILD)
 71            if (button(CHILD_LOAD, (text = "Load"))) {
 72                print("load\n")
 73            }
 74            slider_float(CHILD_VOL, (text = "Volume"))
 75        }
 76        text("CHILD_SAVE: clicked {CHILD_SAVE.click_count} times")
 77
 78        separator_text("with_button_repeat")
 79
 80        // Inside with_button_repeat(true), holding the button fires click
 81        // events repeatedly — useful for steppers.
 82        text("Hold the button - click_count keeps rising.")
 83        with_button_repeat(true) {
 84            if (button(STEP_UP, (text = "+"))) {
 85                print("step up: {STEP_UP.click_count}\n")
 86            }
 87        }
 88
 89        text("STEP_UP.click_count = {STEP_UP.click_count}")
 90
 91        separator_text("with_font")
 92
 93        // The default font is the same as GetFont() — change to any loaded
 94        // font handle to switch scope-local typography.
 95        text("with_font(...) swaps the active font for one scope.")
 96        with_font(GetFont()) {
 97            text(FONT_DEMO, (text = "Inside the with_font scope."))
 98        }
 99    }
100
101    end_of_frame()
102    Render()
103    var w, h : int
104    live_get_framebuffer_size(w, h)
105    glViewport(0, 0, w, h)
106    glClearColor(0.10f, 0.10f, 0.12f, 1.0f)
107    glClear(GL_COLOR_BUFFER_BIT)
108    live_imgui_render()
109
110    live_end_frame()
111}
112
113[export]
114def shutdown() {
115    live_imgui_shutdown()
116    live_destroy_window()
117}
118
119[export]
120def main() {
121    init()
122    while (!exit_requested()) {
123        update()
124    }
125    shutdown()
126}

Requires

One extra module beyond the baseline boost layer:

  • imgui/imgui_scope_builtin — defines the four with_* scope wrappers.

Why scope wrappers

Raw BeginDisabled / EndDisabled pairs work, but the v2 boost lint flags them as “invisible state changes” — if the source has BeginDisabled(...) somewhere and the matching EndDisabled() six branches deep, a reader has to trace control flow to see whether the disable will pop correctly on early-return paths. The scope wrapper:

  • Couples the push/pop into a block — exit through any path pops.

  • Reads as a single statement — the disabled argument is right at the top.

  • Survives return, break, continue in the body — block exit always pops the scope.

with_disabled

The argument is the disabled bool — true greys out the block. The tutorial drives this with an ENABLED_MASTER checkbox and passes !ENABLED_MASTER.value so the checkbox’s natural “enable child group” reading produces the right semantics.

with_button_repeat

When true, holding a button inside the block fires click events at ImGui’s repeat rate (configured by KeyRepeatDelay and KeyRepeatRate in ImGuiIO). Use it for stepper buttons (+, -) where hold-to-increment is the natural interaction. Outside this scope, buttons fire one click per press regardless of hold duration.

The tutorial’s STEP_UP.click_count climbs visibly while the cursor holds down on the + button in the recording — each repeat fires the click handler.

with_font

Push a different ImFont? for the block’s render — the default font is whatever GetFont() returns. Combine with load_daslang_font (see imgui/imgui_theme_daslang) to load a custom TTF and scope-swap it for specific UI sections (code editors, narration boxes, etc.).

The tutorial’s with_font(GetFont()) is a no-op for demonstration — the rendered text is the active font. Production code would pass a specific ImFont? returned from a prior AddFontFromFileTTF call.

with_clip_rect

The fourth scope wrapper isn’t exercised in this tutorial — see examples/features/clip_rect.das for a per-frame clipping demo. with_clip_rect((min, max, isect), blk) is the safest way to install a custom clip rectangle around custom-rendered content (drawlist primitives, images, manual layout) since the scope guarantees the prior clip rect is restored on exit.

Combining wrappers

The wrappers compose cleanly — nest them to layer scopes:

with_disabled(!FEATURE_ENABLED.value) {
    with_button_repeat(true) {
        button(STEP_UP, (text = "+"))
        button(STEP_DN, (text = "-"))
    }
}

Steppers fire repeat clicks when held, but the whole pair greys out when the feature flag is off. Each wrapper’s exit pops its own scope; ImGui’s internal stacks handle the LIFO ordering.

See also

Full source: examples/tutorial/with_disabled.das

Integration tests: tests/integration/test_disabled_block.das, tests/integration/test_button_repeat.das, tests/integration/test_font_stack.das.

Companion tutorials: With id, With style, With tab stop — other with_* scope helpers.

Boost macros — the macro layer.