@leafer/layouter
Advanced tools
+3
-3
| { | ||
| "name": "@leafer/layouter", | ||
| "version": "1.0.0-rc.6", | ||
| "version": "1.0.0-rc.7", | ||
| "description": "@leafer/canvas", | ||
@@ -25,7 +25,7 @@ "author": "Chao (Leafer) Wan", | ||
| "dependencies": { | ||
| "@leafer/core": "1.0.0-rc.6" | ||
| "@leafer/core": "1.0.0-rc.7" | ||
| }, | ||
| "devDependencies": { | ||
| "@leafer/interface": "1.0.0-rc.6" | ||
| "@leafer/interface": "1.0.0-rc.7" | ||
| } | ||
| } |
| import { IBounds, ILayoutBlockData, ILeafList, ILeaf } from '@leafer/interface' | ||
| import { Bounds, BoundsHelper, LeafBoundsHelper, LeafList } from '@leafer/core' | ||
| import { Bounds, LeafBoundsHelper, LeafList } from '@leafer/core' | ||
| const { worldBounds } = LeafBoundsHelper | ||
| const { setByListWithHandle } = BoundsHelper | ||
| const bigBounds = { x: 0, y: 0, width: 100000, height: 100000 } | ||
@@ -22,12 +22,18 @@ export class LayoutBlockData implements ILayoutBlockData { | ||
| public setBefore(): void { | ||
| setByListWithHandle(this.beforeBounds, this.updatedList.list, worldBounds) | ||
| this.beforeBounds.setListWithFn(this.updatedList.list, worldBounds) | ||
| } | ||
| public setAfter(): void { | ||
| setByListWithHandle(this.afterBounds, this.updatedList.list, worldBounds) | ||
| this.updatedBounds.setByList([this.beforeBounds, this.afterBounds]) | ||
| const { list } = this.updatedList | ||
| if (list.some(leaf => leaf.noBounds)) { | ||
| this.afterBounds.set(bigBounds) | ||
| } else { | ||
| this.afterBounds.setListWithFn(list, worldBounds) | ||
| } | ||
| this.updatedBounds.setList([this.beforeBounds, this.afterBounds]) | ||
| } | ||
| public merge(data: ILayoutBlockData): void { | ||
| this.updatedList.pushList(data.updatedList.list) | ||
| this.updatedList.addList(data.updatedList.list) | ||
| this.beforeBounds.add(data.beforeBounds) | ||
@@ -34,0 +40,0 @@ this.afterBounds.add(data.afterBounds) |
+15
-15
| import { ILayouter, ILeaf, ILayoutBlockData, IEventListenerId, ILayouterConfig, ILeafList } from '@leafer/interface' | ||
| import { LayoutEvent, WatchEvent, LeafLevelList, LeafList, BranchHelper, LeafHelper, DataHelper, Run, Debug } from '@leafer/core' | ||
| import { updateBounds, updateMatrix, updateChange } from './LayouterHelper' | ||
| import { updateMatrix, updateBounds, updateChange } from './LayouterHelper' | ||
| import { LayoutBlockData } from './LayoutBlockData' | ||
| const { updateAllWorldMatrix, updateAllChange } = LeafHelper | ||
| const { pushAllBranchStack, updateWorldBoundsByBranchStack } = BranchHelper | ||
| const { updateAllMatrix, updateAllChange } = LeafHelper | ||
@@ -17,2 +16,3 @@ const debug = Debug.get('Layouter') | ||
| public layoutedBlocks: ILayoutBlockData[] | ||
| public extraBlock: ILayoutBlockData // around / autoLayout | ||
@@ -80,3 +80,2 @@ public totalTimes: number = 0 | ||
| public layoutOnce(): void { | ||
| if (this.layouting) return debug.warn('layouting') | ||
@@ -104,3 +103,2 @@ if (this.times > 3) return debug.warn('layout max times') | ||
| } | ||
| } | ||
@@ -116,5 +114,6 @@ | ||
| const blocks = this.getBlocks(updateList) | ||
| blocks.forEach(item => { item.setBefore() }) | ||
| blocks.forEach(item => item.setBefore()) | ||
| target.emitEvent(new LayoutEvent(BEFORE, blocks, this.times)) | ||
| this.extraBlock = null | ||
| updateList.sort() | ||
@@ -125,2 +124,3 @@ updateMatrix(updateList, this.__levelList) | ||
| if (this.extraBlock) blocks.push(this.extraBlock) | ||
| blocks.forEach(item => item.setAfter()) | ||
@@ -136,3 +136,2 @@ | ||
| Run.end(t) | ||
| } | ||
@@ -158,14 +157,11 @@ | ||
| Run.end(t) | ||
| } | ||
| static fullLayout(target: ILeaf): void { | ||
| updateAllWorldMatrix(target) | ||
| updateAllMatrix(target, true) | ||
| if (target.isBranch) { | ||
| const branchStack: ILeaf[] = [target] | ||
| pushAllBranchStack(target, branchStack) | ||
| updateWorldBoundsByBranchStack(branchStack) | ||
| BranchHelper.updateBounds(target) | ||
| } else { | ||
| target.__updateWorldBounds() | ||
| LeafHelper.updateBounds(target) | ||
| } | ||
@@ -176,2 +172,7 @@ | ||
| public addExtra(leaf: ILeaf): void { | ||
| const block = this.extraBlock || (this.extraBlock = new LayoutBlockData([])) | ||
| block.updatedList.add(leaf) | ||
| block.beforeBounds.add(leaf.__world) | ||
| } | ||
@@ -211,4 +212,3 @@ public createBlock(data: ILeafList | ILeaf[]): ILayoutBlockData { | ||
| this.__removeListenEvents() | ||
| this.target = null | ||
| this.config = null | ||
| this.target = this.config = null | ||
| } | ||
@@ -215,0 +215,0 @@ } |
+14
-18
@@ -1,6 +0,6 @@ | ||
| import { ILeaf, ILeafLayout, ILeafLevelList, ILeafList } from '@leafer/interface' | ||
| import { ILeafLayout, ILeafLevelList, ILeafList, ILeaf } from '@leafer/interface' | ||
| import { BranchHelper, LeafHelper } from '@leafer/core' | ||
| const { updateAllWorldMatrix, updateAllWorldOpacity } = LeafHelper | ||
| const { updateAllMatrix, updateBounds: updateOneBounds, updateAllWorldOpacity } = LeafHelper | ||
| const { pushAllChildBranch, pushAllParent } = BranchHelper | ||
@@ -18,5 +18,5 @@ | ||
| updateAllWorldMatrix(leaf) | ||
| updateAllMatrix(leaf, true) | ||
| levelList.push(leaf) | ||
| levelList.add(leaf) | ||
| if (leaf.isBranch) pushAllChildBranch(leaf, levelList) | ||
@@ -27,3 +27,3 @@ pushAllParent(leaf, levelList) | ||
| levelList.push(leaf) | ||
| levelList.add(leaf) | ||
| if (leaf.isBranch) leaf.__tempNumber = 0 // 标识需要更新子Leaf元素的WorldBounds分支, 0表示不需要更新 | ||
@@ -37,26 +37,22 @@ pushAllParent(leaf, levelList) | ||
| export function updateBounds(boundsList: ILeafLevelList): void { | ||
| let itemList: ILeaf[], branch: ILeaf | ||
| let list: ILeaf[], branch: ILeaf, children: ILeaf[] | ||
| boundsList.sort(true) | ||
| boundsList.levels.forEach(level => { | ||
| itemList = boundsList.levelMap[level] | ||
| for (let i = 0, len = itemList.length; i < len; i++) { | ||
| branch = itemList[i] | ||
| list = boundsList.levelMap[level] | ||
| for (let i = 0, len = list.length; i < len; i++) { | ||
| branch = list[i] | ||
| // 标识了需要更新子元素 | ||
| if (branch.isBranch && branch.__tempNumber) { | ||
| for (let j = 0, jLen = branch.children.length; j < jLen; j++) { | ||
| if (!branch.children[j].isBranch) { | ||
| branch.children[j].__updateWorldBounds() | ||
| children = branch.children | ||
| for (let j = 0, jLen = children.length; j < jLen; j++) { | ||
| if (!children[j].isBranch) { | ||
| updateOneBounds(children[j]) | ||
| } | ||
| } | ||
| } | ||
| branch.__updateWorldBounds() | ||
| updateOneBounds(branch) | ||
| } | ||
| }) | ||
| } | ||
@@ -63,0 +59,0 @@ |
+2
-0
@@ -7,2 +7,3 @@ import { ILayouter, ILeaf, ILayoutBlockData, ILayouterConfig, ILeafList, IEventListenerId } from '@leafer/interface'; | ||
| layoutedBlocks: ILayoutBlockData[]; | ||
| extraBlock: ILayoutBlockData; | ||
| totalTimes: number; | ||
@@ -28,2 +29,3 @@ times: number; | ||
| static fullLayout(target: ILeaf): void; | ||
| addExtra(leaf: ILeaf): void; | ||
| createBlock(data: ILeafList | ILeaf[]): ILayoutBlockData; | ||
@@ -30,0 +32,0 @@ getBlocks(list: ILeafList): ILayoutBlockData[]; |
12435
3.24%273
4.6%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated