TaffyTree 对象
TaffyTree 对象代表整个布局树,并作为布局计算的入口点。
关键职责
- 节点管理:创建、添加、移除和插入节点。
- 树层次结构:维护节点之间的父子关系。
- 计算:通过
computeLayout或computeLayoutWithMeasure调用布局算法。 - 结果检索:存储并提供对每个节点计算结果的访问。
节点 ID 是 bigint,只能用于创建它的树,且必须仍指向活动节点。删除节点或调用 clear() 后应丢弃相应 ID;不要通过访问旧 ID 来探测节点是否存在。
用法
const tree = new TaffyTree(); // 创建节点 const child = tree.newLeaf(new Style()); const root = tree.newWithChildren(new Style(), [child]); // 计算布局 tree.computeLayout(root, { width: 500, height: 500 }); // 获取结果 const layout = tree.getLayout(child);