Selectable hover

selectable is a toggleable row — its ToggleState flips between selected and unselected on click. Some call sites want the row geometry only, with the selected flag pinned to false; the hover variant covers that:

for (i in range(length(ROWS))) {
    let hovered = selectable_hover(SH_ROW[i], (text = "Row {i}: {ROWS[i]}"))
    if (hovered) {
        // per-frame side-effect, e.g. SetMouseCursor(...)
    }
}

EmptyMarkerState backs the widget; the return value is the per-frame hover bool. The selected flag is fixed at false — clicks render a brief selection highlight but the row never persists as selected.

Source: examples/tutorial/selectable_hover.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: selectable_hover — hover-target variant of selectable.
 20//
 21//   selectable(IDENT, (text = "Row"))        — toggleable (ToggleState).
 22//   selectable_hover(IDENT, (text = "Row"))  — hover only (EmptyMarkerState);
 23//                                               selected pinned to false;
 24//                                               returns true while hovered.
 25//
 26// Use the hover variant when the selectable row is the surface for a
 27// per-frame hover side-effect (e.g. "while hovering this cursor sample,
 28// set ImGui's mouse cursor to that style") and the toggle semantics of
 29// regular selectable would be incorrect.
 30//
 31// STANDALONE: daslang.exe modules/dasImgui/examples/tutorial/selectable_hover.das
 32// LIVE:       daslang-live modules/dasImgui/examples/tutorial/selectable_hover.das
 33// =============================================================================
 34
 35var private STATE_MESSAGE = "Hover any row."
 36var private SH_ROW : table<int; EmptyMarkerState>
 37
 38let private ROWS = fixed_array("Arrow", "TextInput", "ResizeAll", "Hand", "NotAllowed")
 39
 40[export]
 41def init() {
 42    live_create_window("dasImgui selectable_hover tutorial", 600, 380)
 43    live_imgui_init(live_window)
 44    let io & = unsafe(GetIO())
 45    GetStyle().FontScaleMain = 1.4
 46}
 47
 48[export]
 49def update() {
 50    if (!live_begin_frame()) return
 51    begin_frame()
 52
 53    ImGui_ImplGlfw_NewFrame()
 54    apply_synth_io_override()
 55    NewFrame()
 56
 57    SetNextWindowPos(ImVec2(40.0f, 40.0f), ImGuiCond.Always)
 58    SetNextWindowSize(ImVec2(520.0f, 300.0f), ImGuiCond.Always)
 59    window(SH_WIN, (text = "selectable_hover", closable = false,
 60                    flags = ImGuiWindowFlags.None)) {
 61        text("Hover a row - STATE_MESSAGE follows the highlighted item.")
 62        separator()
 63
 64        for (i in range(length(ROWS))) {
 65            let hovered = selectable_hover(SH_ROW[i], (text = "Row {i}: {ROWS[i]}"))
 66            if (hovered) {
 67                STATE_MESSAGE = "Hovering: {ROWS[i]}"
 68            }
 69        }
 70
 71        separator()
 72        text(SH_STATUS, (text = STATE_MESSAGE))
 73    }
 74
 75    end_of_frame()
 76    Render()
 77    var w, h : int
 78    live_get_framebuffer_size(w, h)
 79    glViewport(0, 0, w, h)
 80    glClearColor(0.10f, 0.10f, 0.12f, 1.0f)
 81    glClear(GL_COLOR_BUFFER_BIT)
 82    live_imgui_render()
 83
 84    live_end_frame()
 85}
 86
 87[export]
 88def shutdown() {
 89    live_imgui_shutdown()
 90    live_destroy_window()
 91}
 92
 93[export]
 94def main() {
 95    init()
 96    while (!exit_requested()) {
 97        update()
 98    }
 99    shutdown()
100}

Requires

Same baseline as selectable — already in imgui/imgui_widgets_builtin (re-exported by imgui/imgui_boost_v2).

When to reach for it

When the selectable row is a hover surface, not a toggle:

  • examples/imgui_demo/inputs.das — the Mouse Cursors list renders one selectable_hover row per ImGuiMouseCursor value and sets ImGui’s cursor while a row is hovered. Toggle semantics would be wrong (no persistent selection; the cursor follows hover frame-to-frame).

  • Per-row preview rails where hovering shows a tooltip / status pane and the click semantics don’t matter.

Toggle vs hover

  • selectable(IDENT, (text)) — returns bool changed, persists state.value (selected/unselected) across frames.

  • selectable_hover(IDENT, (text)) — returns bool hovered, no persistent selection state.

A site that needs both (click toggles, hover previews) should use the regular selectable and read IsItemHovered() after the call.

Standalone vs live

Same convention as the other widget tutorials.

See also

Full source: examples/tutorial/selectable_hover.das

Integration test: tests/integration/test_selectable_hover.das.

Boost macros — the macro layer.