mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Adjust padding so smaller objects have smaller padding
This commit is contained in:
parent
230e47fd52
commit
41711af210
1 changed files with 28 additions and 10 deletions
|
@ -110,18 +110,30 @@ type ElbowArrowData = {
|
||||||
const calculateDedupTreshhold = <Point extends GlobalPoint | LocalPoint>(
|
const calculateDedupTreshhold = <Point extends GlobalPoint | LocalPoint>(
|
||||||
a: Point,
|
a: Point,
|
||||||
b: Point,
|
b: Point,
|
||||||
) => 1 + pointDistance(a, b) / 100;
|
) => 1 + pointDistance(a, b) / 300;
|
||||||
|
|
||||||
const calculatePadding = (
|
const calculatePadding = (
|
||||||
aabb: Bounds,
|
aabb: Bounds,
|
||||||
startHeading: Heading,
|
startBoundingBox: Bounds,
|
||||||
endHeading: Heading,
|
endBoundingBox: Bounds,
|
||||||
) => {
|
) => {
|
||||||
const width = aabb[2] - aabb[0];
|
const width = aabb[2] - aabb[0];
|
||||||
const height = aabb[3] - aabb[1];
|
const height = aabb[3] - aabb[1];
|
||||||
const size = Math.max(width, height);
|
const size = Math.max(width, height);
|
||||||
|
const startExtent = Math.max(
|
||||||
|
startBoundingBox[2] - startBoundingBox[0],
|
||||||
|
startBoundingBox[3] - startBoundingBox[1],
|
||||||
|
10,
|
||||||
|
);
|
||||||
|
const endExtent = Math.max(
|
||||||
|
endBoundingBox[2] - endBoundingBox[0],
|
||||||
|
endBoundingBox[3] - endBoundingBox[1],
|
||||||
|
10,
|
||||||
|
);
|
||||||
|
|
||||||
return size > 75
|
return Math.min(startExtent, endExtent) < 80
|
||||||
|
? Math.min(startExtent, endExtent) / 2
|
||||||
|
: size > 75
|
||||||
? 40
|
? 40
|
||||||
: Math.min(Math.max(Math.min(width / 2 - 1, height / 2 - 1), 10), 40);
|
: Math.min(Math.max(Math.min(width / 2 - 1, height / 2 - 1), 10), 40);
|
||||||
};
|
};
|
||||||
|
@ -486,8 +498,10 @@ const handleSegmentMove = (
|
||||||
): ElementUpdate<ExcalidrawElbowArrowElement> => {
|
): ElementUpdate<ExcalidrawElbowArrowElement> => {
|
||||||
const BASE_PADDING = calculatePadding(
|
const BASE_PADDING = calculatePadding(
|
||||||
aabbForElement(arrow),
|
aabbForElement(arrow),
|
||||||
startHeading,
|
hoveredStartElement
|
||||||
endHeading,
|
? aabbForElement(hoveredStartElement)
|
||||||
|
: [10, 10, 10, 10],
|
||||||
|
hoveredEndElement ? aabbForElement(hoveredEndElement) : [10, 10, 10, 10],
|
||||||
);
|
);
|
||||||
const activelyModifiedSegmentIdx = fixedSegments
|
const activelyModifiedSegmentIdx = fixedSegments
|
||||||
.map((segment, i) => {
|
.map((segment, i) => {
|
||||||
|
@ -735,8 +749,10 @@ const handleEndpointDrag = (
|
||||||
) => {
|
) => {
|
||||||
const BASE_PADDING = calculatePadding(
|
const BASE_PADDING = calculatePadding(
|
||||||
aabbForPoints([startGlobalPoint, endGlobalPoint]),
|
aabbForPoints([startGlobalPoint, endGlobalPoint]),
|
||||||
startHeading,
|
hoveredStartElement
|
||||||
endHeading,
|
? aabbForElement(hoveredStartElement)
|
||||||
|
: [10, 10, 10, 10],
|
||||||
|
hoveredEndElement ? aabbForElement(hoveredEndElement) : [10, 10, 10, 10],
|
||||||
);
|
);
|
||||||
let startIsSpecial = arrow.startIsSpecial ?? null;
|
let startIsSpecial = arrow.startIsSpecial ?? null;
|
||||||
let endIsSpecial = arrow.endIsSpecial ?? null;
|
let endIsSpecial = arrow.endIsSpecial ?? null;
|
||||||
|
@ -1330,8 +1346,10 @@ const getElbowArrowData = (
|
||||||
] as Bounds;
|
] as Bounds;
|
||||||
const BASE_PADDING = calculatePadding(
|
const BASE_PADDING = calculatePadding(
|
||||||
aabbForPoints([startGlobalPoint, endGlobalPoint]),
|
aabbForPoints([startGlobalPoint, endGlobalPoint]),
|
||||||
startHeading,
|
hoveredStartElement
|
||||||
endHeading,
|
? aabbForElement(hoveredStartElement)
|
||||||
|
: [10, 10, 10, 10],
|
||||||
|
hoveredEndElement ? aabbForElement(hoveredEndElement) : [10, 10, 10, 10],
|
||||||
);
|
);
|
||||||
const startElementBounds = hoveredStartElement
|
const startElementBounds = hoveredStartElement
|
||||||
? aabbForElement(
|
? aabbForElement(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue