Class: Plushie::Widget::Canvas

Inherits:
Object
  • Object
show all
Defined in:
lib/plushie/widget/canvas.rb

Overview

Typed builder for the canvas widget: vector drawing surface.

Canvas is a container widget. Its children are +layer+ nodes (each mapping to an iced Cache for independent tessellation) or direct shape nodes for simple cases.

Examples:

DSL usage

canvas("drawing", width: 400, height: 300) do
  layer("bg") { canvas_rect(0, 0, 400, 300, fill: "#eee") }
  layer("fg") { canvas_circle(200, 150, 50, fill: "#f00") }
end

Builder API

Canvas.new("drawing", width: 400, height: 300)
  .add_layer("bg", [Node.new(id: "r1", type: "rect", props: {x: 0, y: 0, w: 400, h: 300})])
  .build

Instance Method Summary collapse

Instance Method Details

#add_layer(name, shape_nodes) ⇒ Canvas

Add a named layer of shape nodes as children.

Parameters:

  • name (String)

    layer name (used for cache keying)

  • shape_nodes (Array<Node>)

    shape child nodes

Returns:

  • (Canvas)

    new Canvas with the layer appended



37
38
39
40
# File 'lib/plushie/widget/canvas.rb', line 37

def add_layer(name, shape_nodes)
  layer_node = Node.new(id: name, type: "__layer__", props: {name: name}, children: shape_nodes)
  push(layer_node)
end