添加图形

使用类创建

创建一个带边框样式的矩形, 并允许拖拽。

import { Leafer, Rect } from 'leafer-ui'

const leafer = new Leafer({ view: window })

const rect = new Rect({
  x: 100,
  y: 100,
  width: 200,
  height: 200,
  fill: '#32cd79', // 背景色
  stroke: 'black', // 边框
  strokeWidth: 2, // 边框粗细
  draggable: true,
})

leafer.add(rect)

使用名称创建

import { Leafer, UI } from 'leafer-ui'

const leafer = new Leafer({ view: window })

const rect = UI.create('Rect', {
  x: 100,
  y: 100,
  width: 200,
  height: 200,
  fill: '#32cd79', // 背景色
  stroke: 'black', // 边框
  strokeWidth: 2, // 边框粗细
  draggable: true,
})

leafer.add(rect)

快速创建

import { Leafer, UI } from 'leafer-ui'

const leafer = new Leafer({ view: window })

const rect = UI.create('Rect', { fill: '#32cd79' }, 100, 100, 200, 200) // x?, y?, width?, height?

leafer.add(rect)