Added a grid snapping sensitivity accessibility option
This commit is contained in:
@@ -9,13 +9,20 @@ import {
|
||||
getCellCorners,
|
||||
} from "../helpers/grid";
|
||||
|
||||
import useSetting from "./useSetting";
|
||||
|
||||
import { useGrid } from "../contexts/GridContext";
|
||||
|
||||
/**
|
||||
* Returns a function that when called will snap a node to the current grid
|
||||
* @param {number} snappingThreshold 1 = Always snap, 0 = never snap
|
||||
* @param {number=} snappingSensitivity 1 = Always snap, 0 = never snap if undefined the default user setting will be used
|
||||
*/
|
||||
function useGridSnapping(snappingThreshold) {
|
||||
function useGridSnapping(snappingSensitivity) {
|
||||
const [defaultSnappingSensitivity] = useSetting(
|
||||
"map.gridSnappingSensitivity"
|
||||
);
|
||||
snappingSensitivity = snappingSensitivity || defaultSnappingSensitivity;
|
||||
|
||||
const { grid, gridOffset, gridCellPixelSize } = useGrid();
|
||||
|
||||
/**
|
||||
@@ -57,7 +64,7 @@ function useGridSnapping(snappingThreshold) {
|
||||
const distanceToSnapPoint = Vector2.distance(offsetPosition, snapPoint);
|
||||
if (
|
||||
distanceToSnapPoint <
|
||||
Vector2.min(gridCellPixelSize) * snappingThreshold
|
||||
Vector2.min(gridCellPixelSize) * snappingSensitivity
|
||||
) {
|
||||
// Reverse grid offset
|
||||
let offsetSnapPoint = Vector2.add(snapPoint, gridOffset);
|
||||
|
||||
Reference in New Issue
Block a user