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: examples/tutorial/flat_tooltips.das.

Walkthrough

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

Requires

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

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.

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.

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: examples/tutorial/flat_tooltips.das

Integration test: tests/integration/test_tooltip_flat.das.

Boost macros — the macro layer.