From 4a4762f414a2d1358fcb0447d7e2e7e1b1f4919c Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Fri, 22 Nov 2024 01:55:10 +1100 Subject: [PATCH] Fix snap to grid - now toggled at app level Was impl. as per workflow. --- src/LGraph.ts | 19 +++---------------- src/LGraphCanvas.ts | 4 ++-- src/LiteGraphGlobal.ts | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/LGraph.ts b/src/LGraph.ts index e14fd41..75e4028 100644 --- a/src/LGraph.ts +++ b/src/LGraph.ts @@ -47,19 +47,6 @@ type ParamsArray, K extends MethodNames> = export interface LGraphConfig { /** @deprecated Legacy config - unused */ align_to_grid?: any - /** - * When set to a positive number, when nodes are moved their positions will - * be rounded to the nearest multiple of this value. Half up. - * Default: `undefined` - * @todo Not implemented - see {@link LiteGraph.CANVAS_GRID_SIZE} - */ - snapToGrid?: number - /** - * If `true`, items always snap to the grid - modifier keys are ignored. - * When {@link snapToGrid} is falsy, a value of `1` is used. - * Default: `false` - */ - alwaysSnapToGrid?: boolean links_ontop?: any } @@ -791,7 +778,7 @@ export class LGraph implements LinkNetwork, Serialisable { const { state } = this // Ensure created items are snapped - if (this.config.alwaysSnapToGrid) { + if (LiteGraph.alwaysSnapToGrid) { const snapTo = this.getSnapToGridSize() if (snapTo) node.snapToGrid(snapTo) } @@ -1060,7 +1047,7 @@ export class LGraph implements LinkNetwork, Serialisable { * * Item positions are reounded to the nearest multiple of {@link LiteGraph.CANVAS_GRID_SIZE}. * - * When {@link config}.{@link LGraphConfig.alwaysSnapToGrid alwaysSnapToGrid} is enabled + * When {@link LiteGraph.alwaysSnapToGrid} is enabled * and the grid size is falsy, a default of 1 is used. * @param items The items to be snapped to the grid * @todo Currently only snaps nodes. @@ -1080,7 +1067,7 @@ export class LGraph implements LinkNetwork, Serialisable { */ getSnapToGridSize(): number { // Default to 1 when always snapping - return this.config.alwaysSnapToGrid + return LiteGraph.alwaysSnapToGrid ? LiteGraph.CANVAS_GRID_SIZE || 1 : LiteGraph.CANVAS_GRID_SIZE } diff --git a/src/LGraphCanvas.ts b/src/LGraphCanvas.ts index 22d8193..431a031 100644 --- a/src/LGraphCanvas.ts +++ b/src/LGraphCanvas.ts @@ -3019,7 +3019,7 @@ export class LGraphCanvas { */ #processDraggedItems(e: CanvasPointerEvent): void { const { graph } = this - if (e.shiftKey || graph.config.alwaysSnapToGrid) + if (e.shiftKey || LiteGraph.alwaysSnapToGrid) graph.snapToGrid(this.selectedItems) this.dirty_canvas = true @@ -4180,7 +4180,7 @@ export class LGraphCanvas { } // TODO: Set snapping value when changed instead of once per frame - this.#snapToGrid = this.#shiftDown || this.graph.config.alwaysSnapToGrid + this.#snapToGrid = this.#shiftDown || LiteGraph.alwaysSnapToGrid ? this.graph.getSnapToGridSize() : undefined diff --git a/src/LiteGraphGlobal.ts b/src/LiteGraphGlobal.ts index f1651c3..e290897 100644 --- a/src/LiteGraphGlobal.ts +++ b/src/LiteGraphGlobal.ts @@ -166,6 +166,21 @@ export class LiteGraphGlobal { /** [true!] renders a partial border to highlight when a dragged link is snapped to a node */ snap_highlights_node = true + /** + * If `true`, items always snap to the grid - modifier keys are ignored. + * When {@link snapToGrid} is falsy, a value of `1` is used. + * Default: `false` + */ + alwaysSnapToGrid?: boolean + + /** + * When set to a positive number, when nodes are moved their positions will + * be rounded to the nearest multiple of this value. Half up. + * Default: `undefined` + * @todo Not implemented - see {@link LiteGraph.CANVAS_GRID_SIZE} + */ + snapToGrid?: number + /** [false on mobile] better true if not touch device, TODO add an helper/listener to close if false */ search_hide_on_mouse_leave = true /**