mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-05 07:30:11 +00:00
Snap everything to grid (#315)
* Implement snap to grid - Moves positioning logic to LGraph - Simplifies code - Adds Pointer API to alt-clone node - Removes always_round_positions, replaced by always snap to grid (default size is 1 when always snapping) Fix refator error * Fix group items snapped without group * Allow snapping of all items - Add snapToGrid to Positionable - Impl. on all types - Deprecated: alignToGrid is now a wrapper * Fix test import alias, update expectations * Prevent desync of before / after change events Adds ability to perform late binding of finally() during drag start. * nit - Refactor * Fix unwanted snap on node/group add * nit - Doc * Add shift key state tracking for snap to grid Private impl., no state API as yet. * Add snap guides rendering Nodes, reroutes * Optimisation - reroute rendering Fixes exponential redraw * Add snap guidelines for groups
This commit is contained in:
@@ -3,7 +3,7 @@ import type { LGraph } from "./LGraph"
|
||||
import type { ISerialisedGroup } from "./types/serialisation"
|
||||
import { LiteGraph } from "./litegraph"
|
||||
import { LGraphCanvas } from "./LGraphCanvas"
|
||||
import { containsCentre, containsRect, isInRectangle, isPointInRect, createBounds } from "./measure"
|
||||
import { containsCentre, containsRect, isInRectangle, isPointInRect, createBounds, snapPoint } from "./measure"
|
||||
import { LGraphNode } from "./LGraphNode"
|
||||
import { RenderShape, TitleMode } from "./types/globalEnums"
|
||||
|
||||
@@ -192,6 +192,11 @@ export class LGraphGroup implements Positionable, IPinnable {
|
||||
}
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
snapToGrid(snapTo: number): boolean {
|
||||
return this.pinned ? false : snapPoint(this.pos, snapTo)
|
||||
}
|
||||
|
||||
recomputeInsideNodes(): void {
|
||||
const { nodes, reroutes, groups } = this.graph
|
||||
const children = this._children
|
||||
@@ -233,8 +238,8 @@ export class LGraphGroup implements Positionable, IPinnable {
|
||||
* @param padding Value in graph units to add to all sides of the group. Default: 10
|
||||
*/
|
||||
resizeTo(objects: Iterable<Positionable>, padding: number = 10): void {
|
||||
const boundingBox = createBounds(objects, padding);
|
||||
if(boundingBox === null) return
|
||||
const boundingBox = createBounds(objects, padding)
|
||||
if (boundingBox === null) return
|
||||
|
||||
this.pos[0] = boundingBox[0]
|
||||
this.pos[1] = boundingBox[1] - this.titleHeight
|
||||
|
||||
Reference in New Issue
Block a user