Behaviour for canvas elements.
Canvas elements are the building blocks of canvas drawing. Like widgets, they produce tree nodes, but they operate in the canvas domain: positioned by coordinates rather than layout, drawn by the canvas renderer rather than the widget renderer.
Declaring an element
defmodule MyApp.Canvas.Star do
use Plushie.Canvas.Element
element :star do
field :x, :float
field :y, :float
field :radius, :float
field :points, :integer, default: 5
field :fill, Plushie.Type.Color
end
endGenerated code
The macro generates:
new/1auto-ID constructor (new(opts)) for use inside canvas blocks where the container assigns IDs automaticallynew/2constructor with explicit ID (new(id, opts))- Setter functions per field for pipeline composition
with_options/2for applying keyword options via settersbuild/1for explicitui_node()conversiontype_name/0returning the element type stringencode/1for backward compatibility withPlushie.Type.encode_value@type t,@type optiontypespecsPlushie.Tree.Nodeprotocol implementation
Container elements
Pass container: true for group-like elements that hold children:
element :group, container: true do
field :opacity, :float
endContainer elements get push/2 and extend/2 for adding children,
and new/2 accepts a :do option for inline children.