Skip to content

Commit

Permalink
refactor: adjust the execution timing of label clampForce
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoluoHe committed Jul 31, 2023
1 parent e245a04 commit 2a13907
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions packages/vrender-components/src/label/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,24 +296,6 @@ export abstract class LabelBase<T extends BaseLabelAttrs> extends AbstractCompon
}
}

// 尝试向内挤压
if (clampForce) {
const { dx = 0, dy = 0 } = clampText(text, bmpTool.width, bmpTool.height);
if (
!(dx === 0 && dy === 0) &&
canPlace(bmpTool, bitmap, {
x1: text.AABBBounds.x1 + dx,
x2: text.AABBBounds.x2 + dx,
y1: text.AABBBounds.y1 + dy,
y2: text.AABBBounds.y2 + dy
})
) {
text.setAttributes({ x: text.attribute.x + dx, y: text.attribute.y + dy });
result.push(text);
continue;
}
}

let hasPlace: ReturnType<typeof place> = false;
// 发生碰撞,根据策略寻找可放置的位置
for (let j = 0; j < strategy.length; j++) {
Expand All @@ -333,6 +315,25 @@ export abstract class LabelBase<T extends BaseLabelAttrs> extends AbstractCompon
}
}

// 尝试向内挤压
if (clampForce) {
const { dx = 0, dy = 0 } = clampText(text, bmpTool.width, bmpTool.height);
if (
!(dx === 0 && dy === 0) &&
canPlace(bmpTool, bitmap, {
x1: text.AABBBounds.x1 + dx,
x2: text.AABBBounds.x2 + dx,
y1: text.AABBBounds.y1 + dy,
y2: text.AABBBounds.y2 + dy
})
) {
text.setAttributes({ x: text.attribute.x + dx, y: text.attribute.y + dy });
bitmap.setRange(boundToRange(bmpTool, text.AABBBounds, true));
result.push(text);
continue;
}
}

!hasPlace && !hideOnHit && result.push(text);
}

Expand Down

0 comments on commit 2a13907

Please sign in to comment.