创建 Leafer
Leafer 实例是一个树状结构(提供了布局、渲染等管理功能),能够独立运行。作为根节点,可以往里面添加子元素,并且子元素可以通过 Group / Box 层层嵌套,组成一颗复杂的渲染树。
创建固定宽高的 Leafer
view 参数支持 window 、div、canvas 标签对象,注意 view 为 id 字符串时不用加 # 号。
ts
ts
// #创建固定宽高的 Leafer [div]
import { Leafer, Rect } from 'leafer-ui'
const div = document.createElement('div')
document.body.appendChild(div)
const leafer = new Leafer({
view: div, // view 参数支持设置 div 标签对象
width: 600, // 不能设置为 0, 否则会变成自动布局
height: 600,
fill: '#333'
})
leafer.add(Rect.one({ fill: '#32cd79', draggable: true }, 100, 100))
ts
// #创建固定宽高的 Leafer [canvas]
import { Leafer, Rect } from 'leafer-ui'
const canvas = document.createElement('canvas')
document.body.appendChild(canvas)
const leafer = new Leafer({
view: canvas, // view 参数支持设置 canvas 标签对象
width: 600, // 不能设置为 0, 否则会变成自动布局
height: 600,
fill: '#333'
})
leafer.add(Rect.one({ fill: '#32cd79', draggable: true }, 100, 100))
ts
// #创建固定宽高的 Leafer [id]
import { Leafer, Rect } from 'leafer-ui'
const div = document.createElement('div')
div.setAttribute('id', 'leafer-view')
document.body.appendChild(div)
const leafer = new Leafer({
view: 'leafer-view', // view 参数支持使用id字符串(不用加 # 号)
width: 600, // 不能设置为 0, 否则会变成自动布局
height: 600,
fill: '#333'
})
leafer.add(Rect.one({ fill: '#32cd79', draggable: true }, 100, 100))
创建自适应布局的 Leafer
当画布的父节点尺寸改变后会自动 resize, 了解详情。
ts
ts
创建自动生长的 Leafer
画布大小会生长,自动贴合实际内容,用于快速在 HTML 中嵌入 Leafer 元素,了解详情。
注意 App 结构 暂不支持此功能。
ts
ts