excalidraw/src/scene/comparisons.ts
Christopher Chedeau 141b7409a2 Only show correct settings (#565)
* Only show correct settings

The logic to display which settings when nothing was selected was incorrect. This PR ensures that they are in sync.

I also removed all the <hr /> which after the redesigned just looked like weird empty spaces

* fix handling editing/text elements

Co-authored-by: David Luzar <luzar.david@gmail.com>
2020-01-26 15:19:43 +01:00

50 lines
1.3 KiB
TypeScript

import { ExcalidrawElement } from "../element/types";
import { hitTest } from "../element/collision";
import { getElementAbsoluteCoords } from "../element";
export const hasBackground = (type: string) =>
type === "rectangle" || type === "ellipse" || type === "diamond";
export const hasStroke = (type: string) =>
type === "rectangle" ||
type === "ellipse" ||
type === "diamond" ||
type === "arrow" ||
type === "line";
export const hasText = (type: string) => type === "text";
export function getElementAtPosition(
elements: readonly ExcalidrawElement[],
x: number,
y: number,
) {
let hitElement = null;
// We need to to hit testing from front (end of the array) to back (beginning of the array)
for (let i = elements.length - 1; i >= 0; --i) {
if (hitTest(elements[i], x, y)) {
hitElement = elements[i];
break;
}
}
return hitElement;
}
export function getElementContainingPosition(
elements: readonly ExcalidrawElement[],
x: number,
y: number,
) {
let hitElement = null;
// We need to to hit testing from front (end of the array) to back (beginning of the array)
for (let i = elements.length - 1; i >= 0; --i) {
const [x1, y1, x2, y2] = getElementAbsoluteCoords(elements[i]);
if (x1 < x && x < x2 && y1 < y && y < y2) {
hitElement = elements[i];
break;
}
}
return hitElement;
}