MCPcopy Create free account
hub / github.com/Easy-Editor/EasyEditor / align

Method align

packages/plugin-dashboard/src/designer/alignment.ts:104–140  ·  view source on GitHub ↗
(type: AlignType)

Source from the content-addressed store, hash-verified

102 */
103 @action
104 align(type: AlignType): boolean {
105 const nodes = this.getSelectedNodes()
106 if (nodes.length < 2) return false
107
108 const box = this.calculateBoundingBox(nodes)
109
110 for (const node of nodes) {
111 const rect = node.getDashboardRect()
112 let newX = rect.x
113 let newY = rect.y
114
115 switch (type) {
116 case AlignType.LEFT:
117 newX = box.minX
118 break
119 case AlignType.RIGHT:
120 newX = box.maxX - rect.width
121 break
122 case AlignType.TOP:
123 newY = box.minY
124 break
125 case AlignType.BOTTOM:
126 newY = box.maxY - rect.height
127 break
128 case AlignType.HORIZONTAL_CENTER:
129 newX = box.minX + (box.width - rect.width) / 2
130 break
131 case AlignType.VERTICAL_CENTER:
132 newY = box.minY + (box.height - rect.height) / 2
133 break
134 }
135
136 this.updateNodePosition(node, newX, newY)
137 }
138
139 return true
140 }
141
142 /**
143 * 执行分布操作

Callers 1

AlignmentClass · 0.95

Calls 4

getSelectedNodesMethod · 0.95
calculateBoundingBoxMethod · 0.95
updateNodePositionMethod · 0.95
getDashboardRectMethod · 0.80

Tested by

no test coverage detected