mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
fix: make arrow binding area adapt to zoom levels (#8927)
* make binding area adapt to zoom * revert stroke color * normalize binding gap * reduce normalized gap
This commit is contained in:
parent
873698a1a2
commit
1e3399eac8
14 changed files with 247 additions and 119 deletions
|
@ -43,7 +43,11 @@ import type {
|
|||
SuggestedBinding,
|
||||
SuggestedPointBinding,
|
||||
} from "../element/binding";
|
||||
import { maxBindingGap } from "../element/binding";
|
||||
import {
|
||||
BINDING_HIGHLIGHT_OFFSET,
|
||||
BINDING_HIGHLIGHT_THICKNESS,
|
||||
maxBindingGap,
|
||||
} from "../element/binding";
|
||||
import { LinearElementEditor } from "../element/linearElementEditor";
|
||||
import {
|
||||
bootstrapCanvas,
|
||||
|
@ -217,17 +221,18 @@ const renderBindingHighlightForBindableElement = (
|
|||
context: CanvasRenderingContext2D,
|
||||
element: ExcalidrawBindableElement,
|
||||
elementsMap: ElementsMap,
|
||||
zoom: InteractiveCanvasAppState["zoom"],
|
||||
) => {
|
||||
const [x1, y1, x2, y2] = getElementAbsoluteCoords(element, elementsMap);
|
||||
const width = x2 - x1;
|
||||
const height = y2 - y1;
|
||||
const thickness = 10;
|
||||
|
||||
// So that we don't overlap the element itself
|
||||
const strokeOffset = 4;
|
||||
context.strokeStyle = "rgba(0,0,0,.05)";
|
||||
context.lineWidth = thickness - strokeOffset;
|
||||
const padding = strokeOffset / 2 + thickness / 2;
|
||||
// When zooming out, make line width greater for visibility
|
||||
const zoomValue = zoom.value < 1 ? zoom.value : 1;
|
||||
context.lineWidth = BINDING_HIGHLIGHT_THICKNESS / zoomValue;
|
||||
// To ensure the binding highlight doesn't overlap the element itself
|
||||
const padding = context.lineWidth / 2 + BINDING_HIGHLIGHT_OFFSET;
|
||||
|
||||
const radius = getCornerRadius(
|
||||
Math.min(element.width, element.height),
|
||||
|
@ -285,6 +290,7 @@ const renderBindingHighlightForSuggestedPointBinding = (
|
|||
context: CanvasRenderingContext2D,
|
||||
suggestedBinding: SuggestedPointBinding,
|
||||
elementsMap: ElementsMap,
|
||||
zoom: InteractiveCanvasAppState["zoom"],
|
||||
) => {
|
||||
const [element, startOrEnd, bindableElement] = suggestedBinding;
|
||||
|
||||
|
@ -292,6 +298,7 @@ const renderBindingHighlightForSuggestedPointBinding = (
|
|||
bindableElement,
|
||||
bindableElement.width,
|
||||
bindableElement.height,
|
||||
zoom,
|
||||
);
|
||||
|
||||
context.strokeStyle = "rgba(0,0,0,0)";
|
||||
|
@ -390,7 +397,7 @@ const renderBindingHighlight = (
|
|||
|
||||
context.save();
|
||||
context.translate(appState.scrollX, appState.scrollY);
|
||||
renderHighlight(context, suggestedBinding as any, elementsMap);
|
||||
renderHighlight(context, suggestedBinding as any, elementsMap, appState.zoom);
|
||||
|
||||
context.restore();
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue