Node Wrangler: Improved accuracy on Align Nodes operator #104551
@ -2352,6 +2352,9 @@ class NWAlignNodes(Operator, NWBase):
|
||||
active_node = context.active_node
|
||||
margin = self.margin
|
||||
|
||||
# Somehow hidden nodes would come out 10 units higher that non-hidden nodes when aligned, so this offset has to exist
|
||||
weird_offset = 10
|
||||
|
||||
with temporary_unframe(nodes=selection):
|
||||
active_loc = None
|
||||
if active_node in selection:
|
||||
@ -2360,12 +2363,19 @@ class NWAlignNodes(Operator, NWBase):
|
||||
# Check if nodes should be laid out horizontally or vertically
|
||||
# use dimension to get center of node, not corner
|
||||
x_locs = [n.location.x + (0.5 * n.dimensions.x) for n in selection]
|
||||
y_locs = [n.location.y - (0.5 * n.dimensions.y) for n in selection]
|
||||
y_locs = [n.location.y - weird_offset if n.hide
|
||||
else n.location.y - (0.5 * n.dimensions.y) for n in selection]
|
||||
|
||||
x_range = max(x_locs) - min(x_locs)
|
||||
y_range = max(y_locs) - min(y_locs)
|
||||
horizontal = x_range > y_range
|
||||
|
||||
#Undo corrective offsets for hidden nodes if alignment is horizontal
|
||||
if not horizontal:
|
||||
y_locs = [n.location.y - (0.5 * n.dimensions.y) for n in selection]
|
||||
|
||||
mid_x = 0.5 * (max(x_locs) + min(x_locs))
|
||||
mid_y = 0.5 * (max(y_locs) + min(y_locs))
|
||||
horizontal = x_range > y_range
|
||||
|
||||
# Sort selection by location of node mid-point
|
||||
if horizontal:
|
||||
@ -2375,23 +2385,18 @@ class NWAlignNodes(Operator, NWBase):
|
||||
|
||||
# Alignment
|
||||
current_pos = 0
|
||||
weird_offset = 10 # Somehow hidden nodes would come out 10 units higher that non-hidden nodes when aligned, so this offset has to exist
|
||||
|
||||
if horizontal:
|
||||
for node in selection:
|
||||
node.location.x = current_pos
|
||||
node.location.y = mid_y + (0.5 * node.dimensions.y)
|
||||
if node.hide:
|
||||
node.location.y -= (0.5 * node.dimensions.y) - weird_offset
|
||||
node.location.y = (mid_y + weird_offset) if node.hide else mid_y + (0.5 * node.dimensions.y)
|
||||
|
||||
current_pos += margin + node.dimensions.x
|
||||
else:
|
||||
for node in selection:
|
||||
node.location.y = current_pos
|
||||
if node.hide:
|
||||
node.location.y -= (0.5 * node.dimensions.y) - weird_offset
|
||||
|
||||
node.location.x = mid_x - (0.5 * node.dimensions.x)
|
||||
node.location.y = (current_pos - (0.5 * node.dimensions.y) + weird_offset) if node.hide else current_pos
|
||||
|
||||
current_pos -= 0.3 * margin + node.dimensions.y # use half-margin for vertical alignment
|
||||
|
||||
# If active node is selected, center nodes around it
|
||||
|
Loading…
Reference in New Issue
Block a user