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

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

8.18.1.12.1.1. Requires

One extra module beyond the baseline boost layer:

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

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

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

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

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

8.18.1.12.1.6. with_clip_rect

The fourth scope wrapper isn’t exercised in this tutorial — see modules/dasImgui/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.

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

Integration tests: modules/dasImgui/tests/test_disabled_block.das, modules/dasImgui/tests/test_button_repeat.das, modules/dasImgui/tests/test_font_stack.das.

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

Boost macros — the macro layer.