Skip to content

Viz controls & interactions architecture

How interactive UI — control views, overlays, banners, editors, file choosers, and interactive 3D objects — is wired end-to-end in py/pytanga/viz/. Follow this contract when adding a new control, view, or interactive element. For the overall scene/layout/overlay model, see viz-architecture.md.

Concepts

Three orthogonal concerns, one model:

  • Scene — a 3D/2D world of entities (incl. interactive objects) + a camera
  • scene chrome.
  • Layout — a tree arranging scene panes (SceneView) and widgets (*View) in split/stack/overlay views (one per page).
  • Control — one model id + kind + value + handlers, wrapped by a *View(ControlView) and placed in an overlay GroupView or a SceneView(overlay=[...]), a layout pane, or a banner/dialog.
  • Interaction — an interactive object (ActPoint, …) under the same event model; it differs only in payload richness and coalescing.

Fixed contract

  1. Single global id namespace. Every control, interactive object, and View has a globally unique, stable id (views auto-generate v0… and can override it via id=); scene is a routing hint, not a storage key. Stable ids are what make viz.remove_view(id) possible, and what the frontend reconciles a view_layout re-push on — there is one live-view registry (_viewRegistry, see viz-architecture.md) and no parallel id-indexed dicts. The reconcile allow-list preserves every content view by id (scene panes, controls, log_view, file_chooser_view, table_view, progress_bar_view, and group); only split/stack/toolbar/menu are rebuilt. Registry-backed views (MessageView → _messageViews, FileChooserView → fileBrowser._views) only forget their entry in destroy() when it still points at them.
  2. One (id, event) registry. ControlHandlerRegistry keys handlers by (id, event) — change, click, press, release, cell_change, row_add, column_add, row_delete, toggle, close, accept. Layout views, banners, dialogs, editors, and interactions all register here.
  3. One control model. Each *View wraps a pytanga.viz._controls.Control (exposed as view.control) and serializes its fields from it via Control.serialize (_fields() per kind). ControlView and each concrete *View expose explicit typed forwarders — @property reads plus set_value/get_value/undo/redo/can_undo/can_redo methods — so value and history live on the control, not on a host. Two handler shapes share that one registry, distinguished by the stored HandlerOrigin: ControlHandler (async def h(value, event: ControlEvent)) for controls, and InteractionHandler (async def h(event)) for interactive objects. Every event derives from the single ControlEvent; the interaction events (InteractionEvent → ClickEvent/DragEvent/ScrollEvent) add the target object_id, the event_type and the camera. See Handler types below for the full set of aliases.
  4. One client→server envelope. The frontend sends every user action through sendEvent(target, event, data) in templates/events.js: { type: "event", target: "<id>", event: "<name>", data: {…} }. server.py maps event → the control or interaction callback.
  5. Tree-walk dispatch, one registry. Inbound control:* events route to LayoutHost.dispatch_control_event, which resolves the control id by walking the layout trees and dialog contents (resolve_control — there is no _control_views index) and delegates to control.handle_event. Interactions route through InteractionHost._dispatch_interaction_event (handler (event), with drag-move coalescing + camera caching) — reading from the same registry.
  6. One async request/reply seam. Control.handle_event_async(event, payload) -> Dispatch (default delegates to the sync handle_event) lets a kind await a provider before reporting its dispatch. A Dispatch may also carry a reply message dict, which dispatch_control_event sends only to the requesting browser via Transport.send_to_browser. Request/response events (e.g. a custom enum column's enum_options) use reply instead of a broadcast control_update.

Handler types

Handlers are async callables. Their arity and event type say which family they belong to; all aliases are public (exported from pytanga.viz).

Alias Signature Attached through
ControlHandler async def h(value, event: ControlEvent) a control's on_* fields (on_change, on_click, on_press, on_release, on_cell_change, on_row_add, …)
EnumOptionsHandler async def h(request: TableEnumOptionsRequest, event: ControlEvent) -> list[str] \| tuple[str, ...] \| None Table.on_enum_options (custom enum columns; reply-only)
InteractionHandler async def h(event: InteractionEvent) Visualizer.on_interaction(object_id, event_type, h), VizSceneHandle.on_interaction, VizObjectRef.on_interaction
ActHandler · ActEventHandler · ActClickHandler async def h(event: DragEvent \| ClickEvent, obj: ActSceneObject) an ActSceneObject subclass' own handler= / on_drag_start= / on_drag_end= / on_click= constructor kwargs

Both ControlHandler and InteractionHandler are Awaitable-returning, but the interaction one is declared as Coroutine because the interaction dispatcher schedules it with asyncio.create_task — a custom awaitable that is not a coroutine is not accepted there.

The control value argument depends on the kind (float for sliders, str for dropdowns / text / textarea / colour pickers, bool for checkboxes, None for buttons and group toggles, a change/selection dataclass for tables) and is annotated Any in ControlHandler; see ControlHandler's docstring for the per-kind table. ActHandler returns bool: True means "I handled it completely (including the flush)", False lets the default behaviour run (move the object and flush).

Event hierarchy

ControlEvent                      # shared base: browser_id, key, value
└── InteractionEvent              # + object_id, event_type, camera
    ├── ClickEvent                # + mouse_button, modifiers, screen_position,
    │                               world_position, world_normal, ray_origin,
    │                               ray_direction
    ├── DragEvent                 # + screen_position, delta_pixels, world_position,
    │                               world_delta, drag_mode, ray_origin,
    │                               ray_direction, delta_transform
    └── ScrollEvent               # + screen_position, scroll_delta

screen_position is in canvas-local pixels (clientX - rect.left, clientY - rect.top — top-left origin of the renderer canvas) for every pointer event; relative fields (delta_pixels, world_delta) are frame-independent deltas. Click and drag_start carry the same position fields (screen_position, world_position, ray_origin/ray_direction, camera), so both resolve their ideal anchor from the picking ray the same way.

Two consequences worth knowing when writing a handler:

  • Annotate the concrete event. world_position lives on ClickEvent / DragEvent, not on InteractionEvent, so async def h(event: InteractionEvent) cannot read it — use DragEvent for drag handlers.
  • Events may grow. ControlEvent is extensible: the event is always the last argument, after the value, so extra fields can be added without breaking existing handler signatures.

Registration

  • Controls. Handlers are dataclass fields named on_<event> on the Control; Control.register_handlers (called by LayoutHost.register when a view tree is mounted) maps on_change → "change", on_cell_change → "cell_change", … and registers each under (control_id, event) with HandlerOrigin.CONTROL.
  • Interactive objects. on_interaction(object_id, InteractionEventType.DRAG_MOVE, handler) registers under (object_id, "drag_move") with HandlerOrigin.INTERACTION. ActSceneObject does this for you in _init, mapping its constructor kwargs onto DRAG_MOVE (the per-frame handler), DRAG_START, DRAG_END and CLICK.
  • One registry, one key space. ControlHandlerRegistry stores both families side by side, tagged with HandlerOrigin; read control entries with get() and interaction entries with get_interaction(), and use clear_controls() to drop only the control family. Registration is last-writer-wins per (id, event), and the family is not checked — a control and an interactive object sharing an id and an event name shadow each other.
  • Request/reply. EnumOptionsHandler is registered like any other on_* field, but its Dispatch.reply is sent only to the requesting browser instead of broadcasting a control_update.

Handler (the ambiguous old single alias) no longer exists — use the explicit aliases above. Typing guidance for the handlers you write is in typing-and-annotations.md: annotate value: Any, event: ControlEvent for controls and event: DragEvent, obj: ActSceneObject for act objects, and narrow (isinstance) before touching a subclass-only attribute such as ActPoint.point.

Host layer

Control/overlay concerns are split out of Visualizer into hosts in py/pytanga/viz/_hosts.py:

  • OverlayHost — base that holds the two ports (Transport + LayoutHost); _handler_registry/_push_message are thin aliases over Transport.
  • LayoutHost (in _layout.py) — the owner of scenes + layouts. It registers a mounted view tree (register walks iter_control_views and calls each Control.register_handlers, injecting the _push callback), resolves control ids (resolve_control — layouts + dialogs), and runs the control:* / file_browser_* dispatch core (dispatch_control_event). There is no ControlHost.
  • ThemeHost / InteractionHost — theme selection and interactive-object handling.
  • OverlayContainer (in _layout.py) — the per-layout overlay: add(view), show_banner/alert/confirm, show_dialog, open_editor, and their _on_close/_on_accept handlers (the old BannerHost/DialogHost/ EditorHost are folded into it).

Visualizer exposes the public API through explicit forwarders (no __getattr__); _register_routes() installs the inbound routing table on the Transport.

View & layout model

The layout tree is the single render path for every page:

  • View is the base for every pane/container (SceneView, StackView, SplitView, GroupView, MenuView, and the *View control wrappers); every view has a stable id (auto v0…, overridable) so it can be addressed/removed at runtime.
  • SceneView is a pane that renders a named scene; its overlay lists views (e.g. a GroupView) that float over that pane's canvas, anchored by each child's position (EAnchor).
  • A GroupView(parent_id="<entity>") in a SceneView(overlay=[...]) is instead attached to that entity via CSS2D. Because view_layout arrives before the scene entities, ThreeJsView defers the attach until the parent entity is registered (_pendingAttachedGroups), so anchored groups appear on first load.
  • GroupView is a titled StackView with an optional leading icon, icon_only mode, and a borderless fold button — the control-group container.
  • MenuView is a hamburger dropdown or a permanent bar of options (EControlVariant.MENU flattens its control children). Choosing an option auto-closes the menu tree: a button click or a dropdown change closes it (walking _parentMenu up to the root), while checkboxes and sliders stay open.

Controls are added declaratively — build the *View and either pass it to set_layout (or viz.add(view), which mounts it in the default layout's overlay) or list it in a SceneView(overlay=[...]). The whole tree serializes to one view_layout message via serialize_layout(root, name=..., overlay=[...]).

View-mode unification

There is one view mode. A "single scene" is served as a layout whose root is a one-SceneView stack (StackView("vertical", [SceneView(name)])) merged with the global overlay (base scene "" only) and per-scene overlays:

  • LayoutHost._scene_layout_for(scene_name) resolves any scene to its serialized view_layout (the base scene reuses the default layout).
  • The server always resolves a view_layout on ready (layout → _layout_callback, else _scene_layout_callback(scene_name)) and the frontend always renders through _buildLayout — there is no separate single-scene bootstrap.
  • Global-overlay changes are granular: viz.add(view) pushes an overlay_define and viz.remove_view(id) pushes an overlay_remove (only the overlay view is sent, not the whole layout); per-scene overlays and set_layout re-push the full view_layout instead.
  • On every view_layout the frontend reuses the existing ThreeJsView scene panes (keyed by scene name) rather than tearing them down, so only the DOM chrome rebuilds and the WebGL scene/camera survive; a scene pane newly introduced by a re-push fetches its state via scene_sync_request.

Event names

Control events (→ LayoutHost.dispatch_control_event): change, click, press, release, cell_change, row_add, column_add, row_delete, undo, redo, toggle (group), close (banner/editor — data.value is the editor's text or null), file_browser_navigate, file_browser_select.

File chooser (file_chooser_view / FileChooserDialog) — the backend list_directory filters non-directory entries by the control's file_filter (comma/space-separated, case-insensitive extensions and/or full-filename glob patterns such as hello_*.png) plus an optional pattern (a single case-insensitive glob) forwarded from the file_browser_navigate payload, and, when folders_only=True, hides files; both are resolved from the control in the file_browser_navigate handler. The dialog footer is an editable filename field plus a directory label: typing drives the pattern glob filter over the selected folder. A single click on a file highlights it and selects it (fills the filename field); double-click accepts it. The OK button stays disabled until the filename is non-empty and, when existing_only=True (the default), matches a listed file; existing_only=False is save mode and accepts names that do not exist yet. OK fires accept carrying the full path as its value. Directories navigate on a single click, and folder mode adds a "Select this folder" action that selects the current directory.

Interaction events (→ InteractionHost._dispatch_interaction_event, coalesced): interaction:click, interaction:dblclick, interaction:drag_start, interaction:drag_move, interaction:drag_end, interaction:scroll.

Client → server logging

The browser reports warnings/errors to the backend over the same event envelope, targeting a backend-only ClientLog control (_controls.py, id "client_log"):

  • Frontend sendLog(level, message, { source, data }) → sendEvent("client_log", "log", { level, message, source, data }) (templates/events.js); level ∈ debug|info|warn|error.
  • server.py::_EVENT_MSG_MAP maps "log" → "control:log", routing it to LayoutHost.dispatch_control_event, which resolves the reserved id to the ClientLog control (a LayoutHost hook — the control is not in a layout).
  • ClientLog.handle_event("log", payload) normalizes the payload into a ClientLogRecord and fires ("client_log", "log"); the default sink logs via logging.getLogger("tanga.viz.client"), replaceable with viz.on_client_log(handler).
  • Shader compile errors — the live viewer installs renderer.debug.onShaderError (renderers/shader-error.js) and reports a formatted driver log as a source: "shader" record; Visualizer.on_shader_error(handler) filters those records over on_client_log (e.g. to show a banner).
  • ClientLog is backend-only: never serialized, never placed in a layout.
  • Opt-in trace forwarding: setLogForwarding(true) / ?log=1 additionally forwards the frontend _log(...) init/WS lines at info level (default off — only console.warn/console.error are forwarded).

Image load events

The image renderers (renderers/image.js, renderers/image-background.js) report lifecycle events over the same envelope, targeting a backend-only ImageStatus control (_controls.py, id "image_status"):

  • Frontend sendImageEvent(event, data) → sendEvent("image_status", event, data) (templates/events.js).
  • server.py::_EVENT_MSG_MAP maps image_loaded → control:image_loaded, image_tile_load → control:image_tile_load, and image_tile_loaded → control:image_tile_loaded; LayoutHost.dispatch_control_event resolves the reserved id to the ImageStatus control (a LayoutHost hook, mirroring client_log).
  • ImageStatus.handle_event(event, payload) normalizes the payload into an ImageStatusRecord (image_id, source, width, height, level, tile_version, browser_id) and fires ("image_status", event).
  • image_loaded fires once when an image's first texture becomes displayable; image_tile_load / image_tile_loaded fire around each tiled-pyramid level fetch (start / swapped in). Register handlers via viz.on_image_loaded(handler) / viz.on_image_tile_load(handler) / viz.on_image_tile_loaded(handler), each async def h(record, event).
  • ImageStatus is backend-only: never serialized, never placed in a layout, with a silent default sink (opt-in via the on_image_* API).

Adding a new control kind

  1. Backend model — add a Control dataclass in py/pytanga/viz/_controls.py (id/label/tooltip + kind fields) with _value_type + _fields() (or set_value/get_value overrides for table-like kinds). There is no central serialization/coercion switch — serialize() merges _fields() and set_value coerces via _value_type.
  2. Layout view — add a *View(ControlView) in py/pytanga/viz/views.py whose __init__ builds self.control = <Control>(...) (keep the constructor signature); the base ControlView._serialize emits the fields from self.control, and the view exposes its kind-specific fields through explicit typed @property forwarders (read-only) plus explicit set_value/undo/redo/… methods. Handler registration is automatic: the on_* constructor kwargs are dataclass fields on the control, and Control.register_handlers maps each on_<event> to its (id, event) registry entry at mount time.
  3. Frontend — add a create<Kind> factory in templates/controls/<kind>.js (importing the shared registry/event/icon helpers from controls-panel.js, and registering a _controlRegistry entry with an owner and an apply(value)), and, for a layout view, a views/<kind>-view.js whose render() calls it with owner: 'layout'. Send events via sendEvent(id, "<event>", { value }).
  4. Server routing — if the kind introduces a new event (not just a value), add the event→message mapping to server.py::_EVENT_MSG_MAP. Event handling lives on the control: override Control.handle_event(event, payload) -> Dispatch in _controls.py to mutate the model and report which (id, event) handler to fire and what to push back (see Table.handle_event). For a kind whose handler must still fire when the control id is not resolvable, mirror the parse_table_event helper. For an async request/response event, override Control.handle_event_async (declare the provider as an on_* field so register_handlers registers it) and return Dispatch(reply=<message>); the dispatcher sends that reply to the requesting browser only (see Table.handle_event_async for enum_options).
  5. Tests — serialization round-trip, registration, and dispatch.

ParamsView (composite control view)

ParamsView (py/pytanga/viz/views/params_view.py) is not a new control kind — it is a plain View whose children are ordinary ControlViews, one per key/field of a dict or @dataclass. Its _serialize emits a params_view node with rows = [{key, title, control}] (each control is a full control-view node); build.js recursively builds each row's control, so handler registration and event routing reuse the existing (id, event) registry unchanged.

  • Per-field UI metadata is a ControlUI spec (py/pytanga/viz/_params_ui.py), written via param_ui(default, ui=<ControlUI>) or raw field(metadata={"param_ui": <ControlUI>}); keys with no spec are inferred from the value/field type (including Enum/Literal → dropdown and Optional[X]/X | None unwrapping).
  • The new Control.hide_label field (serialized only when True) makes a control factory render without its own label — the params row's left column shows the title instead.
  • Change events carry the field: ParamsView sets event.key/event.value on the shared ControlEvent before firing the handler, and a per-field ControlUI.on_change (when set) replaces the view's shared on_change for that row. Values are coerced to the resolved field type (coerce=/integer= to override), and ControlUI.validate can reject a change (the control reverts).
  • Non-parameter rows are declared with extra_rows=[RowSpec(key, ui, …)] (position "above"/"below"); they render as ordinary child controls.
  • Full-width / captioned rows — ControlUI.full_width renders a row without a key column (serialized as full_width: true; params-view.js treats it like a nested group). It defaults True on ButtonUI/MarkdownUI/ProgressBarUI; ButtonUI.label is the button's own caption (rendered instead of the key title).
  • Nested dataclasses render as a nested GroupView (tagged tanga-group-nested in the frontend) wrapping a nested ParamsView whose id is f"{view.id}.{key}"; GroupUI(title=…, collapsed=…, extra_rows=[…]) customizes it. The nested view inherits the parent's on_change and carries a key_prefix, so a nested change fires the shared handler with a dotted event.key like "surface.scale" (the handler still receives the top-level state).
  • Row state (set_visible/set_enabled/set_title/set_options/set_value) reuses the existing control_state message and resolves dotted keys ("surface.scale") down nested groups. Group rows support set_visible/set_enabled/set_title too: GroupView carries visible/enabled/title and pushes control_state {visible}/{enabled}/ {title}; viewer.js routes {enabled} to the group's setEnabled (greys the header, collapses the pane, locks the fold toggle) and {title} (without row) to the group's setTitle. set_state/add/remove rebind the source (nested groups recursively) or mutate the row list and re-push the layout via the injected _push_layout callback.

Interactive objects

Register handlers with Visualizer.on_interaction(object_id, event_type, handler) (stored under (object_id, event_type.value)). The per-pane frontend InteractionController captures/throttles pointer events and sends them under interaction:* names; the backend coalesces drag_move.

Active rectangles

ActRectangle2D (_active.py) is an interactive axis-aligned rectangle: a visual-only Rectangle2D body plus child ActPoint handles (4 corners for resize, one centre handle for translate). It is a composite — the frontend raycasts one mesh per entity, so each grabbable part is its own ActPoint entity and the body's interaction_config is disabled. Default resize/translate behaviour is overridable (on_corner_drag / on_translate / on_change); the rectangle_labeling.py example composes a disabled left-drag DragBinding plus a mode flag to drag out a preview Rectangle2D and finalize an ActRectangle2D.

SquarePointStyle (a PointStyle variant, dispatched in factory.js by style_type exactly like CrossHairPointStyle) renders a Point as a flat square marker — used for the rectangle handles.

Per-handler enable/disable + cursors

Every active element (ActSceneObject) can toggle its handlers individually: DragBinding/ClickBinding carry a mutable enabled flag, and the general handler/on_click are toggled via set_handler_enabled/set_click_enabled. refresh_interaction() re-registers the trigger set after a change. A cursor can be attached to an element (ActSceneObject(cursor=…) → hover_cursor, shown on hover) or to the gesture (InteractionConfig.cursor, shown during the drag); Visualizer.set_cursor()/VizSceneHandle.set_cursor() set a per-scene override (via the scene_config message) for mode switches.

Active object handle controls

Every active object — a bare ActPoint and each composite (ActRectangle2D, ActEllipse, ActCircle, ActLine, ActPolygon) — is an ActiveObject (the shared base, formerly _ActWithHandles) with the same public handle API:

  • set_handles_enabled(enabled) — enable/disable dragging of the control point(s). A composite's handles are its child ActPoint markers; a bare ActPoint is its own control point (_reshape_handles() == [self]).
  • set_handles_visible(visible) — show/hide the control point(s) (hiding also disables interaction, mirroring set_translate_handle_visible / set_rotate_handle_visible).
  • set_drag_modifiers(*modifiers) — require ModifierKey values (e.g. SHIFT) to drag, reusing the DragBinding-style modifier matching already in the frontend.

A bare ActPoint has two rendering styles: handle_style (the active/draggable control-point appearance, e.g. a square marker) and style (the content Point appearance, e.g. a round marker). set_handles_enabled(False) swaps to the content style while keeping the point visible; set_handles_visible(False) hides it.

This lets a host (e.g. a labeling app) gate editing by type: show the control points of every entity of the active tool's type, and keep a bare point visible but inert outside point mode.

Interaction surface

Pointer/drag interaction for images (and any flat plane in a pane) is provided by an InteractionSurface (_surface.py) — a per-pane interaction plane with no scene entity. It is the shared primitive behind both the flat ImageCanvas (a PlanarMapper, the z = 0 pixel plane) and a calibrated CameraView.background_image (a CalibratedPlaneMapper, the ⟂-optical-axis plane at a fixed depth).

Three orthogonal concerns:

  • pane — a SceneView (its CameraView supplies the camera, navigation, and optional background_image). SceneView(surface=…) binds an InteractionSurface to the pane, and SceneView(read_only=True) suppresses all interaction on the pane (surface and Act* object editing) while leaving navigation (orbit/pan/zoom) working.
  • surface — the InteractionSurface: a CoordinateMapper (which defines the plane via plane(), its in-plane pixel basis via pixel_axes(), and the pixel↔world mapping) plus pane-level on_drag_start/on_drag/on_drag_end/on_click handlers and the same DragBinding/ClickBinding + cursor + enable/disable API as an ActSceneObject.
  • visual — the image, an orthogonal rendering detail: ImageView (flat ImageCanvas) or CameraView.background_image (calibrated).

The surface resolves pointer→world on the backend: the frontend resolves each gesture (drag/click/dblclick/scroll) to the nearest hit target whose interaction.triggers match — event type + button + modifiers, matched exactly (a trigger with no modifiers fires only when none are held) — falling through to the pane's surface when no nearer entity matches. The surface hit is the mouse ray intersected with the surface's serialized {point, normal} in interaction.js _getSurfaceHit; each event carries the picking ray_origin/ray_direction, and the backend rebases onto surface.drag_anchor/click_anchor (a generic ray↔mapper.plane() intersection) from that ray — no pixel_ray reconstruction — via the same _act_objects lookup as Act entities. The surface serializes as a surface field on the scene_view node ({id, point, normal, interaction}); runtime toggles re-push a view_surface message (handled in viewer.js next to view_background_image).

ImageCanvas (_image_view.py) owns a dedicated 2D scene with a y-down pixel frame (1 unit = 1 pixel) and wraps an InteractionSurface(PlanarMapper()) — the ImageView stays the visual only. Mouse handlers modify shader uniforms via ImageCanvas.set_uniform (an image_update JSON message); pixel data travels on the image transport described in viz-architecture.md. The calibrated_labeling_app.py example binds a CalibratedSurface to the 2d-navigation background pane and marks the overview pane read_only.

A surface registers the button + modifier combinations it reacts to via its drag triggers (each DragBinding(button, handler, *modifiers) becomes a drag InteractionTrigger). Navigation yields to the surface only for those combos: the per-pane InteractionController.surfaceClaimsPointer(event) matches the event's button and held modifiers against the surface's drag triggers (a trigger without mouse_button/modifiers matches any button/modifier). Every other combo passes through to navigation — pan/rotate/zoom — so, for example, a left-only draw binding leaves right-button panning free, and a Shift-gated binding leaves the plain button free.

Coordinate frame overlay/underlay

CoordinateSystem(display_mode="overlay") (see viz-architecture.md) emits two payload-style scene objects — axes_overlay (overlay) and grid_underlay (underlay) — each carrying a static spec. They register no (id, event) handlers and send no interaction/control events: the frontend renderers read the live camera every frame and recompute ticks/grid locally, so pan/zoom needs no backend round-trip.

Per-pane camera view & visibility

SceneView(camera_view=…) (a CameraView bundling camera + lock + navigation + per-pane controls + viewport + background_image) is a per-pane attribute, not a new (id, event) control. It serializes as fields on the scene_view node and is applied by ThreeJsView (setCamera, applyCameraLock, configureControls for the "2d" navigation mode, the viewport crop via applyPinhole, and the NDC background quad). Per-pane entity visibility is runtime state too: SceneView.set_visible(entity_id, visible) pushes a view_visibility message, and Scene.new/add(..., visible_in={view_ids}) gives an entity a static per-view scope (never constructed outside those views).

Viewport state is set at runtime through the existing message dispatch, not a new channel: Visualizer.set_viewport(view, …) pushes a view_viewport message (handled in viewer.js next to view_camera, dispatched to ThreeJsView.setViewport), and set_viewport(scene_name=…) / VizSceneHandle.set_viewport(…) re-push the existing scene_config with a viewport field. See viz-architecture.md.

Per-pane visibility is updated the same way: SceneView.set_visible(entity_id, visible) sends a view_visibility message (handled in viewer.js next to the other view_* messages, dispatched to ThreeJsView.setVisibility).

Background images are swapped the same way: Visualizer.set_background_image(view, image) sends the new pixel frame (binary) followed by a view_background_image message (handled in viewer.js next to view_camera/view_viewport, dispatched to ThreeJsView.setBackgroundImage) — no view_layout re-push, so the pane's WebGL scene and every other pane are untouched.

Control enable/disable/hide (control_state)

Controls carry two runtime state flags on the model — Control.enabled (rendered but greyed out + non-interactive when False) and Control.visible (False hides it without removing it from the layout). Both are serialized only when non-default (False), mirroring tooltip.

Set them at runtime without re-pushing view_layout:

  • ControlView.set_enabled / set_visible (+ enable/disable/show/hide sugar) mutate self.control and push through the injected _push_state callback (injected by LayoutHost.register, next to _push).
  • Visualizer.set_control_enabled(cid, bool) / set_control_visible(cid, bool) resolve the control via resolve_control (layouts and dialogs) and push — so they work for dialog/banner controls too.

The wire message is { type: "control_state", id, enabled?, visible? } (only changed fields), pushed by LayoutHost._push_control_state and handled in viewer.js next to control_update. applyControlState(id, msg) looks up the rendered control in _controlRegistry (each factory stores el: wrapper) and applyControlStateToElement toggles the .tanga-control-disabled class, the native disabled attribute on input/select/textarea/button, and display:none. For a layout ControlView, visible=false also collapses the hosting view: viewer.js looks it up in _viewRegistry (the control id doubles as the ControlView's stable view id) and calls View.setHidden(true), which removes it from flow and reports zero minimum / no preferred size so the enclosing Stack/Split views re-layout; the initial visible:false is applied the same way in build.js. Disabled grey-out uses the theme tokens --tanga-disabled-opacity / --tanga-disabled-fg (overridable per theme).

A numeric range can also change at runtime through the same control_state seam. SliderView / ValueEditView expose set_min / set_max / set_step / set_range, and Visualizer.set_control_range(cid, *, min, max, step) resolves the control, clamps its current value into the new [min, max], and pushes the changed min/max/step fields (plus a control_update when the value was clamped). On the frontend, applyControlStateToElement writes min/max/step onto the slider's native <input type="range"> (the browser re-clamps the thumb), and value-edit.js re-clamps its closure-captured bounds via a per-entry applyState.

A group collapse can also change through the same control_state seam and is user-reportable. GroupView.set_collapsed(collapsed) mutates self.collapsed and pushes {"collapsed": bool}; the frontend resolves the group in _viewRegistry (not _controlRegistry) and calls GroupView.setCollapsed(...). The user's toggle reports back through the existing control:group_toggle route: the frontend click handler sends sendControlEvent('control:group_toggle', groupId, collapsed), and dispatch_control_event sets group.collapsed (via resolve_group) then fires on_toggle ((id, "toggle")), registered by LayoutHost.register when GroupView.on_toggle is set.

Keyboard shortcuts (per-scene, per-pane focus)

Scene-level keyboard shortcuts use the same (id, event) registry and the interaction dispatch path, but are not pointer interactions:

  • Visualizer.on_key(key, handler, *, modifiers=None, scene_name="") (and the VizSceneHandle / ImageCanvas wrappers) stores a KeyBinding in InteractionHost._key_bindings and registers a dispatcher under (key:{scene}:{key}, "key") with origin=INTERACTION.
  • The per-scene key list is synced onto SceneConfig.keyboard ([{"key": …, "modifiers": […]}, …]) and pushed via the existing scene_config message.
  • The frontend attaches a per-pane keydown listener to each ThreeJsView pane's DOM element (per-pane focus: the pane gets tabIndex = 0 and is focused on pointerdown). On a registered key it sends { type: "interaction:key", event_type: "key", scene, key, modifiers, browser_id }.
  • InteractionHost._dispatch_interaction_event special-cases interaction:key, builds a KeyEvent (derived from ControlEvent, not InteractionEvent), and dispatches the most-specific matching binding.

Editable targets (INPUT/TEXTAREA/contentEditable) and auto-repeat are ignored so shortcuts don't hijack typing.

Follow-ups

  • Fold interaction.js onto sendEvent — the interactive-object frontend (templates/interaction.js) still sends interaction:* messages directly rather than through sendEvent (the server already routes event: "interaction:*"). Deferred: it touches the timing-sensitive drag path and isn't covered by the browser-less test suite.
  • Active menu element — if menus gain a backend-visible "active element", add value / on_change / on_activate to MenuView directly (menus are overlay containers, not control leaves, and keyboard navigation is frontend-only).