Layout Export
Introduction
The LayoutExporter class provides extension methods for exporting the computed layout of a Gum UI tree as JSON. All values are resolved to absolute pixel coordinates and dimensions, making the output useful for diagnostics and AI-driven layout workflows.
LayoutExporter is defined in the GumRuntime namespace and extends GraphicalUiElement.
Usage
To use LayoutExporter, add the following using statement:
using GumRuntime;Getting JSON as a String
The ToLayoutJson extension method returns the full layout tree as a JSON string:
// Initialize
string json = root.ToLayoutJson();Writing JSON to a File
The ExportLayoutJson extension method writes the layout tree directly to a file:
// Initialize
root.ExportLayoutJson("layout.json");Output Format
Each element in the JSON output includes the following properties:
type
string
The renderable type name (e.g. "InvisibleRenderable", "Text", "Sprite")
name
string
The element's Name. Omitted if null or empty.
x
number
Absolute X position in pixels
y
number
Absolute Y position in pixels
width
number
Absolute width in pixels
height
number
Absolute height in pixels
visible
boolean
Effective visibility, accounting for parent visibility
text
string
The text content. Only present on Text elements.
children
array
Child elements, recursively. Omitted if the element has no children.
Example Output
The following code:
Produces output similar to:
Invisible Elements
Elements with Visible set to false are included in the output with "visible": false. This allows diagnostic tools and AI to reason about the full layout tree, including hidden elements.
Intended Use Cases
AI-assisted layout - An AI agent building layouts in code can call
ToLayoutJsonto inspect what it produced without visual rendering.Layout debugging - Export the layout tree to a file for offline inspection during development.
Automated testing - Verify layout structure and positioning in integration tests.
Last updated
Was this helpful?

