Skip to content
Ooidget

Ooidget Component Format 0.1Editor's Draft

Layers

A widget’s layers are drawn in array order, the first at the back. Each layer is a JSON object. Its kind is given by the first of these members it has, in this order: use, slot, primitive, paint, image, svg / svgExpr, shape / style / pathExpr, text / runs. A layer with none of them is unknown and is skipped (fallbacks).

Common properties

PropertyTypeRequiredDescription
whenExpression<boolean>noThe layer is drawn only while this is true. Absent: always.
frameFramenoThe layer’s box, anchored to the instance’s edges.
box[number, number, number, number]noThe layer’s box, fixed. Ignored when frame is present.
boxExprExpression<box>noThe layer’s box, computed. Takes precedence over frame and box when it yields a box.
opacitynumberno0 to 1. Absent: 1.
opacityExprExpression<number>noComputed opacity, clamped to 0..1. Takes precedence over opacity.
clipbooleannoClip the layer to its box.
regionstringnoName the layer’s box as a region.

A layer with none of frame, box or boxExpr covers the instance: its box is [0, 0, ui.w, ui.h].

Frames

A frame places a box relative to the instance’s edges, with the meaning of CSS absolute positioning [CSS2 §9.3]: l, t, r, b are the CSS left, top, right and bottom offsets and w, h the width and height. Each is a number or an Expression<number>.

To compute a frame’s box inside an area of width W and height H, run these steps:

  1. Let w be the value of w if present, else W. Let h be the value of h if present, else H.
  2. If l and r are both present, let x be l and set w to W − l − r. Otherwise, if l is present, let x be l; if r is present, let x be W − r − w; otherwise let x be (W − w) / 2.
  3. Compute y and h from t, b and H in the same way.
  4. Return [x, y, w, h].

Shape

A shape is a primitive outline painted by its effects.

PropertyTypeRequiredDescription
shapestringyes"rect", "ellipse" or "path".
radiusnumber or [number, number, number, number]noCorner radii of a rect (top-left, top-right, bottom-right, bottom-left), clamped to half the shorter side.
dstringfor pathSVG path data [SVG2 §9.3], in the layer’s box coordinates.
pathExprExpression<string>noComputed path data; implies shape: "path".
effectsarray of EffectnoPainted in order. Absent: nothing is painted.
stylestringnoA style whose radius and effects come before the layer’s own. Implies shape: "rect".

Text

PropertyTypeRequiredDescription
textExpression<string>yesThe text. To give a literal, quote it inside the expression: "'Play'".
sizenumbernoFont size in design units. Absent: 12.
colorColornoA CSS colour. Absent: #000000.
fontstringnoA CSS font-family list [CSS-FONTS].
weightnumbernoCSS font-weight, 1 to 1000. Absent: 400.
alignstringno"left", "center" or "right" within the box. Absent: "left".
valignstringno"top", "middle" or "bottom". Absent: "middle".
wrapbooleannoWrap to the box width. Absent: a single line.
runsarraynoInstead of text: styled spans, each { "text": Expression<string>, ...text properties }.

Text is shaped and laid out as CSS would lay out the same string in the same font, size and weight [CSS-TEXT]. A runtime MUST use the first available family of font, then the host’s default sans-serif face.

Image

PropertyTypeRequiredDescription
imagestringyesAn asset name, or "$key": the name held by the view’s member key.
framesintegernoThe image is a filmstrip of this many frames of equal height, stacked top to bottom. Absent: 1.
frameBystringnoThe view member, a number in 0..1, that picks the frame: frame round(v × (frames − 1)).
fitstringnoCSS object-fit: "fill" (default), "contain", "cover".

Assets are PNG, JPEG, WebP or SVG. A missing asset draws nothing.

SVG

PropertyTypeRequiredDescription
svgstringyesAn SVG fragment: the content of an <svg> element whose viewport is the layer’s box.
svgExprExpression<string>noA computed fragment. Takes precedence over svg.

The fragment MUST use only the SVG subset. It is drawn in a coordinate system whose origin is the box’s top-left corner and whose unit is the design unit; the widget’s defs are in scope.

Use

A use layer draws another component inside the layer’s box.

PropertyTypeRequiredDescription
usestringyesA component name, or "$key" for the name held by the view’s member key.
propsobjectnoValues placed over the used component’s initial state. A string value "$key" is the view’s member key.

The used component is drawn at its design size, scaled uniformly to fit the box and centred in it (CSS object-fit: contain). It is drawn as it starts: its behaviour does not run and it takes no input. A component that must respond to input is a child, not a layer.

If the name does not resolve to a component, the layer is passed to the host as a host draw.

Host-drawn layers

KindPropertyDescription
Slotslot: stringA box whose contents and input the host owns: an editor’s canvas, a video, a native view.
Primitiveprimitive: stringA drawing the host performs from the layer and the view, for what layers cannot express.
Painterpaint: stringA named painter program; see Painters.

The runtime passes the layer, its box and the view to the host. A host that does not know the name draws nothing.