Inherits gin::FileSystemWatcher::Listener.
JSON-based layout system for JUCE components.
Allows declarative component positioning with expressions, constants, macros, and live reloading.
Usage Example
{
public:
{
button.setComponentID ("myButton");
}
private:
juce::TextButton button;
};
JSON-based layout system for JUCE components.
Definition gin_layoutsupport.h:231
A lightweight 2D point class for projects that don't use juce_graphics.
Definition gin_point.h:25
void addAndMakeVisible(juce::Component &parent, juce::Array< juce::Component * > children)
Adds an Array of components to a parent Component.
Definition gin_componentutils.h:16
JSON Format
Top-level properties:
w, h - Set parent component size
constants - Define reusable constant values
macros - Define reusable component templates
components - Array of component definitions
Component Properties
Identification:**
id - Component identifier (supports comma-separated list or range syntax like "button[0..9]")
factory - Factory name to create component on demand
optional - Boolean, won't assert if component not found
if - Conditional expression to include/exclude component
Position (absolute):**
x, y - Absolute position
xy - Comma-separated "x,y"
r, b - Right/bottom edges
cx, cy - Center position (requires size)
Position (relative):**
xd - Horizontal delta from previous (or "delta,refID" for specific component)
yd - Vertical delta from previous (or "delta,refID")
cxd, cyd - Center delta from previous
Position (special):**
bounds - "parent", "prev", "reduced,N", "reduced,H,V", "reduced,L,T,R,B", or "x,y,w,h"
inset - Component ID to inset from
border - Border amount for inset (default 0)
Size:**
w, h - Width and height
size - Reference to size constant (e.g., "buttonSize" references constants.buttonSize.w/h)
Display:**
visible - Boolean or expression
zorder - Z-order index
Accessibility:**
title - Accessibility title
tip - Tooltip text
Focus:**
order - Component focus order
parentOrder - Parent component focus order
Custom:**
properties - Object with custom properties to set on component
constants - Local constants scoped to this component
macro - Macro name with parameters
components - Nested child components
Grid Layout:**
grid - Component IDs for grid (supports range syntax)
cols, rows - Grid dimensions (default 1)
colGap, rowGap - Grid spacing (default 0)
Constants
Built-in constants:
mac, win, linux - Platform flags (1.0 or 0.0)
parX, parY, parW, parH, parR, parB - Parent bounds
prevX, prevY, prevW, prevH, prevR, prevB, prevCX, prevCY - Previous component
i - Current child index
idIdx - Current iteration index (when using multiple IDs or ranges)
Custom constants can be defined at top-level or per-component:
{
"constants": [
{ "margin": 10 },
{ "buttonSize": { "w": 100, "h", 25 } }
],
"components": [
{ "id": "button", "x": "margin", "w": 100, "h": 30 }
]
}
Expressions
All numeric properties support mathematical expressions:
- Operators:
+, -, *, /, %, (, )
- Constants: Any defined constant name
- Functions:
getX(id), getY(id), getW(id), getH(id), getR(id), getB(id), getCX(id), getCY(id)
Example: ‘"x": "parW / 2 - getW('button’) / 2"`
Macros
Reusable component templates with parameters:
{
"macros": [
{ "id": "standardButton", "w": 100, "h": 30, "tip": "P1" }
],
"components": [
{ "id": "saveBtn", "macro": "standardButton('Save')", "x": 10, "y": 10 }
]
}
Parameters are referenced as P1, P2, P3, etc.
Examples
Simple layout:
{
"components": [
{ "id": "header", "bounds": "parent" },
{ "id": "button", "x": 10, "y": 10, "w": 100, "h": 30 }
]
}
Relative positioning:
{
"components": [
{ "id": "button1", "x": 10, "y": 10, "w": 100, "h": 30 },
{ "id": "button2", "xd": 10, "y": 10 },
{ "id": "button3", "xd": 10, "y": 10 }
]
}
Grid layout:
{
"grid": "cell[0..8]",
"bounds": "10,10,300,300",
"cols": 3,
"rows": 3,
"colGap": 5,
"rowGap": 5
}
Range syntax and expressions:
{
"id": "knob[0..7]",
"x": "10 + i * 50",
"y": 10,
"w": 40,
"h": 40
}