Skip to content

[0.1.0][area:ui] Define the tab interaction verbs and stop treating Stack as tabs (bitty#2478 B) #3166

Closed

Description

@Xuepoo

Summary

The repo describes LayoutNode::Stack as tabs, but there is no tab interaction anywhere: no open, switch, close, or reorder verbs, and Stack is a pure paint-order container. The only tab-shaped machinery in the runtime is an exclusive claim on the tabline slot — a permission gate, not an interaction model. This issue asks for the verbs to be defined (with validated layout commits and atomic failure) and for the paint-only Stack to stop being described as tabs until it has an owner.

Parent: #2478 (item 5).

The gap, with evidence

1. Stack is paint-only stacking.

  • crates/bitty-ui/src/layout.rs:118-119 — Stack(Vec<LayoutNode>), documented as "Stacked children sharing the same bounds (e.g., tabs)".
  • crates/bitty-ui/src/layout.rs:94-95 — "Stack: tab-like stacking where every child occupies the full container bounds; the last element is considered top-most for focus/visual order."
  • crates/bitty-ui/src/layout.rs:703-707 — the solver lays out every child at the identical bounds:
    Self::Stack(children) => {
        for child in children {
            child.layout_inner(bounds, gap_in, out);
        }
    }
  • crates/bitty-ui/src/layout.rs:670 — "Stack children share the full inset bounds (only one is visible)".

So Stack emits rects for all children at once and relies on "last is top-most" for visual order. There is no notion of an active child, no per-child visibility state, no identity for a tab, and no transition. "Only one is visible" is a convention the container does not enforce.

2. No tab verbs exist.

git grep over origin/main for tab_open, tab_switch, tab_close, tab_new returns zero hits in the entire repository. The command surface that tab verbs would live on is crates/bitty-ui/src/panel.rs:569-572 — CommandRegistry { commands: HashMap<String, PanelId>, per_panel: HashMap<PanelId, Vec<String>> }, i.e. a command-to-panel map with register (:585-609) enforcing grammar, duplicate rejection, and a per-panel cap. It has no tab concept.

3. The only tab-shaped machinery is an exclusive claim.

crates/bitty-runtime/src/plugin_runtime/services.rs:6611-6621 — a tabline mount requires the workspaceline exclusive claim, else E_UI_CLAIM_REQUIRED. That is a permission check on whoever owns the strip. It opens nothing, switches nothing, closes nothing.

Two further inconsistencies to resolve while doing this work:

  • crates/bitty-runtime/src/runtime/band_slots.rs:103-105 — UiSlot::Tabline placement is Unsupported("is reserved for panel tabs ... and has no host surface yet"), so no tabline mount can succeed at all today.
  • crates/bitty-runtime/src/plugin_runtime/services.rs:3374 — yet UiBlockState treats Top | Bottom | Tabline as the same band-visible case, gated by band_is_visible (one row, hidden only by empty text). Any future tabline host would therefore inherit horizontal-band semantics (a single painted row) that are wrong for a tab strip with multiple entries.

4. Stack is reachable by users today with no interaction attached.

crates/bitty-terminal/src/ctl/apply.rs:1015-1017 splits leaves inside a Stack, and crates/bitty-terminal/src/dev.rs:270-277 exposes stack as a --layout spec (single, split, stack, overlay). So the container is user-constructible, and its documented "tabs" behaviour is unbacked by any command.

The constraint this issue must respect

A tab must be a projection of a Panel, never an anonymous slot. A tab is a view onto a panel instance that already has identity, ownership, and lifetime — it is not a free-floating container child, not a nameless rectangle in a Vec<LayoutNode>, and not a place a plugin can mount into independently of the panel it represents.

That rule is what the current reservation already encodes in source: tabline is kept "reserved for panel tabs" (crates/bitty-runtime/src/runtime/band_slots.rs:103-105, echoed in crates/bitty-lua/src/ui.rs:107) precisely so the slot cannot be consumed as a generic band. Panel identity is a newtype distinct from ViewId (crates/bitty-ui/src/panel.rs:26, PanelId(pub u64)), which is the identity any tab projection must carry.

Consequence: adding Stack children that carry no panel identity, and calling them tabs, is the bug. Whatever the verbs do, they must project panel state; they must not mint anonymous slots.

Acceptance criteria

  1. The verbs exist and are registered. tab.open, tab.switch, and tab.close are defined in the Core command surface and discoverable/registered through the same per-window registry the panel commands use (crates/bitty-ui/src/panel.rs:569-609), with the same duplicate-rejection and per-panel cap discipline. Naming must match the existing command grammar (QualifiedCommand::parse), not invent a parallel namespace. Reorder is not required by this issue; if it ships, it follows the same rules.
  2. Every verb commits a validated layout tree or nothing. A tab.open / tab.close that mutates the layout must validate before commit:
    • structural validity via LayoutNode::validate_structure (crates/bitty-ui/src/layout.rs:1349), which already rejects an empty Stack tombstone surviving a commit (:1344) and out-of-range split ratios (:1342-1343);
    • view-set validity via validate_proposal(tree, views) (crates/bitty-ui/src/provider.rs:422).
      A tree that fails either check leaves the previous layout and the previous focus in place. Failure is atomic: no partial mutation, no half-switched tab, no orphaned leaf.
  3. Typed failure, no panics. A verb naming an unknown tab, a tab whose panel generation is gone, a switch on a single-tab stack, and a close that would leave the tree a tombstone each return a typed error. No unwrap, no silent no-op that reports success.
  4. Closing a tab re-homes focus before the removal lands. The close path must move focus off the id being closed before the structure is mutated and persisted, using the same ordering the workspace code already enforces for a panel leaving a slot (crates/bitty-runtime/src/runtime/workspaces.rs:2735-2759, WS-INV-19: re-home focus off the moved id before the source slot is mirrored, so a dangling focus id can never be persisted and later read as dead). Primary ownership does not move with focus. Closing the last tab has an explicit, documented behaviour rather than an incidental one.
  5. Stack stops claiming to be tabs, or earns it. Either (a) the doc comments at crates/bitty-ui/src/layout.rs:94-95, :118, and :670 are reworded to describe what the container actually does (paint-order stacking of co-located children) and the tab language moves to the tab projection layer, or (b) the container gains the identity/active-child semantics the tab projection needs. This issue does not decide which; it requires that the code stop asserting tabs it does not implement.
  6. tabline consistency. The UiBlockState treatment at crates/bitty-runtime/src/plugin_runtime/services.rs:3374 and the Unsupported placement at crates/bitty-runtime/src/runtime/band_slots.rs:103-105 must agree with whatever model lands. A tab strip is not a one-row band gated by band_is_visible; if it becomes hostable, its visibility rule is its own.

Open questions

These are deliberately not decided here. The implementing issue/PR must answer them explicitly, in writing, before writing code:

  1. Does a tab need its own PanelId? PanelId is a stable handle for a panel instance (crates/bitty-ui/src/panel.rs:26), distinct from ViewId. Is a tab 1:1 with a panel (so the tab key is the PanelId), or may several tabs project one panel at different states, requiring a distinct TabId? Choosing wrong here decides whether close semantics are "destroy the panel" or "detach a view".
  2. Is Stack a layout node or a projection cache? If a tab is a projection of a panel, the layout tree arguably holds only the active projection and Stack is a serialization artifact — which would mean Stack should never contain more than one live child and the multi-child form is a bug. Or Stack stays a real container and the active index becomes layout state. The two answers have different persistence formats and different validate_structure rules.
  3. Where does tab state live — layout, panel registry, or both? LayoutNode is pure geometry with no ownership (crates/bitty-ui/src/layout.rs:103-131); the registry owns generations and focus. Which one is authoritative for the active tab across a save/restore cycle?
  4. What does tab.switch do to focus and to input mode? The workspace path couples a switch to sync_mode_caches_to_focus (crates/bitty-runtime/src/runtime/workspaces.rs:2756). Does a tab switch re-attribute input-mode caches the same way, and does it set pending_full_redraw?
  5. Is the workspaceline exclusive claim (services.rs:6611-6621) still the right gate once tabs are Core-owned verbs? An exclusive plugin claim and a Core command surface can both want authority over the strip; the resolution must be stated, not assumed.

Out of scope

  • Implementing tab reorder, drag-to-reorder, or tab overflow/scroll.
  • Changing the seven-name UiSlot set (crates/bitty-lua/src/ui.rs:119-127).
  • Plugin-authored tab verbs. If plugins get a tab API, that is a separate capability decision with its own error vocabulary.

Activity

  1. added this to the v0.1.0 milestone on Nov 14, 2026
  2. added
    feat
    area:ui
    P2
    on Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2area:uifeat

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions