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

8.18.1.37.1. Walkthrough

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

8.18.1.37.1.1. Requires

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

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

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

8.18.1.37.1.4. Standalone vs live

Same convention as the other widget tutorials.

See also

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

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

Boost macros — the macro layer.