mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-30 19:21:54 +00:00
Move Snap to Grid control to LiteGraphGlobal (#329)
* Fix snap to grid - now toggled at app level Was impl. as per workflow. * Update test expectations
This commit is contained in:
@@ -47,19 +47,6 @@ type ParamsArray<T extends Record<any, any>, K extends MethodNames<T>> =
|
|||||||
export interface LGraphConfig {
|
export interface LGraphConfig {
|
||||||
/** @deprecated Legacy config - unused */
|
/** @deprecated Legacy config - unused */
|
||||||
align_to_grid?: any
|
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
|
links_ontop?: any
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -791,7 +778,7 @@ export class LGraph implements LinkNetwork, Serialisable<SerialisableGraph> {
|
|||||||
const { state } = this
|
const { state } = this
|
||||||
|
|
||||||
// Ensure created items are snapped
|
// Ensure created items are snapped
|
||||||
if (this.config.alwaysSnapToGrid) {
|
if (LiteGraph.alwaysSnapToGrid) {
|
||||||
const snapTo = this.getSnapToGridSize()
|
const snapTo = this.getSnapToGridSize()
|
||||||
if (snapTo) node.snapToGrid(snapTo)
|
if (snapTo) node.snapToGrid(snapTo)
|
||||||
}
|
}
|
||||||
@@ -1060,7 +1047,7 @@ export class LGraph implements LinkNetwork, Serialisable<SerialisableGraph> {
|
|||||||
*
|
*
|
||||||
* Item positions are reounded to the nearest multiple of {@link LiteGraph.CANVAS_GRID_SIZE}.
|
* 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.
|
* and the grid size is falsy, a default of 1 is used.
|
||||||
* @param items The items to be snapped to the grid
|
* @param items The items to be snapped to the grid
|
||||||
* @todo Currently only snaps nodes.
|
* @todo Currently only snaps nodes.
|
||||||
@@ -1080,7 +1067,7 @@ export class LGraph implements LinkNetwork, Serialisable<SerialisableGraph> {
|
|||||||
*/
|
*/
|
||||||
getSnapToGridSize(): number {
|
getSnapToGridSize(): number {
|
||||||
// Default to 1 when always snapping
|
// Default to 1 when always snapping
|
||||||
return this.config.alwaysSnapToGrid
|
return LiteGraph.alwaysSnapToGrid
|
||||||
? LiteGraph.CANVAS_GRID_SIZE || 1
|
? LiteGraph.CANVAS_GRID_SIZE || 1
|
||||||
: LiteGraph.CANVAS_GRID_SIZE
|
: LiteGraph.CANVAS_GRID_SIZE
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3019,7 +3019,7 @@ export class LGraphCanvas {
|
|||||||
*/
|
*/
|
||||||
#processDraggedItems(e: CanvasPointerEvent): void {
|
#processDraggedItems(e: CanvasPointerEvent): void {
|
||||||
const { graph } = this
|
const { graph } = this
|
||||||
if (e.shiftKey || graph.config.alwaysSnapToGrid)
|
if (e.shiftKey || LiteGraph.alwaysSnapToGrid)
|
||||||
graph.snapToGrid(this.selectedItems)
|
graph.snapToGrid(this.selectedItems)
|
||||||
|
|
||||||
this.dirty_canvas = true
|
this.dirty_canvas = true
|
||||||
@@ -4180,7 +4180,7 @@ export class LGraphCanvas {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Set snapping value when changed instead of once per frame
|
// 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()
|
? this.graph.getSnapToGridSize()
|
||||||
: undefined
|
: undefined
|
||||||
|
|
||||||
|
|||||||
@@ -166,6 +166,21 @@ export class LiteGraphGlobal {
|
|||||||
/** [true!] renders a partial border to highlight when a dragged link is snapped to a node */
|
/** [true!] renders a partial border to highlight when a dragged link is snapped to a node */
|
||||||
snap_highlights_node = true
|
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 */
|
/** [false on mobile] better true if not touch device, TODO add an helper/listener to close if false */
|
||||||
search_hide_on_mouse_leave = true
|
search_hide_on_mouse_leave = true
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -135,6 +135,7 @@ LiteGraphGlobal {
|
|||||||
"allow_multi_output_for_events": true,
|
"allow_multi_output_for_events": true,
|
||||||
"allow_scripts": false,
|
"allow_scripts": false,
|
||||||
"alt_drag_do_clone_nodes": false,
|
"alt_drag_do_clone_nodes": false,
|
||||||
|
"alwaysSnapToGrid": undefined,
|
||||||
"auto_load_slot_types": false,
|
"auto_load_slot_types": false,
|
||||||
"auto_sort_node_types": false,
|
"auto_sort_node_types": false,
|
||||||
"catch_exceptions": true,
|
"catch_exceptions": true,
|
||||||
@@ -170,6 +171,7 @@ LiteGraphGlobal {
|
|||||||
"slot_types_default_out": {},
|
"slot_types_default_out": {},
|
||||||
"slot_types_in": [],
|
"slot_types_in": [],
|
||||||
"slot_types_out": [],
|
"slot_types_out": [],
|
||||||
|
"snapToGrid": undefined,
|
||||||
"snap_highlights_node": true,
|
"snap_highlights_node": true,
|
||||||
"snaps_for_comfy": true,
|
"snaps_for_comfy": true,
|
||||||
"throw_errors": true,
|
"throw_errors": true,
|
||||||
|
|||||||
Reference in New Issue
Block a user