mirror of
https://github.com/stan-smith/FossFLOW.git
synced 2025-12-24 06:58:48 -05:00
feat: allows textBoxes to be dragged from any point
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import React, { useMemo } from 'react';
|
||||
import { ProjectionOrientationEnum } from 'src/types';
|
||||
import { CoordsUtils } from 'src/utils';
|
||||
import { getTextBoxTo } from 'src/utils';
|
||||
import { useTextBox } from 'src/hooks/useTextBox';
|
||||
import { TransformControls } from './TransformControls';
|
||||
|
||||
@@ -12,18 +11,8 @@ export const TextBoxTransformControls = ({ id }: Props) => {
|
||||
const textBox = useTextBox(id);
|
||||
|
||||
const to = useMemo(() => {
|
||||
if (textBox.orientation === ProjectionOrientationEnum.X) {
|
||||
return CoordsUtils.add(textBox.tile, {
|
||||
x: textBox.size.width,
|
||||
y: 0
|
||||
});
|
||||
}
|
||||
|
||||
return CoordsUtils.add(textBox.tile, {
|
||||
x: 0,
|
||||
y: -textBox.size.width
|
||||
});
|
||||
}, [textBox.orientation, textBox.size.width, textBox.tile]);
|
||||
return getTextBoxTo(textBox);
|
||||
}, [textBox]);
|
||||
|
||||
return <TransformControls from={textBox.tile} to={to} />;
|
||||
};
|
||||
|
||||
@@ -21,7 +21,8 @@ import {
|
||||
Rect,
|
||||
ProjectionOrientationEnum,
|
||||
AnchorPositionsEnum,
|
||||
BoundingBox
|
||||
BoundingBox,
|
||||
TextBox
|
||||
} from 'src/types';
|
||||
import {
|
||||
CoordsUtils,
|
||||
@@ -436,6 +437,20 @@ export const connectorPathTileToGlobal = (tile: Coords, origin: Coords) => {
|
||||
);
|
||||
};
|
||||
|
||||
export const getTextBoxTo = (textBox: TextBox) => {
|
||||
if (textBox.orientation === ProjectionOrientationEnum.X) {
|
||||
return CoordsUtils.add(textBox.tile, {
|
||||
x: textBox.size.width,
|
||||
y: 0
|
||||
});
|
||||
}
|
||||
|
||||
return CoordsUtils.add(textBox.tile, {
|
||||
x: 0,
|
||||
y: -textBox.size.width
|
||||
});
|
||||
};
|
||||
|
||||
interface GetItemAtTile {
|
||||
tile: Coords;
|
||||
scene: Scene;
|
||||
@@ -452,7 +467,9 @@ export const getItemAtTile = ({
|
||||
if (node) return node;
|
||||
|
||||
const textBox = scene.textBoxes.find((tb) => {
|
||||
return CoordsUtils.isEqual(tb.tile, tile);
|
||||
const textBoxBounds = getBoundingBox([tb.tile, getTextBoxTo(tb)]);
|
||||
|
||||
return isWithinBounds(tile, textBoxBounds);
|
||||
});
|
||||
|
||||
if (textBox) return textBox;
|
||||
|
||||
Reference in New Issue
Block a user