8.18.1.50. edit_tab_item

Caller-owned visibility bool for a tab. The external-pointer sibling of tab_item (which owns visibility internally). The canonical “shared open state” pattern — a second UI surface (checkbox row, menu toggle, imgui_force_set) drives the same flag the tab’s X-close button writes.

var private g_tab_open : bool = true

edit_tab_item(safe_addr(g_tab_open), (id = "TAB_A",
                                       text = "alpha",
                                       flags = ImGuiTabItemFlags.None)) {
    <tab body>
}

When *p_open == false the tab is skipped entirely — no header chrome, no body. The X close button on the header writes *p_open = false automatically; you flip it back to true from any other UI surface to re-show the tab.

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

8.18.1.50.1. Walkthrough

The recording drives the bind end to end with real gestures. First it clicks the external show B checkbox and the beta tab vanishes outright - header and body both gone. Then it closes alpha with the X on its own tab header, and the show A checkbox flips itself off in response: the X and the checkbox write the very same bool. Finally it ticks both boxes back on and every tab returns. Each step is asserted - a checkbox that didn’t flip, a tab that didn’t hide, or an X that didn’t back-propagate would abort the recording.

  1options gen2
  2options _comment_hygiene = true
  3
  4require daslib/safe_addr
  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: edit_tab_item — caller-owned visibility bool for a tab.
 22//
 23//   edit_tab_item(safe_addr(open_bool), (id = "..", text = "..",        // bidir
 24//                                         flags = ...)) {                //   bind
 25//       <tab body>
 26//   }
 27//
 28// External-pointer sibling of `tab_item` (which owns visibility on its
 29// TabItemState). When `*p_open == false` the tab is skipped entirely
 30// (no header chrome, no body). The X close button on the header writes
 31// `*p_open = false` — bidir-bound.
 32//
 33// Use this when a SECOND UI surface (a checkbox row, a menu toggle,
 34// imgui_force_set on the external bool) needs to drive the same visibility
 35// flag the X writes. `tab_item`'s internal `state.open` isn't exposed
 36// for write outside the widget, so a shared external bool is the
 37// canonical pattern.
 38//
 39// All edit_* rails require an `id = "<literal>"` argument — that's the
 40// snapshot path. The first positional arg is the bool? pointer (passed
 41// via safe_addr for own globals, unsafe(addr(...)) for array elements
 42// or fields).
 43//
 44// STANDALONE: daslang.exe modules/dasImgui/examples/tutorial/edit_tab_item.das
 45// LIVE:       daslang-live modules/dasImgui/examples/tutorial/edit_tab_item.das
 46//
 47// DRIVE (when running live):
 48//   curl -X POST -d '{"name":"imgui_force_set","args":{"target":"ET_WIN/ET_BAR/ET_TAB_A","value":false}}' \
 49//        localhost:9090/command
 50// =============================================================================
 51
 52var private g_tab_a_open : bool = true
 53var private g_tab_b_open : bool = true
 54var private g_tab_c_open : bool = true
 55
 56[export]
 57def init() {
 58    live_create_window("dasImgui edit_tab_item tutorial", 760, 560)
 59    live_imgui_init(live_window)
 60    let io & = unsafe(GetIO())
 61    GetStyle().FontScaleMain = 1.4
 62}
 63
 64[export]
 65def update() {
 66    if (!live_begin_frame()) return
 67    begin_frame()
 68
 69    ImGui_ImplGlfw_NewFrame()
 70    apply_synth_io_override()
 71    NewFrame()
 72
 73    SetNextWindowPos(ImVec2(20.0f, 20.0f), ImGuiCond.Always)
 74    SetNextWindowSize(ImVec2(720.0f, 520.0f), ImGuiCond.Always)
 75    window(ET_WIN, (text = "edit_tab_item tutorial", closable = false,
 76                    flags = ImGuiWindowFlags.None)) {
 77
 78        text("Caller-owned visibility bool - the X button on each tab writes it.")
 79        text(ET_HINT, (text = "Checkboxes below also drive the SAME bools. Bidir-bound on g_tab_*_open."))
 80        separator()
 81
 82        // ---- External controls — second UI surface driving the same bools ----
 83        text("External controls (mirror the X-button state):")
 84        edit_checkbox(safe_addr(g_tab_a_open), (id = "ET_CHECK_A", text = "show A"))
 85        same_line(ET_SL1)
 86        edit_checkbox(safe_addr(g_tab_b_open), (id = "ET_CHECK_B", text = "show B"))
 87        same_line(ET_SL2)
 88        edit_checkbox(safe_addr(g_tab_c_open), (id = "ET_CHECK_C", text = "show C"))
 89        spacing()
 90        separator()
 91
 92        // ---- The tab bar — three edit_tab_item instances ----
 93        tab_bar(ET_BAR, (text = "MyBar",
 94                          flags = ImGuiTabBarFlags.FittingPolicyShrink)) {
 95            edit_tab_item(safe_addr(g_tab_a_open),
 96                          (id = "ET_TAB_A", text = "alpha",
 97                           flags = ImGuiTabItemFlags.None)) {
 98                text(ET_BODY_A, (text = "alpha tab body - close me with the X."))
 99            }
100            edit_tab_item(safe_addr(g_tab_b_open),
101                          (id = "ET_TAB_B", text = "beta",
102                           flags = ImGuiTabItemFlags.None)) {
103                text(ET_BODY_B, (text = "beta tab body - close me with the X."))
104            }
105            edit_tab_item(safe_addr(g_tab_c_open),
106                          (id = "ET_TAB_C", text = "gamma",
107                           flags = ImGuiTabItemFlags.None)) {
108                text(ET_BODY_C, (text = "gamma tab body - close me with the X."))
109            }
110        }
111        spacing()
112        text("g_tab_a_open = {g_tab_a_open}, g_tab_b_open = {g_tab_b_open}, g_tab_c_open = {g_tab_c_open}")
113    }
114
115    end_of_frame()
116    Render()
117    var w, h : int
118    live_get_framebuffer_size(w, h)
119    glViewport(0, 0, w, h)
120    glClearColor(0.10f, 0.10f, 0.12f, 1.0f)
121    glClear(GL_COLOR_BUFFER_BIT)
122    live_imgui_render()
123
124    live_end_frame()
125}
126
127[export]
128def shutdown() {
129    live_imgui_shutdown()
130    live_destroy_window()
131}
132
133[export]
134def main() {
135    init()
136    while (!exit_requested()) {
137        update()
138    }
139    shutdown()
140}

8.18.1.50.1.1. Requires

  • daslib/safe_addrsafe_addr(global) for the pointer arg.

  • imgui/imgui_containers_builtinedit_tab_item + tab_bar.

  • imgui/imgui_widgets_builtinedit_checkbox (for the external controls), text.

8.18.1.50.1.2. Why edit_tab_item over tab_item

tab_item (container) owns its open state internally on TabItemState.open. That field is read-only from outside the widget — there’s no public channel to flip it. So if you need a SECOND UI surface to drive the same visibility, you have to choose:

  • Use tab_item and accept that only the X-close button can hide the tab.

  • Use edit_tab_item with a shared external bool — both the X button AND your other UI write the same value.

The recording shows the second case: a row of checkboxes mirrors the state of three tabs. Clicking a checkbox hides the tab; clicking the tab’s X writes the bool, which back-propagates to the checkbox the next frame.

8.18.1.50.1.3. The id arg

All edit_* rails require an id = "<literal>" argument — that’s the snapshot path segment. Unlike the IDENT of state-owned widgets (which the [widget] macro promotes from a bare identifier to a string), the id here is a regular string literal you pass inline. Snapshot probes use it the same way:

curl -X POST -d '{"name":"imgui_snapshot"}' localhost:9090/command \
    | jq '.globals."ET_WIN/ET_BAR/ET_TAB_A"'

8.18.1.50.1.4. The pointer arg

The first positional arg is var p_open : bool? — a daslang pointer to a bool. How you get the pointer depends on where the bool lives:

  • Module-scope globalsafe_addr(g_open). Safest; verified at compile time.

  • Array elementunsafe(addr(arr[i])). Required because safe_addr only works on locally-scoped expressions, not computed addresses.

  • Struct fieldunsafe(addr(my_struct.field)). Same reason.

The recording uses safe_addr on three module globals (g_tab_a_open / b / c).

8.18.1.50.1.5. Driving from outside

imgui_force_set writes the external bool through edit_checkbox’s channel (which shares the bool with the tab):

# Hide alpha tab:
curl -X POST -d '{"name":"imgui_force_set","args":{"target":"ET_WIN/ET_CHECK_A","value":false}}' \
     localhost:9090/command

The X-button click on the tab header writes the same bool — symmetric.

See also

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

Internal-state sibling: Tab bar (covers tab_item + tab_item_button).

External-binding tour: External-pointer editing rail — every edit_* rail in one window.

Boost macros — the macro layer.