OpenFresco.Layout (open_fresco v0.1.0)

Copy Markdown View Source

Resolves a scene's computed layout before it is drawn:

  • Text wrap — each text/stamp element's resolved content is wrapped to its box width, storing the lines and the rendered block height. Measurement-accurate when measure: true + resvg is available (wrap points match the render); a character-count estimate otherwise.
  • Button auto-width — a button with auto_width: true gets its box widened to the measured label plus horizontal padding.
  • Anchor reflow — an element anchored to another (edge + gap + align) is repositioned relative to the target's rendered box; chains resolve in dependency order and cycles are rejected (validate/1) — during resolve/3 a cyclic anchor is dropped so rendering still proceeds.

Runs on every render (cheap in estimate mode; OpenFresco.render/3 opts into measurement). Results are stashed on transient :_lines / :_rendered_h element keys the SVG generator reads.

Summary

Functions

Resolve wrap, auto-width, and anchor positions. Returns the scene with updated element boxes and :_lines / :_rendered_h annotations. Never raises; a cyclic anchor is left un-applied.

:ok, or {:error, {:anchor_cycle, ids}} if the anchor graph has a cycle.

Functions

resolve(scene, values, opts \\ [])

@spec resolve(OpenFresco.Scene.t(), map(), keyword()) :: OpenFresco.Scene.t()

Resolve wrap, auto-width, and anchor positions. Returns the scene with updated element boxes and :_lines / :_rendered_h annotations. Never raises; a cyclic anchor is left un-applied.

validate(scene)

@spec validate(OpenFresco.Scene.t()) :: :ok | {:error, {:anchor_cycle, [String.t()]}}

:ok, or {:error, {:anchor_cycle, ids}} if the anchor graph has a cycle.