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