ADR-008: Unified GUI Object Order
Date: 2026-11-24
Issue: https://github.com/Wasted-Audio/hvcc/issues/294
Context
In Pure Data, graphical objects ([cnv], [bng], [tgl], etc.) and Graph-on-Parent (GoP) subpatches/abstractions are stored in a single canvas list (gl_list). Pure Data renders elements strictly in the chronological order they appear in the .pd file (from bottom/back to top/front).
In ADR-002, the initial pd2gui implementation separated canvas contents into two separate collections:
objects: list[GUIObjects]graphs: list[Graph]
This separation caused two major issues:
- Lost Z-Order: The relative interleaving of subpatches and normal GUI objects on the same canvas was lost during parsing.
- Layer Inversion in Renderers: Downstream code generators (such as
c2dpf/nanovg_render.py) rendered allobjectsfirst and allgraphsafterwards. As a result, subpatches were always drawn on top of all local objects, making it impossible for a UI object to cover or sit on top of a subpatch.
Decision
We unify subpatches/graphs and standard GUI objects into a single recursive tree hierarchy:
Graph is a GUIObject
Graphinherits fromBaseUIwithtype: Literal["graph"] = "graph".gop_sizeis unified tosize: Sizeacross all objects.Graph.objectsholds an ordered list ofGUIObjects(which recursively includesGraph).GraphBaseis removed;GraphRootretains root-level document metadata (id,size,theme,version) and the top-levelobjects: list[GUIObjects].
Sequential Canvas Parsing in PdGUIParser
PdGUIParser.gui_from_canvasmaintains a singleobjects: list[GUIObjects]list.- Subpatches (
#N canvas ... #X restore) and abstractions (#X obj) are appended directly intoobjectsat the point they are encountered. filter_invisible_graphsis merged intofilter_invisible_objects, which recursively validates bounding box intersections with the local GoP area and discards empty graphs.
Tree-Ordered Rendering in Generators
- Generators like
nanovg_render.pytraverseobjectsin sequence. - Standard objects and
PDSubpatchinstances are instantiated and added to the parent widget in the exact order parsed, correctly preserving z-order while keeping child objects clipped inside their respective subpatches.
Breaking Changes
- Breaking IR Change: The top-level
"graphs"key and nested"graphs"keys in the GUI IR JSON are removed. Subpatches now appear inside"objects"with"type": "graph". - Field Rename:
gop_sizeon subpatches is renamed tosizeto conform toBaseUI.
MVP Definition
Subpatches and standard GUI objects maintain their exact canvas z-order as defined in the .pd file. Downstream generators render elements in sequence, allowing UI objects to be placed both behind and in front of subpatches, while maintaining proper Graph-on-Parent clipping for child objects.