mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-21 15:24:09 +00:00
Unify pin/unpin interface between LGraphNode and LGraphGroup (#274)
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import type { IContextMenuValue, Point, Positionable, Size } from "./interfaces"
|
||||
import type { IContextMenuValue, IPinnable, Point, Positionable, Size } from "./interfaces"
|
||||
import type { LGraph } from "./LGraph"
|
||||
import type { ISerialisedGroup } from "./types/serialisation"
|
||||
import { LiteGraph } from "./litegraph"
|
||||
import { LGraphCanvas } from "./LGraphCanvas"
|
||||
import { isInsideRectangle, containsCentre, containsRect, isPointInRectangle } from "./measure"
|
||||
import { isInsideRectangle, containsCentre, containsRect } from "./measure"
|
||||
import { LGraphNode } from "./LGraphNode"
|
||||
import { RenderShape, TitleMode } from "./types/globalEnums"
|
||||
|
||||
@@ -11,7 +11,7 @@ export interface IGraphGroupFlags extends Record<string, unknown> {
|
||||
pinned?: true
|
||||
}
|
||||
|
||||
export class LGraphGroup implements Positionable {
|
||||
export class LGraphGroup implements Positionable, IPinnable {
|
||||
static minWidth = 140
|
||||
static minHeight = 80
|
||||
static resizeLength = 10
|
||||
@@ -85,12 +85,19 @@ export class LGraphGroup implements Positionable {
|
||||
return !!this.flags.pinned
|
||||
}
|
||||
|
||||
pin(): void {
|
||||
this.flags.pinned = true
|
||||
/**
|
||||
* Prevents the group being accidentally moved or resized by mouse interaction.
|
||||
* Toggles pinned state if no value is provided.
|
||||
**/
|
||||
pin(value?: boolean): void {
|
||||
const newState = value === undefined ? !this.pinned : value
|
||||
|
||||
if (newState) this.flags.pinned = true
|
||||
else delete this.flags.pinned
|
||||
}
|
||||
|
||||
unpin(): void {
|
||||
delete this.flags.pinned
|
||||
this.pin(false)
|
||||
}
|
||||
|
||||
configure(o: ISerialisedGroup): void {
|
||||
|
||||
@@ -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],
|
||||
|
||||
@@ -12,9 +12,9 @@ export type NullableProperties<T> = {
|
||||
|
||||
export type CanvasColour = string | CanvasGradient | CanvasPattern
|
||||
|
||||
/**
|
||||
/**
|
||||
* An object that can be positioned, selected, and moved.
|
||||
*
|
||||
*
|
||||
* May contain other {@link Positionable} objects.
|
||||
*/
|
||||
export interface Positionable {
|
||||
@@ -46,6 +46,17 @@ export interface Positionable {
|
||||
onDeselected?(): void
|
||||
}
|
||||
|
||||
/**
|
||||
* An object that can be pinned.
|
||||
*
|
||||
* Prevents the object being accidentally moved or resized by mouse interaction.
|
||||
*/
|
||||
export interface IPinnable {
|
||||
pinned: boolean
|
||||
pin(value?: boolean): void
|
||||
unpin(): void
|
||||
}
|
||||
|
||||
export interface IInputOrOutput {
|
||||
// If an input, this will be defined
|
||||
input?: INodeInputSlot
|
||||
|
||||
Reference in New Issue
Block a user