Unify pin/unpin interface between LGraphNode and LGraphGroup (#274)

This commit is contained in:
Chenlei Hu
2024-11-04 15:09:17 -05:00
committed by GitHub
parent b663f86c9e
commit 5edfc185c5
3 changed files with 33 additions and 10 deletions

View File

@@ -1,4 +1,4 @@
import type { Dictionary, IContextMenuValue, IFoundSlot, INodeFlags, INodeInputSlot, INodeOutputSlot, IOptionalSlotData, ISlotType, Point, Positionable, ReadOnlyRect, Rect, Size } from "./interfaces"
import type { Dictionary, IContextMenuValue, IFoundSlot, INodeFlags, INodeInputSlot, INodeOutputSlot, IOptionalSlotData, IPinnable, ISlotType, Point, Positionable, ReadOnlyRect, Rect, Size } from "./interfaces"
import type { LGraph } from "./LGraph"
import type { IWidget, TWidgetValue } from "./types/widgets"
import type { ISerialisedNode } from "./types/serialisation"
@@ -111,7 +111,7 @@ export interface LGraphNode {
* Base Class for all the node type classes
* @param {String} name a name for the node
*/
export class LGraphNode implements Positionable {
export class LGraphNode implements Positionable, IPinnable {
// Static properties used by dynamic child classes
static title?: string
static MAX_CONSOLE?: number
@@ -2329,6 +2329,7 @@ export class LGraphNode implements Positionable {
/**
* Prevents the node being accidentally moved or resized by mouse interaction.
* Toggles pinned state if no value is provided.
**/
pin(v?: boolean): void {
this.graph._version++
@@ -2342,6 +2343,10 @@ export class LGraphNode implements Positionable {
delete this.flags.pinned
}
unpin(): void {
this.pin(false)
}
localToScreen(x: number, y: number, dragAndScale: DragAndScale): Point {
return [
(x + this.pos[0]) * dragAndScale.scale + dragAndScale.offset[0],