8.19.23. Flat tooltips

The container form tooltip(IDENT) { ... } (already in v1) wraps a full layout scope — useful when the tooltip needs nested widgets or its own state. For one-liner annotations that just need one line of text on a hovered item, v2 ships two flat-form rails that fire without opening a scope:

  • set_tooltip(IDENT, (text = ...)) — always shows; rare in practice, shown for completeness.

  • set_item_tooltip(IDENT, (text = ...)) — shows when the most-recently-submitted item is hovered. The canonical replacement for the imgui_demo HelpMarker helper.

if (button(SAVE_BTN, (text = "Save"))) { /* ... */ }
set_item_tooltip(SAVE_TIP, (text = "Persists current state to disk."))

Chain them one per row — the tooltip attaches to whatever was just submitted. No layout scope, no extra widgets, no nested block.

Source: modules/dasImgui/examples/tutorial/flat_tooltips.das.

8.19.23.1. Walkthrough

  1options gen2
  2options _comment_hygiene = true
  3options gc
  4
  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: flat_tooltips — boost v2 flat-form tooltip widgets.
 22//
 23// The container form `tooltip(IDENT) { ... }` (already in v1) wraps a full
 24// scope. For one-liner tooltips with no inner layout, use the flat forms:
 25//
 26//   set_tooltip(IDENT, (text = ...))         — always shows; rare
 27//   set_item_tooltip(IDENT, (text = ...))    — shows when previous item hovered
 28//
 29// set_item_tooltip is the canonical replacement for the imgui_demo HelpMarker
 30// idiom (call after the widget you want to annotate).
 31//
 32// STANDALONE: daslang.exe modules/dasImgui/examples/tutorial/flat_tooltips.das
 33// LIVE:       daslang-live modules/dasImgui/examples/tutorial/flat_tooltips.das
 34// =============================================================================
 35
 36[export]
 37def init() {
 38    live_create_window("dasImgui flat tooltips", 720, 420)
 39    live_imgui_init(live_window)
 40    let io & = unsafe(GetIO())
 41    GetStyle().FontScaleMain = 1.4
 42}
 43
 44[export]
 45def update() {
 46    if (!live_begin_frame()) return
 47    begin_frame()
 48
 49    ImGui_ImplGlfw_NewFrame()
 50    apply_synth_io_override()
 51    NewFrame()
 52
 53    SetNextWindowPos(ImVec2(60.0, 60.0), ImGuiCond.Always)
 54    SetNextWindowSize(ImVec2(600.0, 300.0), ImGuiCond.Always)
 55    window(TOOLTIP_WIN, (text = "Flat tooltips", closable = false,
 56                         flags = ImGuiWindowFlags.None)) {
 57        text("Hover the buttons - tooltips fire on item hover.")
 58
 59        // set_item_tooltip — fires on the most-recently-submitted item.
 60        if (button(SAVE_BTN, (text = "Save"))) {
 61            print("save\n")
 62        }
 63        set_item_tooltip(SAVE_TIP, (text = "Persists current state to disk."))
 64
 65        spacing(SP_BTNS)
 66
 67        if (button(LOAD_BTN, (text = "Load"))) {
 68            print("load\n")
 69        }
 70        set_item_tooltip(LOAD_TIP, (text = "Restores the last saved state."))
 71
 72        spacing(SP_HELP)
 73
 74        // Classic "(?)" disabled marker + item_tooltip — replaces the old
 75        // HelpMarker / demo_help_marker helpers in v1 imgui_demo.
 76        text("Verbose option (with help marker):")
 77        same_line(SL_HINT)
 78        text_disabled(HELP_GLYPH, (text = "(?)"))
 79        set_item_tooltip(HELP_TIP, (text = "The imgui_demo HelpMarker idiom, in two lines."))
 80    }
 81
 82    end_of_frame()
 83    Render()
 84    var w, h : int
 85    live_get_framebuffer_size(w, h)
 86    glViewport(0, 0, w, h)
 87    glClearColor(0.10f, 0.10f, 0.12f, 1.0f)
 88    glClear(GL_COLOR_BUFFER_BIT)
 89    live_imgui_render()
 90
 91    live_end_frame()
 92}
 93
 94[export]
 95def shutdown() {
 96    live_imgui_shutdown()
 97    live_destroy_window()
 98}
 99
100[export]
101def main() {
102    init()
103    while (!exit_requested()) {
104        update()
105        maybe_collect_gc()
106    }
107    shutdown()
108}

8.19.23.1.1. Requires

Baseline boost layer — both rails live in imgui/imgui_boost_v2.

8.19.23.1.2. set_item_tooltip vs the container form

tooltip(IDENT) { ... } is still the right tool when:

  • The tooltip body needs nested widgets — separators, colored text, inline checkboxes, indented bullets.

  • The hover bool is computed at the call site and you want a custom block to fire only on certain conditions.

set_item_tooltip is the right tool when:

  • You want exactly one line of text on hover.

  • The tooltip is purely informational (no nested layout).

  • You want to chain many of them — one per button, slider, etc.

8.19.23.1.3. The HelpMarker pattern

The imgui_demo’s HelpMarker(...) helper renders a disabled (?) glyph and shows a tooltip on hover. v2 replaces it with two source lines:

text("Verbose option (with help marker):")
same_line(SL_HINT)
text_disabled(HELP_GLYPH, (text = "(?)"))
set_item_tooltip(HELP_TIP, (text = "short explanation here"))

The text_disabled(HELP_GLYPH, ...) renders the dim glyph; set_item_tooltip attaches the tooltip to that disabled-text item. No helper function, no extra abstraction — just two boost rails composed.

8.19.23.1.4. Standalone vs live

Same convention as the other widget tutorials: daslang for standalone or daslang-live for live-reload + telemetry. set_item_tooltip’s state struct (NarrativeState) carries the text string into the snapshot for downstream playwright tests.

See also

Full source: modules/dasImgui/examples/tutorial/flat_tooltips.das

Integration test: modules/dasImgui/tests/test_tooltip_flat.das.

Boost macros — the macro layer.